alerts stats on alerts page
This commit is contained in:
@@ -95,9 +95,9 @@ def alert_get_stats(alert,nperiod=0):
|
|||||||
columns += condition.metric
|
columns += condition.metric
|
||||||
|
|
||||||
workouts = Workout.objects.filter(date__gte=startdate,date__lte=enddate,user=alert.rower,
|
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]
|
ids = [w.id for w in workouts]
|
||||||
|
|
||||||
df = getsmallrowdata_db(columns,ids=ids,doclean=True,workstrokesonly=workstrokesonly)
|
df = getsmallrowdata_db(columns,ids=ids,doclean=True,workstrokesonly=workstrokesonly)
|
||||||
|
|
||||||
if df.empty:
|
if df.empty:
|
||||||
@@ -107,6 +107,7 @@ def alert_get_stats(alert,nperiod=0):
|
|||||||
'enddate':enddate,
|
'enddate':enddate,
|
||||||
'nr_strokes':0,
|
'nr_strokes':0,
|
||||||
'nr_strokes_qualifying':0,
|
'nr_strokes_qualifying':0,
|
||||||
|
'percentage':0,
|
||||||
}
|
}
|
||||||
|
|
||||||
# check if filters are in columns list
|
# check if filters are in columns list
|
||||||
@@ -137,6 +138,7 @@ def alert_get_stats(alert,nperiod=0):
|
|||||||
'enddate':enddate,
|
'enddate':enddate,
|
||||||
'nr_strokes':0,
|
'nr_strokes':0,
|
||||||
'nr_strokes_qualifying':0,
|
'nr_strokes_qualifying':0,
|
||||||
|
'percentage':0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -160,13 +162,19 @@ def alert_get_stats(alert,nperiod=0):
|
|||||||
df2 = df[mask].copy()
|
df2 = df[mask].copy()
|
||||||
|
|
||||||
nr_strokes_qualifying = len(df2)
|
nr_strokes_qualifying = len(df2)
|
||||||
|
|
||||||
|
if nr_strokes > 0:
|
||||||
|
percentage = int(100.*nr_strokes_qualifying/nr_strokes)
|
||||||
|
else:
|
||||||
|
percentage = 0
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'workouts':len(workouts),
|
'workouts':len(workouts),
|
||||||
'startdate':startdate,
|
'startdate':startdate,
|
||||||
'enddate':enddate,
|
'enddate':enddate,
|
||||||
'nr_strokes':nr_strokes,
|
'nr_strokes':nr_strokes,
|
||||||
'nr_strokes_qualifying':nr_strokes_qualifying
|
'nr_strokes_qualifying':nr_strokes_qualifying,
|
||||||
|
'percentage': percentage,
|
||||||
}
|
}
|
||||||
|
|
||||||
# run alert report
|
# run alert report
|
||||||
|
|||||||
@@ -12,6 +12,33 @@
|
|||||||
|
|
||||||
<ul class="main-content">
|
<ul class="main-content">
|
||||||
{% if alerts %}
|
{% 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">
|
<li class="grid_4">
|
||||||
<table width="100%" class="listtable shortpadded">
|
<table width="100%" class="listtable shortpadded">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -68,6 +95,7 @@
|
|||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
{% include 'menu_analytics.html' %}
|
{% include 'menu_analytics.html' %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -68,6 +68,13 @@ def strfdelta(tdelta):
|
|||||||
|
|
||||||
from rowers.teams import rower_get_managers
|
from rowers.teams import rower_get_managers
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def alertstatspercentage(list,i):
|
||||||
|
alertstats = list[i-1]
|
||||||
|
print(alertstats)
|
||||||
|
|
||||||
|
return alertstats["percentage"]
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def is_coach(rower,rowers):
|
def is_coach(rower,rowers):
|
||||||
for r in rowers:
|
for r in rowers:
|
||||||
|
|||||||
@@ -4323,6 +4323,11 @@ def alerts_view(request,userid=0):
|
|||||||
r = getrequestrower(request,userid=userid)
|
r = getrequestrower(request,userid=userid)
|
||||||
|
|
||||||
alerts = Alert.objects.filter(rower=r).order_by('next_run')
|
alerts = Alert.objects.filter(rower=r).order_by('next_run')
|
||||||
|
|
||||||
|
stats = []
|
||||||
|
|
||||||
|
for alert in alerts:
|
||||||
|
stats.append(alert_get_stats(alert))
|
||||||
|
|
||||||
breadcrumbs = [
|
breadcrumbs = [
|
||||||
{
|
{
|
||||||
@@ -4340,6 +4345,7 @@ def alerts_view(request,userid=0):
|
|||||||
'breadcrumbs':breadcrumbs,
|
'breadcrumbs':breadcrumbs,
|
||||||
'alerts':alerts,
|
'alerts':alerts,
|
||||||
'rower':r,
|
'rower':r,
|
||||||
|
'stats':stats,
|
||||||
})
|
})
|
||||||
|
|
||||||
# alert create view
|
# 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)
|
stats = alert_get_stats(alert,nperiod=nperiod)
|
||||||
|
|
||||||
|
if request.is_ajax():
|
||||||
|
return JSONResponse({
|
||||||
|
"stats":stats,
|
||||||
|
})
|
||||||
|
|
||||||
breadcrumbs = [
|
breadcrumbs = [
|
||||||
{
|
{
|
||||||
'url':'/rowers/analysis',
|
'url':'/rowers/analysis',
|
||||||
|
|||||||
Reference in New Issue
Block a user