new chart

This commit is contained in:
anon 2022-08-11 16:09:48 -03:00
parent 1ae5420d5d
commit 9bd4cbbe2d
3 changed files with 428 additions and 1 deletions

View file

@ -0,0 +1,393 @@
{% extends 'charts/base.html' %}
{% block header %}
<title>Moneroj.net - Stock to Flow Multiple</title>
{% endblock %}
{% block content %}
<!-- Content Wrapper -->
<div id="content-wrapper" style="background-color:rgb(48, 44, 41)">
<!-- Main Content -->
<div id="content">
<!-- Begin Page Content -->
<div class="container-fluid"><br>
<div class="row">
<div class="col-xl-12 col-lg-12">
<div class="card" id="graph1">
<div
class="card-header py-3 d-flex flex-row align-items-center justify-content-between text-white">
<h6 class="m-0 text-light">Stock-to-flow Multiple (Price / SF Model)</h6>
<div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button"
onclick="$('#graph1').toggleClass('fullscreen');window.dispatchEvent(new Event('resize'));">
<i class="bx bx-expand text-gray-400"></i>
</a>
</div>
</div>
<div class="card-body pb-0 pt-0 pl-0 pr-0" style="height: 100px;">
<div id="graph" style="height: 100%; width:100%;"></div>
</div>
</div>
<br>
</div>
</div>
<!-- Content Row -->
<div class="row">
<!-- Earnings (Monthly) Card Example -->
<div class="col-xl-6 col-md-6 mb-4">
<div class="card border-left-new h-100 py-2">
<div class="card-body">
<div class="text-xs font-weight-bold text-info text-uppercase mb-1">
Current Stock-to-flow Multiple</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ now_cycle }}</div>
</div>
</div>
</div>
<!-- Earnings (Monthly) Card Example -->
<div class="col-xl-6 col-md-6 mb-4">
<div class="card border-left-new h-100 py-2">
<div class="card-body">
<div class="text-xs font-weight-bold text-info text-uppercase mb-1">
Top Stock-to-flow Multiple Last Cycle</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ maximum }}</div>
</div>
</div>
</div>
</div>
<!-- Content Row -->
<div class="row">
<div class="col-xl-11 col-md-6 mb-4">
<div class="alert alert-dark" role="alert">
Not financial advice.
For information about the chart, click the button >
</div>
</div>
<div class="col-xl-1">
<button type="button" class="btn btn-dark btn-block" data-toggle="modal" href="#"
data-target="#id_Modal">
<div class="col-auto">
+
</div>
</button>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
</div>
<!-- End of Content Wrapper -->
<!-- Modal -->
<div class="modal fade" id="id_Modal" tabindex="-1" role="dialog" aria-labelledby="Modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="Modal">Help about the chart</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Cancelar">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
This chart shows the Stock-to-flow Multiple, which is the comparison between its current price against
its supposed value. When the indicator reaches 100, it suggests
the coin is at the end of its cycle and will now begin a bear market. This indicator is my own
aprimoration of PlanB's model, since for this one I also considered
the coin's supply. The formula is XMR-Supply*Price/(SF-Value*1.500.000);<br>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Fim do Modal -->
<!-- Page level plugins -->
<script>
var data1 = {
type: "scatter",
mode: "lines",
name: 'Oversold',
x: {{ dates|safe }},
y: {{ buy|safe }},
line: {
color: '#00ff00'
,width: 1
}
};
var data1_mobile = {
type: "scatter",
mode: "lines",
name: 'Oversold',
x: {{ dates|safe }},
y: {{ buy|safe }},
line: {
color: '#00ff00'
,width: 1
}
};
var data2 = {
type: "scatter",
mode: "lines",
name: 'Overbought',
x: {{ dates|safe }},
y: {{ sell|safe }},
line: {
color: '#ff0000'
,width: 1
}
};
var data2_mobile = {
type: "scatter",
mode: "lines",
name: 'Overbought',
x: {{ dates|safe }},
y: {{ sell|safe }},
line: {
color: '#ff0000'
,width: 1
}
};
var data3 = {
type: "scatter",
mode: "markers",
name: 'Average price on date',
x: {{ dates|safe }},
y: {{ color|safe }},
line: {color: '#7f421d'},
marker: {
color: {{ color|safe }},
colorbar: {
title: {
text: 'Cycle on the Bitcoin pair (%)',
side: 'right'
,font: {
color: 'white'
,size: 14
}
}
,thickness: 10
,tickfont: {
color: 'white'
,size: 14
}
,borderwidth: 0
},
colorscale: [['0', '#0000ff'], ['0.33', '#00ff00'], ['0.66', '#ffff00'], ['1', '#ff0000']],
sizemode: 'area',
size: 5,
cmax: 100,
cmin: 0
}
};
var data3_mobile = {
type: "scatter",
mode: "markers",
name: 'Average price on date',
x: {{ dates|safe }},
y: {{ color|safe }},
line: {color: '#7f421d'},
marker: {
color: {{ color|safe }},
colorbar: {
thickness: 4
,tickfont: {
color: 'white'
,size: 6
}
,borderwidth: 0
},
colorscale: [['0', '#0000ff'], ['0.33', '#00ff00'], ['0.66', '#ffff00'], ['1', '#ff0000']],
sizemode: 'area',
size: 3,
cmax: 100,
cmin: 0
}
};
var data = [data1, data2, data3];
var data_mobile = [data1_mobile, data2_mobile, data3_mobile];
var layout = {
plot_bgcolor:"#252221",
paper_bgcolor:"#252221",
annotations: [
{
xref: 'paper',
yref: 'paper',
x: 0.50,
xanchor: 'auto',
y: 0.98,
yanchor: 'auto',
text: 'Moneroj<br>https://www.moneroj.net',
showarrow: false,
borderwidth: 1,
bordercolor: '#5f5f5f',
bgcolor: '#333333',
borderpad: 5,
align: 'center',
font: {
color: "white",
size: 12
}
}],
separators: ",.",
legend: {
x: 0.98,
y: 0.98,
bgcolor: '#333333',
bordercolor: '#5f5f5f',
borderwidth: 1,
font: {
color: 'white',
size: 12
},
traceorder: 'normal',
xanchor: 'auto',
yanchor: 'auto'
},
hoverlabel: {
namelength: -1
},
yaxis: {
type: "linear",
title: {
text: 'Price / Stock-to-flow',
font: {
size: 20,
color: 'white'
}
},
tickformat :",.1f"
,nticks: 8
,tickfont: {
color: "#ffffff"
,size: 12
}
,gridcolor: "#333333"
},
xaxis: {
hoverformat: "%Y-%m-%d",
showgrid: true,
type: 'date',
nticks: 10
,tickfont: {
color: "#dddddd"
,size: 13
}
,gridcolor: "#333333"
,range: ['2014-02-01', '2023-06-01']
,zeroline: true
},
margin: {
l: 120,
r: 60,
b: 35,
t: 10,
pad: 4
}
};
var layout_mobile = {
plot_bgcolor:"black",
paper_bgcolor:"black",
separators: ",.",
hoverlabel: {
namelength: -1
},
legend: {
x: 0.98,
y: 0.02,
bgcolor: '#000000',
bordercolor: '#5f5f5f',
borderwidth: 1,
font: {
color: 'white',
size: 5
},
traceorder: 'normal',
xanchor: 'auto',
yanchor: 'auto'
},
showlegend: false,
yaxis: {
type: "linear",
tickformat :",.1f"
,nticks: 10
,tickfont: {
color: "#ffffff"
,size: 7
}
,gridcolor: "#444444"
},
xaxis: {
hoverformat: "%Y",
showgrid: true,
type: 'date',
nticks: 10
,tickfont: {
color: "#dddddd"
,size: 7
}
,gridcolor: "#444444"
,range: ['2014-02-01', '2023-06-01']
,zeroline: true
},
margin: {
l: 40,
r: 0,
b: 35,
t: 10,
pad: 0
}
};
function findBootstrapEnvironment() {
let envs = ['xs', 'sm', 'md', 'lg', 'xl'];
let el = document.createElement('div');
document.body.appendChild(el);
let curEnv = envs.shift();
for (let env of envs.reverse()) {
el.classList.add(`d-${env}-none`);
if (window.getComputedStyle(el).display === 'none') {
curEnv = env;
break;
}
}
document.body.removeChild(el);
return curEnv;
}
env_size = findBootstrapEnvironment();
if (env_size == "xs") {
document.getElementById("graph1").style.height="350px";
Plotly.newPlot('graph', data_mobile, layout_mobile, {responsive: true, modeBarButtonsToRemove: ['toImage', 'hoverCompareCartesian', 'hoverClosest2d', 'toggleSpikelines', 'lasso2d', 'select2d', 'hoverClosestCartesian'], displaylogo: false});
}
else {
document.getElementById("graph1").style.height="700px";
Plotly.newPlot('graph', data, layout, {responsive: true, modeBarButtonsToRemove: ['toImage', 'hoverCompareCartesian', 'hoverClosest2d', 'toggleSpikelines', 'lasso2d', 'select2d', 'hoverClosestCartesian'], displaylogo: false});
}
</script>
{% endblock %}

View file

@ -90,6 +90,7 @@ urlpatterns = [
path('p2pool_totalblocks/', views.p2pool_totalblocks, name='p2pool_totalblocks'),
path('metcalfesats_deviation/', views.metcalfesats_deviation, name='metcalfesats_deviation'),
path('metcalfe_deviation/', views.metcalfe_deviation, name='metcalfe_deviation'),
path('marketcycle/', views.marketcycle, name='marketcycle'),
# URLs to useful functions on charts/views.py
# Only admins can use these

View file

@ -1033,6 +1033,9 @@ def update_database(date_from=None, date_to=None):
print(str(date_from) + ' to ' + str(date_to))
date_from = datetime.datetime.strptime(date_from, '%Y-%m-%d')
date_to = datetime.datetime.strptime(date_to, '%Y-%m-%d')
all_coins = Coin.objects.filter(name='xmr').all()
amount = int(len(all_coins))
count = 0
date_aux = date_from
@ -1091,7 +1094,8 @@ def update_database(date_from=None, date_to=None):
if data.color == 0:
v0 = 0.002
delta = (0.015 - 0.002)/(6*365)
data.color = 30*coin_xmr.pricebtc/(int(coin_xmr.id)*delta + v0)
data.color = 30*coin_xmr.pricebtc/((amount)*delta + v0)
amount += 1
data.save()
try:
@ -4128,6 +4132,35 @@ def sfmultiple(request):
context = {'dates': dates, 'maximum': maximum, 'stock_to_flow': stock_to_flow, 'now_sf': now_sf, 'buy': buy, 'sell': sell, 'color': color}
return render(request, 'charts/sfmultiple.html', context)
def marketcycle(request):
if request.user.username != "Administrador" and request.user.username != "Morpheus":
update_visitors(False)
dt = datetime.datetime.now(timezone.utc).timestamp()
dates = []
color = []
sell = []
buy = []
data = Sfmodel.objects.order_by('date')
for item in data:
if item.color > 0:
color.append(item.color)
else:
color.append('')
sell.append(100)
buy.append(0)
dates.append(datetime.datetime.strftime(item.date, '%Y-%m-%d'))
now_cycle = locale.format('%.2f', item.color, grouping=True)
dt = 'marketcycle.html ' + locale.format('%.2f', datetime.datetime.now(timezone.utc).timestamp() - dt, grouping=True)+' seconds'
print(dt)
context = {'dates': dates, 'color': color, 'sell': sell, 'buy': buy, 'now_cycle': now_cycle}
return render(request, 'charts/marketcycle.html', context)
def thermocap(request):
if request.user.username != "Administrador" and request.user.username != "Morpheus":
update_visitors(False)