Private
Public Access
1
0

fixing sync wup/cd with icu

This commit is contained in:
2025-03-02 13:42:26 +01:00
parent 02a774bcf8
commit 7ee8836335
6 changed files with 75 additions and 8 deletions

View File

@@ -220,15 +220,23 @@ class IntervalsIntegration(SyncIntegration):
thetype = mytypes.intervalsmapping[workout.workouttype]
jsondict = {'type': thetype}
subtype = workout.sub_type
if subtype:
jsondict['sub_type'] = subtype
jsondict['icu_rpe'] = workout.rpe
if subtype == "Warming Up":
jsondict['sub_type'] = "WARMUP"
elif subtype == "Cooling Down":
jsondict['sub_type'] = "COOLDOWN"
elif subtype == "Commute":
jsondict['commute'] = True
jsondict['sub_type'] = "COMMUTE"
else:
jsondict['sub_type'] = "NONE"
if workout.rpe is not None and workout.rpe > 0:
jsondict['icu_rpe'] = workout.rpe
jsondict['commute'] = workout.is_commute
if workout.plannedsession:
jsondict['paired_event_id'] = workout.plannedsession.intervals_icu_id
response = requests.put(url, headers=headers, json=jsondict)
if response.status_code not in [200, 201]:
@@ -322,6 +330,14 @@ class IntervalsIntegration(SyncIntegration):
dologging('intervals.icu.log', response.text)
return 0
subtypemapping = {
'WARMUP': 'Warming Up',
'COOLDOWN': 'Cooling Down',
'COMMUTE': 'Commute',
'NONE': None,
'RACE': 'Race'
}
data = response.json()
ws = Workout.objects.filter(uploadedtointervals=id)
@@ -338,6 +354,10 @@ class IntervalsIntegration(SyncIntegration):
w.workouttype = mytypes.intervalsmappinginv[data['type']]
except KeyError:
pass
try:
w.sub_type = subtypemapping[data['sub_type']]
except KeyError:
pass
try:
w.rpe = data['icu_rpe']
if w.rpe is None:
@@ -873,7 +893,7 @@ class IntervalsIntegration(SyncIntegration):
try:
ps.comment = data['description']
except KeyError:
ps.comment = ''
ps.comment = ' '
ps.startdate = arrow.get(data['start_date_local']).datetime
ps.enddate = arrow.get(data['end_date_local']).datetime
ps.preferreddate = arrow.get(data['start_date_local']).datetime