plan chart
This commit is contained in:
@@ -354,6 +354,17 @@ def interactive_boxchart(datadf, fieldname, extratitle='',
|
|||||||
|
|
||||||
|
|
||||||
def interactive_planchart(data, startdate, enddate):
|
def interactive_planchart(data, startdate, enddate):
|
||||||
|
# data = data.melt(id_vars=['startdate'], value_vars=['executed', 'planned'])
|
||||||
|
|
||||||
|
data = data.with_columns((pl.col("startdate").apply(lambda x: x.strftime("%Y-%m-%d"))).alias("startdate"))
|
||||||
|
data_dict = data.to_dicts()
|
||||||
|
chart_data = {
|
||||||
|
'data': data_dict,
|
||||||
|
}
|
||||||
|
|
||||||
|
script, div = get_chart("/plan", chart_data, debug=False)
|
||||||
|
return script, div
|
||||||
|
|
||||||
hv.extension('bokeh')
|
hv.extension('bokeh')
|
||||||
|
|
||||||
yaxmaximum = data['executed'].max()
|
yaxmaximum = data['executed'].max()
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ from rowingdata import rower as rrower
|
|||||||
from rowingdata import rowingdata as rrdata
|
from rowingdata import rowingdata as rrdata
|
||||||
import arrow
|
import arrow
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import polars as pl
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# Python
|
# Python
|
||||||
@@ -203,16 +204,8 @@ def get_execution_report(rower, startdate, enddate, plan=None):
|
|||||||
startdate__gte=enddate)
|
startdate__gte=enddate)
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
plans = TrainingPlan.objects.filter(rowers__in=[rower])
|
plans = TrainingPlan.objects.filter(rowers__in=[rower])
|
||||||
#plans2 = TrainingPlan.objects.filter(
|
|
||||||
# enddate__lte=enddate, startdate__lte=enddate, rowers__in=[rower])
|
|
||||||
#plans = plans | plans2
|
|
||||||
|
|
||||||
#plans = plans.exclude(status=False).order_by("-enddate")
|
|
||||||
|
|
||||||
if not plans:
|
if not plans:
|
||||||
# make week cycles here
|
|
||||||
# get monday before startdate
|
|
||||||
|
|
||||||
micros = []
|
micros = []
|
||||||
else:
|
else:
|
||||||
sorted_plans = sorted(plans, key= lambda t: t.overlap(startdate,enddate))
|
sorted_plans = sorted(plans, key= lambda t: t.overlap(startdate,enddate))
|
||||||
@@ -313,7 +306,7 @@ def get_execution_report(rower, startdate, enddate, plan=None):
|
|||||||
planned += [plannedscore]
|
planned += [plannedscore]
|
||||||
executed += [actualscore]
|
executed += [actualscore]
|
||||||
|
|
||||||
data = pd.DataFrame({
|
data = pl.DataFrame({
|
||||||
'startdate': startdates,
|
'startdate': startdates,
|
||||||
'planned': planned,
|
'planned': planned,
|
||||||
'executed': executed,
|
'executed': executed,
|
||||||
|
|||||||
@@ -6,25 +6,22 @@
|
|||||||
|
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<script src="https://cdn.pydata.org/bokeh/release/bokeh-3.1.1.min.js"></script>
|
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
|
||||||
<script src="https://cdn.pydata.org/bokeh/release/bokeh-widgets-3.1.1.min.js"></script>
|
|
||||||
<script async="true" type="text/javascript">
|
|
||||||
Bokeh.set_log_level("info");
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
<h1>Training Plan - {{ plan.name }}</h1>
|
<h1>Training Plan - {{ plan.name }}</h1>
|
||||||
|
|
||||||
{{ the_script | safe }}
|
|
||||||
|
|
||||||
<ul class="main-content">
|
<ul class="main-content">
|
||||||
<li class="grid_4">
|
<li class="grid_4">
|
||||||
<div id="theplot" class="flexplot">
|
{{ the_div|safe }}
|
||||||
{{ the_div|safe }}
|
|
||||||
</div>
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<script src="https://d3js.org/d3.v6.js"></script>
|
||||||
|
{{ the_script | safe }}
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
|
|||||||
@@ -3569,7 +3569,7 @@ def rower_trainingplan_execution_view(request,
|
|||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
data, message = get_execution_report(r, startdate, enddate)
|
data, message = get_execution_report(r, startdate, enddate)
|
||||||
|
|
||||||
if not data.empty:
|
if not data.is_empty():
|
||||||
script, div = interactive_planchart(data, startdate, enddate)
|
script, div = interactive_planchart(data, startdate, enddate)
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
script = ''
|
script = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user