first model of basic alert functions
This commit is contained in:
81
rowers/alerts.py
Normal file
81
rowers/alerts.py
Normal file
@@ -0,0 +1,81 @@
|
||||
from rowers.models import Alert, Condition, User, Rower
|
||||
from rowers.teams import coach_getcoachees
|
||||
|
||||
## BASIC operations
|
||||
|
||||
# create alert
|
||||
def create_alert(manager, rower, measured,period=7, emailalert=True,
|
||||
reststrokes=False, workouttype='water',
|
||||
name=name,**kwargs):
|
||||
|
||||
# check if manager is coach of rower. If not return 0
|
||||
if manager.rower != rower:
|
||||
if rower not in coach_getcoachees(manager.rower):
|
||||
return 0
|
||||
|
||||
m = Condition(
|
||||
metric = measured['metric'],
|
||||
value1 = measured['value1'],
|
||||
value2 = measured['value2'],
|
||||
condition=measured['condition']
|
||||
)
|
||||
|
||||
m.save()
|
||||
|
||||
alert = Alert(name=name,
|
||||
manager=manager,
|
||||
rower=rower,
|
||||
measured=m,
|
||||
restrokes=reststrokes,
|
||||
period=period,
|
||||
emailalert=emailalert,
|
||||
workouttype=workouttype
|
||||
)
|
||||
|
||||
alert.save()
|
||||
|
||||
if 'filter' in kwargs:
|
||||
for f in filter:
|
||||
m = Condition(
|
||||
metric = f['metric'],
|
||||
value1 = f['value1'],
|
||||
value2 = f['value2'],
|
||||
condition = f['condition']
|
||||
)
|
||||
|
||||
m.save()
|
||||
|
||||
alert.filter.add(m)
|
||||
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
# update alert
|
||||
def alert_add_filters(alert,filter):
|
||||
for f in alert.filter.all():
|
||||
alert.filter.remove(f)
|
||||
f.delete()
|
||||
|
||||
for f in filter:
|
||||
m = Condition(
|
||||
metric = f['metric'],
|
||||
value1 = f['value1'],
|
||||
value2 = f['value2'],
|
||||
condition = f['condition']
|
||||
)
|
||||
|
||||
m.save()
|
||||
|
||||
alert.filter.add(m)
|
||||
|
||||
|
||||
|
||||
# get alert stats
|
||||
# nperiod = 0: current period, i.e. next_run - n days to today
|
||||
# nperiod = 1: 1 period ago , i.e. next_run -2n days to next_run -n days
|
||||
def alert_get_stats(alert,nperiod=0):
|
||||
return {}
|
||||
|
||||
# run alert report
|
||||
Reference in New Issue
Block a user