Private
Public Access
1
0

fixes in rp3, performance chart

This commit is contained in:
Sander Roosendaal
2023-01-18 19:43:32 +01:00
parent 22385d606f
commit b5d1090f6a
5 changed files with 47 additions and 13 deletions

View File

@@ -1214,7 +1214,12 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
delta = datetime.timedelta( delta = datetime.timedelta(
seconds=totaltime) seconds=totaltime)
workoutenddatetime = workoutstartdatetime+delta try:
workoutenddatetime = workoutstartdatetime+delta
except AttributeError as e:
workoutstartdatetime = pendulum.parse(str(workoutstartdatetime))
workoutenddatetime = workoutstartdatetime+delta
# check for duplicate start times and duration # check for duplicate start times and duration
duplicate = checkduplicates( duplicate = checkduplicates(

View File

@@ -67,6 +67,7 @@ from rowers.models import (
) )
import pytz import pytz
from pytz.exceptions import UnknownTimeZoneError
import collections import collections
import pendulum import pendulum
from rowingdata import rowingdata as rrdata from rowingdata import rowingdata as rrdata
@@ -915,6 +916,12 @@ parsers = {
def get_startdate_time_zone(r, row, startdatetime=None): def get_startdate_time_zone(r, row, startdatetime=None):
if isinstance(startdatetime, str):
try:
startdatetime = pendulum.parse(startdatetime)
except:
dologging('debuglog.log','Could not parse start date time '+startdatetime)
if startdatetime is not None and startdatetime != '': if startdatetime is not None and startdatetime != '':
try: try:
timezone_str = pendulum.instance(startdatetime).timezone.name timezone_str = pendulum.instance(startdatetime).timezone.name
@@ -969,8 +976,11 @@ def get_startdate_time_zone(r, row, startdatetime=None):
else: else:
timezone_str = str(startdatetime.tzinfo) timezone_str = str(startdatetime.tzinfo)
startdatetime = startdatetime.astimezone(pytz.timezone(timezone_str)) try:
startdatetime = startdatetime.astimezone(pytz.timezone(timezone_str))
except UnknownTimeZoneError:
startdatetime = startdatetime.astimezone(pytz.utc)
startdate = startdatetime.strftime('%Y-%m-%d') startdate = startdatetime.strftime('%Y-%m-%d')
starttime = startdatetime.strftime('%H:%M:%S') starttime = startdatetime.strftime('%H:%M:%S')

View File

@@ -1524,16 +1524,16 @@ def getfatigues(
for w in ws: for w in ws:
if getattr(w, metricchoice) > 0: if getattr(w, metricchoice) > 0:
weight += getattr(w, metricchoice) weight += getattr(w, metricchoice)
if getattr(w, metricchoice) <= 0: if getattr(w, metricchoice) == 0:
if metricchoice == 'rscore' and w.hrtss > 0: # pragma: no cover if metricchoice == 'rscore' and w.hrtss > 0: # pragma: no cover
weight += w.hrtss weight += w.hrtss
else: if getattr(w, metricchoice) < 0:
trimp, hrtss = dataprep.workout_trimp(w) trimp, hrtss = dataprep.workout_trimp(w)
rscore, normp = dataprep.workout_rscore(w) rscore, normp = dataprep.workout_rscore(w)
if w.rpe and w.rpe > 0: # pragma: no cover if w.rpe and w.rpe > 0: # pragma: no cover
dd = 3600*w.duration.hour+60*w.duration.minute+w.duration.second dd = 3600*w.duration.hour+60*w.duration.minute+w.duration.second
dd = dd/3600 dd = dd/3600
weight += rpetotss[w.rpe]*dd weight += rpetotss[w.rpe]*dd
impulses.append(weight) impulses.append(weight)

View File

@@ -9,13 +9,15 @@ from rowsandall_app.settings import (
RP3_CLIENT_ID, RP3_CLIENT_KEY, RP3_REDIRECT_URI, RP3_CLIENT_SECRET, RP3_CLIENT_ID, RP3_CLIENT_KEY, RP3_REDIRECT_URI, RP3_CLIENT_SECRET,
UPLOAD_SERVICE_URL, UPLOAD_SERVICE_SECRET UPLOAD_SERVICE_URL, UPLOAD_SERVICE_SECRET
) )
from rowers.utils import myqueue from rowers.utils import myqueue, NoTokenError
# All the functionality needed to connect to Runkeeper # All the functionality needed to connect to Runkeeper
from rowers.imports import * from rowers.imports import *
# Python # Python
import gzip import gzip
from datetime import timedelta
import base64 import base64
from io import BytesIO from io import BytesIO
@@ -48,6 +50,11 @@ graphql_url = "https://rp3rowing-app.com/graphql"
# Checks if user has UnderArmour token, renews them if they are expired # Checks if user has UnderArmour token, renews them if they are expired
def rp3_open(user): def rp3_open(user):
tokenexpirydate = user.rower.rp3tokenexpirydate
if timezone.now()-timedelta(days=120)>tokenexpirydate:
user.rower.rp3tokenexpirydate = timezone.now()-timedelta(days=1)
user.rower.save()
raise NoTokenError
return imports_open(user, oauth_data) return imports_open(user, oauth_data)
# Refresh ST token using refresh token # Refresh ST token using refresh token
@@ -137,8 +144,12 @@ def get_rp3_workouts(rower, do_async=True): # pragma: no cover
w.uploadedtorp3 for w in Workout.objects.filter(user=rower) w.uploadedtorp3 for w in Workout.objects.filter(user=rower)
]) ])
dologging('rp3_import.log',rp3ids)
newids = [rp3id for rp3id in rp3ids if rp3id not in knownrp3ids] newids = [rp3id for rp3id in rp3ids if rp3id not in knownrp3ids]
dologging('rp3_import.log',newids)
for id in newids: for id in newids:
startdatetime = workouts_list.loc[id, 'executed_at'] startdatetime = workouts_list.loc[id, 'executed_at']
dologging('rp3_import.log', startdatetime) dologging('rp3_import.log', startdatetime)
@@ -150,7 +161,7 @@ def get_rp3_workouts(rower, do_async=True): # pragma: no cover
auth_token, auth_token,
id, id,
startdatetime, startdatetime,
10, 20,
) )
return 1 return 1

View File

@@ -2967,6 +2967,7 @@ def handle_rp3_async_workout(userid, rp3token, rp3id, startdatetime, max_attempt
headers=headers, headers=headers,
json={'query': get_download_link} json={'query': get_download_link}
) )
dologging('rp3_import.log',response.status_code)
if response.status_code != 200: # pragma: no cover if response.status_code != 200: # pragma: no cover
have_link = True have_link = True
@@ -2974,6 +2975,7 @@ def handle_rp3_async_workout(userid, rp3token, rp3id, startdatetime, max_attempt
try: try:
workout_download_details = pd.json_normalize( workout_download_details = pd.json_normalize(
response.json()['data']['download']) response.json()['data']['download'])
dologging('rp3_import.log', response.json())
except: # pragma: no cover except: # pragma: no cover
return 0 return 0
@@ -2981,8 +2983,12 @@ def handle_rp3_async_workout(userid, rp3token, rp3id, startdatetime, max_attempt
download_url = workout_download_details.iat[0, 2] download_url = workout_download_details.iat[0, 2]
have_link = True have_link = True
dologging('rp3_import.log', download_url)
counter += 1 counter += 1
dologging('rp3_import.log', counter)
if counter > max_attempts: # pragma: no cover if counter > max_attempts: # pragma: no cover
have_link = True have_link = True
@@ -2994,6 +3000,8 @@ def handle_rp3_async_workout(userid, rp3token, rp3id, startdatetime, max_attempt
filename = 'media/RP3Import_'+str(rp3id)+'.csv' filename = 'media/RP3Import_'+str(rp3id)+'.csv'
res = requests.get(download_url, headers=headers) res = requests.get(download_url, headers=headers)
dologging('rp3_import.log','tasks.py '+str(rp3id))
dologging('rp3_import.log',startdatetime)
if not startdatetime: # pragma: no cover if not startdatetime: # pragma: no cover
startdatetime = str(timezone.now()) startdatetime = str(timezone.now())