diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 6885e341..56ce5fc4 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -1586,9 +1586,9 @@ def rdata(file, rower=rrower()): try: res = rrdata(csvfile=file + '.gz', rower=rower) except IOError, IndexError: - res = 0 + res = rrdata() except: - res = 0 + res = rrdata() return res @@ -1637,7 +1637,7 @@ def getrowdata_db(id=0, doclean=False, convertnewtons=True): if data.empty: rowdata, row = getrowdata(id=id) - if rowdata: + if not rowdata.empty: data = dataprep(rowdata.df, id=id, bands=True, barchart=True, otwpower=True) else: @@ -1645,7 +1645,8 @@ def getrowdata_db(id=0, doclean=False, convertnewtons=True): else: row = Workout.objects.get(id=id) - if data['efficiency'].mean() == 0 and data['power'].mean() != 0: + + if not data.empty and data['efficiency'].mean() == 0 and data['power'].mean() != 0: data = add_efficiency(id=id) if doclean: diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index 4a1f4dc4..6a91f51d 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -42,8 +42,8 @@ def add_workouts_plannedsession(ws,ps,r): errors.append('For tests, you can only attach one workout') return result,comments,errors - - + + wold = Workout.objects.filter(plannedsession=ps,user=r) ids = [w.id for w in wold] + [w.id for w in ws] ids = list(set(ids)) @@ -51,7 +51,7 @@ def add_workouts_plannedsession(ws,ps,r): if len(ids)>1 and ps.sessiontype in ['test','coursetest']: errors.append('For tests, you can only attach one workout') return result,comments,errors - + # start adding sessions for w in ws: if w.date>=ps.startdate and w.date<=ps.enddate: @@ -63,7 +63,7 @@ def add_workouts_plannedsession(ws,ps,r): errors.append('Workout %i did not match session dates' % w.id) return result,comments,errors - + def remove_workout_plannedsession(w,ps): if w.plannedsession == ps: @@ -98,7 +98,7 @@ def get_session_metrics(ps): status = [] for r in rowers: - rscorev = 0 + rscorev = 0 trimpv = 0 durationv = 0 distancev = 0 @@ -113,7 +113,7 @@ def get_session_metrics(ps): durationv += timefield_to_seconds_duration(w.duration) trimpv += dataprep.workout_trimp(w) rscorev += dataprep.workout_rscore(w)[0] - + ratio,statusv,completiondate = is_session_complete_ws(ws,ps) try: completedatev = completiondate.strftime('%Y-%m-%d') @@ -139,7 +139,7 @@ def get_session_metrics(ps): 'rscore':rscore, 'trimp':trimp, 'completedate':completedate, - 'status':status, + 'status':status, } return thedict @@ -154,7 +154,7 @@ def is_session_complete_ws(ws,ps): return ratio,status,None else: return 0,'not done',None - + value = ps.sessionvalue if ps.sessionunit == 'min': value *= 60. @@ -171,7 +171,7 @@ def is_session_complete_ws(ws,ps): cratiomin = 0.9167 cratiomax = 1.0833 - + score = 0 completiondate = None for w in ws: @@ -236,7 +236,7 @@ def is_session_complete_ws(ws,ps): else: if not completiondate: completiondate = ws.reverse()[0].date - return ratio,'partial',completiondate + return ratio,'partial',completiondate elif ps.sessiontype == 'coursetest': if ps.course: ( @@ -274,19 +274,19 @@ def is_session_complete_ws(ws,ps): if not completiondate: completiondate = ws.reverse()[0].date return ratio,status,completiondate - + def is_session_complete(r,ps): status = 'not done' if r not in ps.rower.all(): return 0,'not assigned',None - + ws = Workout.objects.filter(user=r,plannedsession=ps) return is_session_complete_ws(ws,ps) - - + + def rank_results(ps): return 1 @@ -299,7 +299,7 @@ def add_team_session(t,ps): def add_rower_session(r,ps): ps.rower.add(r) ps.save() - + return 1 def remove_team_session(t,ps): @@ -377,9 +377,9 @@ def get_sessions_manager(m,teamid=0,startdate=date.today(), startdate__lte=enddate, enddate__gte=startdate, ).order_by("preferreddate","startdate","enddate") - + return sps - + def get_sessions(r,startdate=date.today(), enddate=date.today()+timezone.timedelta(+1000)): @@ -388,7 +388,7 @@ def get_sessions(r,startdate=date.today(), startdate__lte=enddate, enddate__gte=startdate, ).order_by("preferreddate","startdate","enddate") - + return sps def get_workouts_session(r,ps): diff --git a/rowers/serializers.py b/rowers/serializers.py index c552e2ed..3e94f954 100644 --- a/rowers/serializers.py +++ b/rowers/serializers.py @@ -21,6 +21,7 @@ class RowerSerializer(serializers.HyperlinkedModelSerializer): 'tr', 'an', 'ftp', + 'sex', ) class FavoriteChartSerializer(serializers.ModelSerializer): @@ -52,6 +53,13 @@ class WorkoutSerializer(serializers.ModelSerializer): 'maxhr', 'notes', 'summary', + 'boattype', + 'timezone', + 'forceunit', + 'inboard', + 'oarlength', + 'privacy', + 'rankingpiece' ) def create(self, validated_data): @@ -78,7 +86,13 @@ class WorkoutSerializer(serializers.ModelSerializer): summary=validated_data['summary'], averagehr=validated_data['averagehr'], maxhr=validated_data['maxhr'], - startdatetime=rowdatetime) + startdatetime=rowdatetime, + timezone=validated_data['timezone'], + forceunit=validated_data['forceunit'], + inboard=validated_data['inboard'], + oarlength=validated_data['oarlength'], + privacy=validated_data['privacy'], + rankingpiece=validated_data['rankingpiece'],) w.save() return w @@ -104,6 +118,13 @@ class WorkoutSerializer(serializers.ModelSerializer): instance.averagehr=validated_data['averagehr'] instance.maxhr=validated_data['maxhr'] instance.startdatetime=rowdatetime + instance.timezone=validated_data['timezone'] + instance.forceunit=validated_data['forceunit'] + instance.inboard=validated_data['inboard'] + instance.oarlength=validated_data['oarlength'] + instance.privacy=validated_data['privacy'] + instance.rankingpiece=validated_data['rankingpiece'] + instance.save() return instance diff --git a/rowers/templates/cum_flex.html b/rowers/templates/cum_flex.html index ea74a7ae..4071a3fb 100644 --- a/rowers/templates/cum_flex.html +++ b/rowers/templates/cum_flex.html @@ -92,7 +92,7 @@ {% if user.is_authenticated and user|is_manager %}
The POST call must have content-type: x-www-form-urlencoded. - I set it this way to support the handy testing utility mentioned - belower. However, - I really would like to support application/json but with the - current framework I cannot support both at the same time. Expect - changes. Write to me if you want to be notified of changes.
The payload is application/json data and looks as follows:
@@ -203,6 +197,12 @@Consistency checks will be done and the stroke data will be diff --git a/rowers/templates/histo.html b/rowers/templates/histo.html index f03c3414..f952ec58 100644 --- a/rowers/templates/histo.html +++ b/rowers/templates/histo.html @@ -88,7 +88,7 @@ {% if user.is_authenticated and user|is_manager %}
@@ -11,7 +9,7 @@