first version workouttype chart
This commit is contained in:
@@ -51,6 +51,7 @@ from rowers.courses import (
|
|||||||
polygon_coord_center
|
polygon_coord_center
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from rowers import mytypes
|
||||||
from rowers.models import course_spline
|
from rowers.models import course_spline
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
@@ -234,7 +235,8 @@ def interactive_hr_piechart(df,rower,title):
|
|||||||
tools=TOOLS,
|
tools=TOOLS,
|
||||||
)
|
)
|
||||||
|
|
||||||
for start, end , legend, color in zip(source_starts, source_ends, source_legends, colors[0:len(source_starts)]):
|
for start, end , legend, color in zip(source_starts, source_ends, source_legends,
|
||||||
|
colors[0:len(source_starts)]):
|
||||||
z.wedge(x=0, y=0, radius=1, start_angle=start, end_angle=end, color=color, legend=legend)
|
z.wedge(x=0, y=0, radius=1, start_angle=start, end_angle=end, color=color, legend=legend)
|
||||||
|
|
||||||
|
|
||||||
@@ -249,6 +251,67 @@ def interactive_hr_piechart(df,rower,title):
|
|||||||
|
|
||||||
return components(z)
|
return components(z)
|
||||||
|
|
||||||
|
def interactive_workouttype_piechart(workouts):
|
||||||
|
if len(workouts) == 0:
|
||||||
|
return "","Not enough workouts to make a chart"
|
||||||
|
|
||||||
|
datadict = {}
|
||||||
|
labels = []
|
||||||
|
types = []
|
||||||
|
|
||||||
|
for w in workouts:
|
||||||
|
try:
|
||||||
|
datadict[w.workouttype] += 3600*w.duration.hour+60*w.duration.minute+w.duration.second
|
||||||
|
except KeyError:
|
||||||
|
datadict[w.workouttype] = 3600*w.duration.hour+60*w.duration.minute+w.duration.second
|
||||||
|
types += [w.workouttype]
|
||||||
|
try:
|
||||||
|
labels += [mytypes.workouttypes_ordered[w.workouttype]]
|
||||||
|
except KeyError:
|
||||||
|
labels += [w.workouttype]
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
source_starts = [0]
|
||||||
|
source_ends = []
|
||||||
|
for type in types:
|
||||||
|
total += datadict[type]
|
||||||
|
source_starts.append(total)
|
||||||
|
source_ends.append(total)
|
||||||
|
|
||||||
|
source_ends.append(total)
|
||||||
|
|
||||||
|
source_starts = pd.Series(source_starts)*2*pi/total
|
||||||
|
source_ends = pd.Series(source_ends)*2*pi/total
|
||||||
|
|
||||||
|
size = 350
|
||||||
|
TOOLS = 'save'
|
||||||
|
|
||||||
|
z = figure(title="Workout Types", x_range=(-1,1), y_range=(-1,1), width=size, height=size,
|
||||||
|
tools=TOOLS,
|
||||||
|
)
|
||||||
|
|
||||||
|
colors = palette
|
||||||
|
|
||||||
|
print(source_ends)
|
||||||
|
print(labels)
|
||||||
|
|
||||||
|
for start, end , legend, color in zip(source_starts, source_ends, labels,
|
||||||
|
colors[0:len(source_starts)]):
|
||||||
|
print(start,end,color,legend)
|
||||||
|
z.wedge(x=0, y=0, radius=1, start_angle=start, end_angle=end, color=color, legend=legend)
|
||||||
|
|
||||||
|
|
||||||
|
z.toolbar_location = 'right'
|
||||||
|
z.legend.location = 'top_right'
|
||||||
|
#z.legend.visible = False
|
||||||
|
z.axis.visible = False
|
||||||
|
z.xgrid.grid_line_color = None
|
||||||
|
z.ygrid.grid_line_color = None
|
||||||
|
z.outline_line_color = None
|
||||||
|
|
||||||
|
return components(z)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def interactive_boxchart(datadf,fieldname,extratitle='',
|
def interactive_boxchart(datadf,fieldname,extratitle='',
|
||||||
spmmin=0,spmmax=0,workmin=0,workmax=0):
|
spmmin=0,spmmax=0,workmin=0,workmax=0):
|
||||||
|
|||||||
@@ -21,6 +21,10 @@
|
|||||||
<div id="id_script">
|
<div id="id_script">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="t_script">
|
||||||
|
{{ tscript|safe}}
|
||||||
|
</div>
|
||||||
|
|
||||||
<ul class="main-content">
|
<ul class="main-content">
|
||||||
<li class="grid_2">
|
<li class="grid_2">
|
||||||
<h1>History for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
|
<h1>History for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
|
||||||
@@ -73,6 +77,9 @@
|
|||||||
</table>
|
</table>
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="grid_2">
|
||||||
|
{{ tdiv|safe }}
|
||||||
|
</li>
|
||||||
<li class="grid_2">
|
<li class="grid_2">
|
||||||
<div id="id_chart">
|
<div id="id_chart">
|
||||||
{{ totaldiv|safe }}
|
{{ totaldiv|safe }}
|
||||||
|
|||||||
@@ -4697,7 +4697,8 @@ def history_view(request,userid=0):
|
|||||||
|
|
||||||
columns = ['hr','power','time']
|
columns = ['hr','power','time']
|
||||||
|
|
||||||
|
tscript,tdiv = interactive_workouttype_piechart(g_workouts)
|
||||||
|
|
||||||
totalmeters,totalhours, totalminutes = get_totals(g_workouts)
|
totalmeters,totalhours, totalminutes = get_totals(g_workouts)
|
||||||
totalminutes = "{totalminutes:02d}".format(totalminutes=totalminutes)
|
totalminutes = "{totalminutes:02d}".format(totalminutes=totalminutes)
|
||||||
|
|
||||||
@@ -4768,6 +4769,8 @@ def history_view(request,userid=0):
|
|||||||
|
|
||||||
return render(request,'history.html',
|
return render(request,'history.html',
|
||||||
{
|
{
|
||||||
|
'tscript':tscript,
|
||||||
|
'tdiv':tdiv,
|
||||||
'rower':r,
|
'rower':r,
|
||||||
'breadcrumbs':breadcrumbs,
|
'breadcrumbs':breadcrumbs,
|
||||||
'active':'nav-analysis',
|
'active':'nav-analysis',
|
||||||
@@ -4836,6 +4839,8 @@ def history_view_data(request,userid=0):
|
|||||||
totalmeters,totalhours, totalminutes = get_totals(g_workouts)
|
totalmeters,totalhours, totalminutes = get_totals(g_workouts)
|
||||||
totalminutes = "{totalminutes:02d}".format(totalminutes=totalminutes)
|
totalminutes = "{totalminutes:02d}".format(totalminutes=totalminutes)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# meters, duration per workout type
|
# meters, duration per workout type
|
||||||
wtypes = list(set([w.workouttype for w in g_workouts]))
|
wtypes = list(set([w.workouttype for w in g_workouts]))
|
||||||
|
|
||||||
@@ -4854,7 +4859,7 @@ def history_view_data(request,userid=0):
|
|||||||
ddict['wtype'] = mytypes.workouttypes_ordered[wtype]
|
ddict['wtype'] = mytypes.workouttypes_ordered[wtype]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
ddict['wtype'] = wtype
|
ddict['wtype'] = wtype
|
||||||
|
|
||||||
ddict['id'] = wtype
|
ddict['id'] = wtype
|
||||||
ddict['distance'] = wmeters
|
ddict['distance'] = wmeters
|
||||||
ddict['duration'] = "{whours}:{wminutes:02d}".format(
|
ddict['duration'] = "{whours}:{wminutes:02d}".format(
|
||||||
|
|||||||
Reference in New Issue
Block a user