Private
Public Access
1
0

initial version histo chart

This commit is contained in:
2024-03-07 12:41:43 +01:00
parent 1fa5f64b50
commit f935db347f
8 changed files with 62 additions and 27 deletions

View File

@@ -88,16 +88,23 @@ from rowers.serializers import *
activate(settings.TIME_ZONE) activate(settings.TIME_ZONE)
thetimezone = get_current_timezone() thetimezone = get_current_timezone()
def get_chart(end_point, chart_data): def get_chart(end_point, chart_data, debug=False):
if debug:
print(chart_data)
url = settings.ROWSANDALL_CHARTS_URL+end_point url = settings.ROWSANDALL_CHARTS_URL+end_point
headers = {'authorization':"Bearer {token}".format(token=settings.ROWSANDALL_CHARTS_TOKEN)} headers = {'authorization':"Bearer {token}".format(token=settings.ROWSANDALL_CHARTS_TOKEN)}
try: try:
response = requests.post(url, json=chart_data, headers=headers) response = requests.post(url, json=chart_data, headers=headers)
except: except ConnectionError as err:
if debug:
print("Chart Server Error")
print(err)
script = '' script = ''
div = 'Chart Server Error' div = 'Chart Server Error'
return script, div return script, div
if debug:
print("Status Code",response.status_code)
if response.status_code == 200: if response.status_code == 200:
script = response.json()['script'] script = response.json()['script']
@@ -108,6 +115,16 @@ def get_chart(end_point, chart_data):
return script, div return script, div
# Example for 3D
def filmdeaths():
data = pd.read_csv("~/Downloads/filmdeathcounts.csv")
chart_data = data.to_dict("records")
chart_data_dict = {"data": chart_data}
script, div = get_chart("/filmdeaths", chart_data_dict)
return script, div
# Example for BokehJS # Example for BokehJS
def sleep(): def sleep():
data = { data = {
@@ -2090,6 +2107,11 @@ def interactive_histoall(theworkouts, histoparam, includereststrokes,
histopwr = histopwr[histopwr > yaxminima[histoparam]] histopwr = histopwr[histopwr > yaxminima[histoparam]]
histopwr = histopwr[histopwr < yaxmaxima[histoparam]] histopwr = histopwr[histopwr < yaxmaxima[histoparam]]
data_dict = {"data": histopwr.tolist()}
script, div = get_chart("/histogram", data_dict, debug=False)
return script, div
plot = figure(tools=TOOLS, width=900, plot = figure(tools=TOOLS, width=900,
toolbar_sticky=False, toolbar_sticky=False,
toolbar_location="above" toolbar_location="above"

View File

@@ -6,6 +6,7 @@
{% block main %} {% block main %}
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="https://d3js.org/d3/v6/js"></script>
<script> <script>
$(function() { $(function() {
@@ -86,7 +87,6 @@
<li class="grid_4"> <li class="grid_4">
<div id="id_chart"> <div id="id_chart">
{{ the_div|safe }} {{ the_div|safe }}
</div> </div>
</li> </li>
@@ -123,22 +123,23 @@
<script> <script>
$(function($) { $(function($) {
console.log('loading script'); console.log('loading script');
$.getJSON(window.location.protocol + '//'+window.location.host + '/rowers/histodata/', function(json) { $.getJSON(window.location.protocol + '//'+window.location.host + '/rowers/histodata/', function(json) {
console.log('got script'); console.log('got script');
var counter=0; var counter=0;
var script = json.script; var script = json.script;
var div = json.div; var div = json.div;
console.log('set vars'); console.log(div)
$("#id_sitready").remove(); console.log('set vars');
console.log('sitready removed'); $("#id_sitready").remove();
$("#id_chart").append(div); console.log('sitready removed');
console.log('div appended'); $("#id_chart").append(div);
$("#id_script").append("<script>"+script+"</s"+"cript>"); console.log('div appended');
console.log('script changed'); $("#id_script").append("<script>"+script+"</s"+"cript>");
console.log('script changed');
}); });
}); });
</script> </script>

View File

@@ -14,6 +14,7 @@
} }
</script> </script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="https://d3js.org/d3.v6.js"></script>
<script> <script>
$(function() { $(function() {
@@ -411,9 +412,9 @@
<ul class="main-content"> <ul class="main-content">
<li class="grid_4"> <li class="grid_4">
<div id="id_chart"> <div id="id_chart">
{{ the_div|safe }} {{ the_div|safe }}
</div> </div>
</li> </li>
<li class="grid_4"> <li class="grid_4">
<p>You can use the date and search forms to search through all <p>You can use the date and search forms to search through all

View File

@@ -273,6 +273,7 @@ urlpatterns = [
name='workouts_summaries_email_view'), name='workouts_summaries_email_view'),
path('failedjobs/', views.failed_queue_view, name='failed_queue_view'), path('failedjobs/', views.failed_queue_view, name='failed_queue_view'),
path('sleep/', views.sleep_view, name='sleep_view'), path('sleep/', views.sleep_view, name='sleep_view'),
path('filmdeaths/', views.filmdeaths_view, name='filmdeaths_view'),
path('failedjobs/empty/', views.failed_queue_empty, name='failed_queue_empty'), path('failedjobs/empty/', views.failed_queue_empty, name='failed_queue_empty'),
re_path('^failedjobs/(?P<id>\w+.*)/$', re_path('^failedjobs/(?P<id>\w+.*)/$',
views.failed_job_view, name='failed_job_view'), views.failed_job_view, name='failed_job_view'),

View File

@@ -155,12 +155,7 @@ def get_call():
call1 = random.choice(coxes_calls) call1 = random.choice(coxes_calls)
call2 = random.choice(info_calls) call2 = random.choice(info_calls)
call = """<div id="id_sitready" class="successmessage"> call = """<div id="id_sitready" class="successmessage"><p>%s (%s)</p></div>""" % (call1, call2)
<p>
%s (%s)
</p>
</div>
""" % (call1, call2)
return call return call

View File

@@ -618,6 +618,7 @@ def histodata(workouts, options):
extratitle=extratitle, extratitle=extratitle,
workmin=workmin, workmax=workmax) workmin=workmin, workmax=workmax)
print(div)
return(script, div) return(script, div)

View File

@@ -18,6 +18,17 @@ def sleep_view(request):
"the_script": script, "the_script": script,
}) })
def filmdeaths_view(request):
script, div = filmdeaths()
return render(request,
"filmdeaths.html",
{
"the_div": div,
"the_script": script,
}
)
@login_required() @login_required()
def download_fit(request, filename=''): def download_fit(request, filename=''):
pss = PlannedSession.objects.filter(fitfile=filename) pss = PlannedSession.objects.filter(fitfile=filename)

View File

@@ -32,6 +32,9 @@
color: red; color: red;
} }
.chartlabel {
font-size: 1.2em;
}
.watermark { .watermark {
position: absolute; position: absolute;