fixes icu
This commit is contained in:
@@ -169,7 +169,10 @@ class IntervalsIntegration(SyncIntegration):
|
||||
|
||||
|
||||
def workout_export(self, workout, *args, **kwargs) -> str:
|
||||
token = self.open()
|
||||
try:
|
||||
token = self.open()
|
||||
except NoTokenError:
|
||||
return 0
|
||||
dologging('intervals.icu.log', "Exporting workout {id}".format(id=workout.id))
|
||||
|
||||
filename = self.createworkoutdata(workout)
|
||||
@@ -220,6 +223,11 @@ class IntervalsIntegration(SyncIntegration):
|
||||
return id
|
||||
|
||||
def get_workout_list(self, *args, **kwargs) -> int:
|
||||
try:
|
||||
token = self.open()
|
||||
except NoTokenError:
|
||||
return []
|
||||
|
||||
url = self.oauth_data['base_url'] + 'athlete/0/activities?'
|
||||
startdate = timezone.now() - timedelta(days=30)
|
||||
enddate = timezone.now() + timedelta(days=1)
|
||||
@@ -238,7 +246,7 @@ class IntervalsIntegration(SyncIntegration):
|
||||
url += 'oldest=' + startdate.strftime('%Y-%m-%d') + '&newest=' + enddate.strftime('%Y-%m-%d')
|
||||
headers = {
|
||||
'accept': '*/*',
|
||||
'authorization': 'Bearer ' + self.open(),
|
||||
'authorization': 'Bearer ' + token
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
@@ -278,7 +286,10 @@ class IntervalsIntegration(SyncIntegration):
|
||||
return workouts
|
||||
|
||||
def update_workout(self, id, *args, **kwargs) -> int:
|
||||
_ = self.open()
|
||||
try:
|
||||
_ = self.open()
|
||||
except NoTokenError:
|
||||
return 0
|
||||
r = self.rower
|
||||
|
||||
headers = {
|
||||
@@ -308,8 +319,10 @@ class IntervalsIntegration(SyncIntegration):
|
||||
pass
|
||||
try:
|
||||
w.rpe = data['icu_rpe']
|
||||
if w.rpe is None:
|
||||
w.rpe = 0
|
||||
except KeyError:
|
||||
pass
|
||||
w.rpe = 0
|
||||
try:
|
||||
w.is_commute = data['commute']
|
||||
if w.is_commute is None:
|
||||
@@ -387,7 +400,11 @@ class IntervalsIntegration(SyncIntegration):
|
||||
return 1
|
||||
|
||||
def get_workout(self, id, *args, **kwargs) -> int:
|
||||
_ = self.open()
|
||||
try:
|
||||
_ = self.open()
|
||||
except NoTokenError:
|
||||
return 0
|
||||
|
||||
r = self.rower
|
||||
|
||||
do_async = kwargs.get('do_async', True)
|
||||
@@ -506,7 +523,7 @@ class IntervalsIntegration(SyncIntegration):
|
||||
|
||||
return 1
|
||||
|
||||
def pair_workout_and_session(w, id):
|
||||
def pair_workout_and_session(self, w, id):
|
||||
pass
|
||||
|
||||
|
||||
@@ -541,7 +558,11 @@ class IntervalsIntegration(SyncIntegration):
|
||||
return super(IntervalsIntegration, self).token_refresh(*args, **kwargs)
|
||||
|
||||
def get_plannedsessions_list(self, *args, **kwargs):
|
||||
_ = self.open()
|
||||
try:
|
||||
_ = self.open()
|
||||
except NoTokenError:
|
||||
return []
|
||||
|
||||
r = self.rower
|
||||
|
||||
headers = {
|
||||
@@ -562,7 +583,11 @@ class IntervalsIntegration(SyncIntegration):
|
||||
return data
|
||||
|
||||
def update_plannedsession(self, ps, data, *args, **kwargs):
|
||||
_ = self.open()
|
||||
try:
|
||||
_ = self.open()
|
||||
except NoTokenError:
|
||||
return 0
|
||||
|
||||
r = self.rower
|
||||
|
||||
if data['category'] == 'WORKOUT':
|
||||
@@ -584,7 +609,11 @@ class IntervalsIntegration(SyncIntegration):
|
||||
return data
|
||||
|
||||
def get_plannedsession(self, id, *args, **kwargs):
|
||||
_ = self.open()
|
||||
try:
|
||||
_ = self.open()
|
||||
except NoTokenError:
|
||||
return 0
|
||||
|
||||
r = self.rower
|
||||
|
||||
url = self.oauth_data['base_url'] + 'athlete/0/events/' + str(id)
|
||||
@@ -618,7 +647,11 @@ class IntervalsIntegration(SyncIntegration):
|
||||
return data
|
||||
|
||||
def plannedsession_create(self, ps, *args, **kwargs):
|
||||
_ = self.open()
|
||||
try:
|
||||
_ = self.open()
|
||||
except NoTokenError:
|
||||
return 0
|
||||
|
||||
r = self.rower
|
||||
|
||||
headers = {
|
||||
@@ -626,6 +659,7 @@ class IntervalsIntegration(SyncIntegration):
|
||||
}
|
||||
|
||||
stepstext = ps.steps_intervals()
|
||||
print(stepstext)
|
||||
|
||||
category = 'WORKOUT'
|
||||
startdate = ps.preferreddate.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
@@ -671,7 +705,11 @@ class IntervalsIntegration(SyncIntegration):
|
||||
return id
|
||||
|
||||
def plannedsession_delete(self, ps, *args, **kwargs):
|
||||
_ = self.open()
|
||||
try:
|
||||
_ = self.open()
|
||||
except NoTokenError:
|
||||
return 0
|
||||
|
||||
r = self.rower
|
||||
|
||||
headers = {
|
||||
@@ -750,9 +788,12 @@ class IntervalsIntegration(SyncIntegration):
|
||||
ps.sessionvalue = timetarget
|
||||
ps.save()
|
||||
if data['category'].lower() == 'workout':
|
||||
ps.fitfile = data['fitfile']
|
||||
ps.save()
|
||||
ps.update_steps()
|
||||
try:
|
||||
ps.fitfile = data['fitfile']
|
||||
ps.save()
|
||||
ps.update_steps()
|
||||
except KeyError:
|
||||
pass
|
||||
if data['category'].lower() == 'target':
|
||||
ps.sessiontype = 'cycletarget'
|
||||
ps.sessionvalue = int(data['time_target'])/60.
|
||||
|
||||
@@ -25,6 +25,7 @@ from rowingdata import rowingdata as rrdata
|
||||
import arrow
|
||||
import polars as pl
|
||||
import json
|
||||
from rowers import integrations
|
||||
|
||||
# Python
|
||||
from django.utils import timezone
|
||||
@@ -418,7 +419,7 @@ def add_workouts_plannedsession(ws, ps, r):
|
||||
comments.append('Attached workout %s to session' %
|
||||
encoder.encode_hex(w.id))
|
||||
if ps.intervals_icu_id:
|
||||
integration = integrations.IntervalsIntegration(w.user)
|
||||
integration = integrations.IntervalsIntegration(w.user.user)
|
||||
integration.pair_workout_and_session(w, ps.intervals_icu_id)
|
||||
if ps.sessiontype == 'coursetest': # pragma: no cover
|
||||
record = CourseTestResult(
|
||||
|
||||
@@ -137,17 +137,9 @@
|
||||
<a class="small"
|
||||
href="https://intervals.icu/?w={{ ps.preferreddate }}"><i class="fa-kit fa-solid-wave-pulse-circle-check"></i></a>
|
||||
{% else %}
|
||||
{% if request.GET.startdate %}
|
||||
<a class="small"
|
||||
href="/rowers/sessions/{{ ps.id }}/tointervals/?next={{ request.path }}?startdate={{ request.GET.startdate }}&enddate={{ request.GET.enddate }}"><i class="fa-solid fa-wave-pulse"></i></a>
|
||||
{% elif request.GET.when %}
|
||||
<a class="small"
|
||||
href="/rowers/sessions/{{ ps.id }}/tointervals/?next={{ request.path }}?when={{ request.GET.when }}"><i class="fa-solid fa-wave-pulse"></i></a>
|
||||
{% else %}
|
||||
<a class="small"
|
||||
href="/rowers/sessions/{{ ps.id }}/tointervals/?next={{ request.path }}"><i class="fa-solid fa-wave-pulse"></i></a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
<td> {{ ps.sessionvalue }} </td>
|
||||
|
||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -737,6 +737,10 @@ def steps_write_fit(steps):
|
||||
url = settings.WORKOUTS_FIT_URL+"/tofit"
|
||||
headers = {'Authorization': authorizationstring}
|
||||
|
||||
# convert to json, value of keys called wkt_step_name to string
|
||||
for step in steps['steps']:
|
||||
step['wkt_step_name'] = str(step['wkt_step_name'])
|
||||
|
||||
response = requests.post(url=url, headers=headers, json=steps)
|
||||
|
||||
if response.status_code != 200: # pragma: no cover
|
||||
|
||||
@@ -33,7 +33,9 @@ def filmdeaths_view(request):
|
||||
|
||||
@login_required()
|
||||
def download_fit(request, filename=''):
|
||||
print(filename)
|
||||
pss = PlannedSession.objects.filter(fitfile=filename)
|
||||
print(pss, len(pss))
|
||||
|
||||
if len(pss) != 1: # pragma: no cover
|
||||
raise Http404("Could not find the required file")
|
||||
|
||||
@@ -1841,6 +1841,8 @@ def plannedsession_clone_view(request, id=0, userid=0):
|
||||
if not ps.is_template:
|
||||
ps.name += ' (copy)'
|
||||
ps.is_template = False
|
||||
ps.intervals_icu_id = None
|
||||
ps.rojabo_id = 0
|
||||
|
||||
deltadays = ps.preferreddate-ps.startdate
|
||||
|
||||
@@ -2057,11 +2059,6 @@ def plannedsession_tointervals_view(request, id=0):
|
||||
|
||||
r = getrequestplanrower(request)
|
||||
|
||||
startdate, enddate = get_dates_timeperiod(request)
|
||||
startdate = startdate.date()
|
||||
enddate = enddate.date()
|
||||
|
||||
|
||||
ps = get_object_or_404(PlannedSession, pk=id)
|
||||
|
||||
intervals = IntervalsIntegration(request.user)
|
||||
@@ -2077,13 +2074,14 @@ def plannedsession_tointervals_view(request, id=0):
|
||||
url = reverse(plannedsession_view, kwargs={'userid': r.user.id,
|
||||
'id': ps.id, })
|
||||
|
||||
startdatestring = startdate.strftime('%Y-%m-%d')
|
||||
enddatestring = enddate.strftime('%Y-%m-%d')
|
||||
url += '?when='+startdatestring+'/'+enddatestring
|
||||
thenext = request.GET.get('next', url)
|
||||
|
||||
next = request.GET.get('next', url)
|
||||
# add ?startdate=startdate&enddate=enddate to url, with startdate ps.startdate and enddate ps.enddate
|
||||
startdate = ps.startdate.strftime('%Y-%m-%d')
|
||||
enddate = ps.enddate.strftime('%Y-%m-%d')
|
||||
url += '?startdate='+startdate+'&enddate='+enddate
|
||||
|
||||
return HttpResponseRedirect(next)
|
||||
return HttpResponseRedirect(thenext)
|
||||
|
||||
|
||||
@permission_required('plannedsession.change_session', fn=get_session_by_pk, raise_exception=True)
|
||||
@@ -2114,7 +2112,7 @@ def plannedsession_togarmin_view(request, id=0):
|
||||
|
||||
startdatestring = startdate.strftime('%Y-%m-%d')
|
||||
enddatestring = enddate.strftime('%Y-%m-%d')
|
||||
url += '?when='+startdatestring+'/'+enddatestring
|
||||
url += '?startdate='+startdatestring+'&enddate='+enddatestring
|
||||
|
||||
next = request.GET.get('next', url)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user