diff --git a/rowers/alerts.py b/rowers/alerts.py index 9226f517..7a3eaa09 100644 --- a/rowers/alerts.py +++ b/rowers/alerts.py @@ -111,6 +111,9 @@ def alert_get_stats(alert,nperiod=0): 'nr_strokes_qualifying':0, 'percentage':0, 'nperiod':nperiod, + 'median': 0, + 'median_q': 0, + 'standard_dev': 0, } # check if filters are in columns list @@ -143,6 +146,9 @@ def alert_get_stats(alert,nperiod=0): 'nr_strokes_qualifying':0, 'percentage':0, 'nperiod':nperiod, + 'median': 0, + 'median_q': 0, + 'standard_dev': 0, } diff --git a/rowers/dataprepnodjango.py b/rowers/dataprepnodjango.py index ed9dfc5f..9fd3d196 100644 --- a/rowers/dataprepnodjango.py +++ b/rowers/dataprepnodjango.py @@ -1104,7 +1104,11 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True, if barchart: # time increments for bar chart time_increments = rowdatadf.loc[:,' ElapsedTime (sec)'].diff() - time_increments[0] = time_increments[1] + try: + time_increments.iloc[0] = time_increments.iloc[1] + except (KeyError, IndexError): + time_increments.iloc[1] = 1. + time_increments = 0.5*time_increments+0.5*np.abs(time_increments) x_right = (t2+time_increments.apply(lambda x:timedeltaconv(x))) diff --git a/rowers/tasks.py b/rowers/tasks.py index cf0bae49..617a3de9 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -791,14 +791,33 @@ def handle_send_email_alert( othertexts = None report = {} - report['Percentage'] = int(stats['percentage']) - report['Number of workouts'] = int(stats['workouts']) - report['Data set'] = "{a} strokes out of {b}".format( + try: + report['Percentage'] = int(stats['percentage']) + except KeyError: + pass + + try: + report['Number of workouts'] = int(stats['workouts']) + except KeyError: + pass + + try: + report['Data set'] = "{a} strokes out of {b}".format( a = stats['nr_strokes_qualifying'], b = stats['nr_strokes'] ) - report['Median'] = sigdig(stats['median']) - report['Median of qualifying strokes'] = sigdig(stats['median_q']) + except KeyError: + pass + + try: + report['Median'] = sigdig(stats['median']) + except KeyError: + pass + + try: + report['Median of qualifying strokes'] = sigdig(stats['median_q']) + except KeyError: + pass subject = "Rowsandall.com: {alertname} ({startdate} to {enddate})".format( startdate = stats['startdate'],