Private
Public Access
1
0

first implementation

This commit is contained in:
2025-01-07 20:22:50 +01:00
parent 9b1d00fb67
commit 53c5193be2
5 changed files with 102 additions and 3 deletions

View File

@@ -306,8 +306,29 @@ class IntervalsIntegration(SyncIntegration):
w.workouttype = mytypes.intervalsmappinginv[data['type']] w.workouttype = mytypes.intervalsmappinginv[data['type']]
except KeyError: except KeyError:
pass pass
try:
w.rpe = data['icu_rpe']
except KeyError:
pass
try:
w.is_commute = data['commute']
if w.is_commute is None:
w.is_commute = False
except KeyError:
w.is_commute = False
w.save() w.save()
try:
paired_session_icu_id = data['paired_event_id']
pss = PlannedSession.objects.filter(intervals_icu_id=paired_session_icu_id, rower=self.rower)
if pss.count() > 0:
for ps in pss:
w.plannedsession = ps
w.save()
except KeyError:
pass
# we stop here now # we stop here now
return 1 return 1
@@ -406,6 +427,18 @@ class IntervalsIntegration(SyncIntegration):
except KeyError: except KeyError:
title = 'Intervals workout' title = 'Intervals workout'
try:
rpe = data['icu_rpe']
except KeyError:
rpe = 0
try:
is_commute = data['commute']
if is_commute is None:
is_commute = False
except KeyError:
is_commute = False
try: try:
workouttype = mytypes.intervalsmappinginv[data['type']] workouttype = mytypes.intervalsmappinginv[data['type']]
except KeyError: except KeyError:
@@ -443,13 +476,38 @@ class IntervalsIntegration(SyncIntegration):
'file': fit_filename, 'file': fit_filename,
'intervalsid': id, 'intervalsid': id,
'title': title, 'title': title,
'rpe': 0, 'rpe': rpe,
'notes': '', 'notes': '',
'offline': False, 'offline': False,
} }
url = UPLOAD_SERVICE_URL url = UPLOAD_SERVICE_URL
return handle_request_post(url, uploadoptions) handle_request_post(url, uploadoptions)
try:
pair_id = data['paired_event_id']
pss = PlannedSession.objects.filter(intervals_icu_id=pair_id, rower=r)
ws = Workout.objects.filter(uploadedtointervals=id)
if is_commute:
for w in ws:
w.is_commute = True
w.save()
if pss.count() > 0:
for ps in pss:
for w in ws:
w.plannedsession = ps
w.save()
except KeyError:
pass
except PlannedSession.DoesNotExist:
pass
except Workout.DoesNotExist:
pass
return 1
def pair_workout_and_session(w, id):
pass
def get_workouts(self, *args, **kwargs): def get_workouts(self, *args, **kwargs):

View File

@@ -3740,6 +3740,8 @@ class Workout(models.Model):
rpe = models.IntegerField(default=0, blank=True, choices=rpechoices, rpe = models.IntegerField(default=0, blank=True, choices=rpechoices,
verbose_name='Rate of Perceived Exertion') verbose_name='Rate of Perceived Exertion')
is_commute = models.BooleanField(default=False)
weightcategory = models.CharField( weightcategory = models.CharField(
default="hwt", default="hwt",
max_length=10, max_length=10,
@@ -4601,6 +4603,7 @@ class WorkoutForm(ModelForm):
'notes', 'notes',
'rankingpiece', 'rankingpiece',
'duplicate', 'duplicate',
'is_commute',
'plannedsession'] 'plannedsession']
widgets = { widgets = {
'date': AdminDateWidget(), 'date': AdminDateWidget(),

View File

@@ -417,6 +417,9 @@ def add_workouts_plannedsession(ws, ps, r):
result += 1 result += 1
comments.append('Attached workout %s to session' % comments.append('Attached workout %s to session' %
encoder.encode_hex(w.id)) encoder.encode_hex(w.id))
if ps.intervals_icu_id:
integration = integrations.IntervalsIntegration(w.user)
integration.pair_workout_and_session(w, ps.intervals_icu_id)
if ps.sessiontype == 'coursetest': # pragma: no cover if ps.sessiontype == 'coursetest': # pragma: no cover
record = CourseTestResult( record = CourseTestResult(
userid=w.user.id, userid=w.user.id,

View File

@@ -3586,6 +3586,18 @@ def handle_intervals_getworkout(rower, intervalstoken, workoutid, debug=False, *
except KeyError: except KeyError:
workouttype = 'water' workouttype = 'water'
try:
rpe = data['icu_rpe']
except KeyError:
rpe = 0
try:
is_commute = data['commute']
if is_commute is None:
is_commute = False
except KeyError:
is_commute = False
url = "https://intervals.icu/api/v1/activity/{workoutid}/fit-file".format(workoutid=workoutid) url = "https://intervals.icu/api/v1/activity/{workoutid}/fit-file".format(workoutid=workoutid)
response = requests.get(url, headers=headers) response = requests.get(url, headers=headers)
@@ -3618,7 +3630,7 @@ def handle_intervals_getworkout(rower, intervalstoken, workoutid, debug=False, *
'file': fit_filename, 'file': fit_filename,
'intervalsid': workoutid, 'intervalsid': workoutid,
'title': title, 'title': title,
'rpe': 0, 'rpe': rpe,
'notes': '', 'notes': '',
'offline': False, 'offline': False,
} }
@@ -3626,6 +3638,27 @@ def handle_intervals_getworkout(rower, intervalstoken, workoutid, debug=False, *
url = UPLOAD_SERVICE_URL url = UPLOAD_SERVICE_URL
handle_request_post(url, uploadoptions) handle_request_post(url, uploadoptions)
try:
paired_event_id = data['paired_event_id']
ws = Workout.objects.filter(uploadedtointervals=workoutid)
if is_commute:
for w in ws:
w.is_commute = True
w.save()
if ws.count() > 0:
pss = PlannedSession.objects.filter(rower=rower,intervals_icu_id=paired_event_id)
if pss.count() > 0:
for ps in pss:
for w in ws:
w.plannedsession = ps
w.save()
except KeyError:
pass
except Workout.DoesNotExist:
pass
except PlannedSession.DoesNotExist:
pass
return 1 return 1
@app.task @app.task

View File

@@ -4455,6 +4455,7 @@ def workout_edit_view(request, id=0, message="", successmessage=""):
notes = form.cleaned_data['notes'] notes = form.cleaned_data['notes']
newdragfactor = form.cleaned_data['dragfactor'] newdragfactor = form.cleaned_data['dragfactor']
thetimezone = form.cleaned_data['timezone'] thetimezone = form.cleaned_data['timezone']
is_commute = form.cleaned_data['is_commute']
try: try:
rpe = form.cleaned_data['rpe'] rpe = form.cleaned_data['rpe']
if not rpe: # pragma: no cover if not rpe: # pragma: no cover
@@ -4532,6 +4533,7 @@ def workout_edit_view(request, id=0, message="", successmessage=""):
row.boatname = boatname row.boatname = boatname
row.empowerside = empowerside row.empowerside = empowerside
row.seatnumber = seatnumber row.seatnumber = seatnumber
row.is_commute = is_commute
dragchanged = False dragchanged = False
if newdragfactor != row.dragfactor: # pragma: no cover if newdragfactor != row.dragfactor: # pragma: no cover