totaldisct in ajax call
This commit is contained in:
@@ -58,16 +58,16 @@
|
||||
<td>Number of workouts</td><td>{{ totalsdict|lookup:"nrworkouts"}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Average heart rate</td><td>{{ totalsdict|lookup:"hrmean"}} bpm</td>
|
||||
<td>Average heart rate</td><td><span id="total_hr"></span> bpm</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Maximum heart rate</td><td>{{ totalsdict|lookup:"hrmax"}} bpm</td>
|
||||
<td>Maximum heart rate</td><td><span id="total_maxhr"></span> bpm</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Average power</td><td>{{ totalsdict|lookup:"powermean"}} W</td>
|
||||
<td>Average power</td><td><span id="total_power"></span> W</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Maximum power</td><td>{{ totalsdict|lookup:"powermax"}} W</td>
|
||||
<td>Maximum power</td><td><span id="total_maxpower"></span> W</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -125,17 +125,21 @@
|
||||
<script>
|
||||
$(function($) {
|
||||
console.log('loading script for chart');
|
||||
|
||||
$.getJSON(window.location.protocol + '//'+window.location.host + '/rowers/history/user/{{ rower.user.id }}/data/', function(json) {
|
||||
|
||||
$.getJSON(window.location.protocol + '//'+window.location.host + '/rowers/history/user/{{ rower.user.id }}/data/?startdate={{ startdate|date:"Y-m-d" }}&{{ enddate|date:"Y-m-d" }}&workouttype={{ workouttype }}', function(json) {
|
||||
|
||||
var script = json.script;
|
||||
var div = json.div;
|
||||
var totalsdict = json.totalsdict
|
||||
$("#id_sitready").remove();
|
||||
$("#id_chart").append(div);
|
||||
console.log(div);
|
||||
// $("#id_script").append("<s"+"cript>"+script+"</s"+"cript>");
|
||||
$("#id_script").append(script);
|
||||
|
||||
$("#total_hr").append(totalsdict.hrmean);
|
||||
$("#total_maxhr").append(totalsdict.hrmax);
|
||||
$("#total_power").append(totalsdict.powermean);
|
||||
$("#total_maxpower").append(totalsdict.powermax);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -4697,14 +4697,6 @@ def history_view(request,userid=0):
|
||||
|
||||
columns = ['hr','power','time']
|
||||
|
||||
df = getsmallrowdata_db(columns,ids=ids)
|
||||
try:
|
||||
df['deltat'] = df['time'].diff()
|
||||
except KeyError:
|
||||
pass
|
||||
df = dataprep.clean_df_stats(df,workstrokesonly=True,
|
||||
ignoreadvanced=True)
|
||||
|
||||
|
||||
totalmeters,totalhours, totalminutes = get_totals(g_workouts)
|
||||
totalminutes = "{totalminutes:02d}".format(totalminutes=totalminutes)
|
||||
@@ -4740,7 +4732,7 @@ def history_view(request,userid=0):
|
||||
|
||||
ddict['hrmean'] = int(wavg(ddf,'hr','deltat'))
|
||||
ddict['hrmax'] = ddf['hr'].max().astype(int)
|
||||
ddict['powermean'] = int(wavg(df,'power','deltat'))
|
||||
ddict['powermean'] = int(wavg(ddf,'power','deltat'))
|
||||
ddict['powermax'] = ddf['power'].max().astype(int)
|
||||
ddict['nrworkouts'] = a_workouts.count()
|
||||
listofdicts.append(ddict)
|
||||
@@ -4772,18 +4764,7 @@ def history_view(request,userid=0):
|
||||
)
|
||||
|
||||
totalsdict['distance'] = totalmeters
|
||||
try:
|
||||
totalsdict['powermean'] = int(wavg(df,'power','deltat'))
|
||||
totalsdict['powermax'] = df['power'].max().astype(int)
|
||||
except KeyError:
|
||||
totalsdict['powermean'] = 0
|
||||
totalsdict['powermax'] = 0
|
||||
try:
|
||||
totalsdict['hrmean'] = int(wavg(df,'hr','deltat'))
|
||||
totalsdict['hrmax'] = df['hr'].max().astype(int)
|
||||
except KeyError:
|
||||
totalsdict['hrmean'] = 0
|
||||
totalsdict['hrmax'] = 0
|
||||
|
||||
|
||||
totalsdict['nrworkouts'] = g_workouts.count()
|
||||
|
||||
@@ -4874,7 +4855,64 @@ def history_view_data(request,userid=0):
|
||||
df = dataprep.clean_df_stats(df,workstrokesonly=True,
|
||||
ignoreadvanced=True)
|
||||
|
||||
totalmeters,totalhours, totalminutes = get_totals(g_workouts)
|
||||
totalminutes = "{totalminutes:02d}".format(totalminutes=totalminutes)
|
||||
|
||||
# meters, duration per workout type
|
||||
wtypes = list(set([w.workouttype for w in g_workouts]))
|
||||
|
||||
typechoices = [("All","All")]
|
||||
for wtype in wtypes:
|
||||
typechoices.append((wtype,mytypes.workouttypes_ordered[wtype]))
|
||||
|
||||
listofdicts = []
|
||||
|
||||
for wtype in wtypes:
|
||||
a_workouts = g_workouts.filter(workouttype=wtype)
|
||||
wmeters, whours, wminutes = get_totals(a_workouts)
|
||||
ddict = {}
|
||||
ddict['wtype'] = mytypes.workouttypes_ordered[wtype]
|
||||
ddict['distance'] = wmeters
|
||||
ddict['duration'] = "{whours}:{wminutes:02d}".format(
|
||||
whours=whours,
|
||||
wminutes=wminutes
|
||||
)
|
||||
ddf = getsmallrowdata_db(columns,ids=[w.id for w in a_workouts])
|
||||
try:
|
||||
ddf['deltat'] = ddf['time'].diff()
|
||||
except KeyError:
|
||||
pass
|
||||
ddf = dataprep.clean_df_stats(ddf,workstrokesonly=True,
|
||||
ignoreadvanced=True)
|
||||
|
||||
ddict['hrmean'] = int(wavg(ddf,'hr','deltat'))
|
||||
ddict['hrmax'] = ddf['hr'].max().astype(int)
|
||||
ddict['powermean'] = int(wavg(df,'power','deltat'))
|
||||
ddict['powermax'] = ddf['power'].max().astype(int)
|
||||
ddict['nrworkouts'] = a_workouts.count()
|
||||
listofdicts.append(ddict)
|
||||
|
||||
totalsdict = {}
|
||||
totalsdict['duration'] = "{totalhours}:{totalminutes}".format(
|
||||
totalhours=totalhours,
|
||||
totalminutes=totalminutes
|
||||
)
|
||||
|
||||
totalsdict['distance'] = totalmeters
|
||||
try:
|
||||
totalsdict['powermean'] = int(wavg(df,'power','deltat'))
|
||||
totalsdict['powermax'] = df['power'].max().astype(int)
|
||||
except KeyError:
|
||||
totalsdict['powermean'] = 0
|
||||
totalsdict['powermax'] = 0
|
||||
try:
|
||||
totalsdict['hrmean'] = int(wavg(df,'hr','deltat'))
|
||||
totalsdict['hrmax'] = df['hr'].max().astype(int)
|
||||
except KeyError:
|
||||
totalsdict['hrmean'] = 0
|
||||
totalsdict['hrmax'] = 0
|
||||
|
||||
totalsdict['nrworkouts'] = g_workouts.count()
|
||||
|
||||
|
||||
# interactive hr pie chart
|
||||
@@ -4894,4 +4932,6 @@ def history_view_data(request,userid=0):
|
||||
return JSONResponse({
|
||||
'script':totalscript,
|
||||
'div':totaldiv,
|
||||
'totalsdict':totalsdict,
|
||||
'listofdicts':listofdicts,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user