Private
Public Access
1
0

alerts stats on alerts page

This commit is contained in:
Sander Roosendaal
2019-08-26 18:08:10 +02:00
parent ce582f7563
commit 454bcde22f
4 changed files with 57 additions and 3 deletions

View File

@@ -95,9 +95,9 @@ def alert_get_stats(alert,nperiod=0):
columns += condition.metric
workouts = Workout.objects.filter(date__gte=startdate,date__lte=enddate,user=alert.rower,
workouttype=alert.workouttype)
workouttype=alert.workouttype,duplicate=False)
ids = [w.id for w in workouts]
df = getsmallrowdata_db(columns,ids=ids,doclean=True,workstrokesonly=workstrokesonly)
if df.empty:
@@ -107,6 +107,7 @@ def alert_get_stats(alert,nperiod=0):
'enddate':enddate,
'nr_strokes':0,
'nr_strokes_qualifying':0,
'percentage':0,
}
# check if filters are in columns list
@@ -137,6 +138,7 @@ def alert_get_stats(alert,nperiod=0):
'enddate':enddate,
'nr_strokes':0,
'nr_strokes_qualifying':0,
'percentage':0,
}
@@ -160,13 +162,19 @@ def alert_get_stats(alert,nperiod=0):
df2 = df[mask].copy()
nr_strokes_qualifying = len(df2)
if nr_strokes > 0:
percentage = int(100.*nr_strokes_qualifying/nr_strokes)
else:
percentage = 0
return {
'workouts':len(workouts),
'startdate':startdate,
'enddate':enddate,
'nr_strokes':nr_strokes,
'nr_strokes_qualifying':nr_strokes_qualifying
'nr_strokes_qualifying':nr_strokes_qualifying,
'percentage': percentage,
}
# run alert report

View File

@@ -12,6 +12,33 @@
<ul class="main-content">
{% if alerts %}
{% for alert in alerts %}
<li class="rounder">
<h2>{{ alert.name }}</h2>
<a class="small" href="/rowers/alerts/{{ alert.id }}/edit/" title="Edit">
<i class="fas fa-pencil-alt fa-fw"></i>
</a>
<a class="small" href="/rowers/alerts/{{ alert.id }}/delete/"
title="Delete">
<i class="fas fa-trash-alt fa-fw"></i>
</a>
<hr>
<a href="/rowers/alerts/{{ alert.id }}/report/">
<div id="id_alert_{{ forloop.counter }}">
<h1>{{ stats|alertstatspercentage:forloop.counter }}%</h1>
</div>
</a>
<p>
{{ alert.description }}
</p>
<p>
Workout type: {{ alert.workouttype }}
</p>
<p>
Next Run: {{ alert.next_run }}
</p>
</li>
{% endfor %}
<li class="grid_4">
<table width="100%" class="listtable shortpadded">
<thead>
@@ -68,6 +95,7 @@
{% endblock %}
{% block sidebar %}
{% include 'menu_analytics.html' %}
{% endblock %}

View File

@@ -68,6 +68,13 @@ def strfdelta(tdelta):
from rowers.teams import rower_get_managers
@register.filter
def alertstatspercentage(list,i):
alertstats = list[i-1]
print(alertstats)
return alertstats["percentage"]
@register.filter
def is_coach(rower,rowers):
for r in rowers:

View File

@@ -4323,6 +4323,11 @@ def alerts_view(request,userid=0):
r = getrequestrower(request,userid=userid)
alerts = Alert.objects.filter(rower=r).order_by('next_run')
stats = []
for alert in alerts:
stats.append(alert_get_stats(alert))
breadcrumbs = [
{
@@ -4340,6 +4345,7 @@ def alerts_view(request,userid=0):
'breadcrumbs':breadcrumbs,
'alerts':alerts,
'rower':r,
'stats':stats,
})
# alert create view
@@ -4443,6 +4449,11 @@ def alert_report_view(request,id=0,userid=0,nperiod=0):
stats = alert_get_stats(alert,nperiod=nperiod)
if request.is_ajax():
return JSONResponse({
"stats":stats,
})
breadcrumbs = [
{
'url':'/rowers/analysis',