improving syncrecord functionality, now also for workout export
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
from .integrations import SyncIntegration, NoTokenError
|
from .integrations import SyncIntegration, NoTokenError, create_or_update_syncrecord, get_known_ids
|
||||||
from rowers.models import User, Rower, Workout, TombStone, SyncRecord
|
from rowers.models import User, Rower, Workout, TombStone
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
|
|
||||||
from rowingdata import rowingdata
|
from rowingdata import rowingdata
|
||||||
@@ -360,15 +360,9 @@ class C2Integration(SyncIntegration):
|
|||||||
|
|
||||||
def get_workout(self, id, *args, **kwargs):
|
def get_workout(self, id, *args, **kwargs):
|
||||||
_ = self.open()
|
_ = self.open()
|
||||||
|
r = self.rower
|
||||||
|
|
||||||
record = SyncRecord(
|
record = create_or_update_syncrecord(r, None, c2id=id)
|
||||||
rower = self.rower,
|
|
||||||
c2id = id,
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
record.save()
|
|
||||||
except IntegrityError:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
_ = myqueue(queuehigh,
|
_ = myqueue(queuehigh,
|
||||||
handle_c2_getworkout,
|
handle_c2_getworkout,
|
||||||
@@ -428,9 +422,7 @@ class C2Integration(SyncIntegration):
|
|||||||
workouts = []
|
workouts = []
|
||||||
c2ids = [item['id'] for item in res.json()['data']]
|
c2ids = [item['id'] for item in res.json()['data']]
|
||||||
|
|
||||||
knownc2ids = uniqify([
|
knownc2ids = get_known_ids(r, 'c2id')
|
||||||
record.c2id for record in SyncRecord.objects.filter(rower=r)
|
|
||||||
])
|
|
||||||
|
|
||||||
for item in res.json()['data']:
|
for item in res.json()['data']:
|
||||||
d = item['distance']
|
d = item['distance']
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from abc import ABCMeta, ABC, abstractmethod
|
from abc import ABCMeta, ABC, abstractmethod
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from rowers.models import Rower, User, create_or_update_syncrecord
|
from rowers.models import Rower, User, create_or_update_syncrecord, get_known_ids
|
||||||
from rowers.utils import NoTokenError,dologging
|
from rowers.utils import NoTokenError,dologging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from .integrations import SyncIntegration, NoTokenError, create_or_update_syncrecord
|
from .integrations import SyncIntegration, NoTokenError, create_or_update_syncrecord, get_known_ids
|
||||||
from rowers.models import User, Rower, Workout, TombStone, SyncRecord
|
from rowers.models import User, Rower, Workout, TombStone
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
|
|
||||||
from rowers import mytypes
|
from rowers import mytypes
|
||||||
@@ -185,9 +185,7 @@ class NKIntegration(SyncIntegration):
|
|||||||
|
|
||||||
# get NK IDs
|
# get NK IDs
|
||||||
nkids = [item['id'] for item in jsondata]
|
nkids = [item['id'] for item in jsondata]
|
||||||
knownnkids = uniqify([
|
knownnkids = get_known_ids(r, 'nkid')
|
||||||
record.nkid for record in SyncRecord.objects.filter(rower=r)
|
|
||||||
])
|
|
||||||
workouts = []
|
workouts = []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from rowers.courseutils import coordinate_in_path
|
|||||||
from rowers.utils import (
|
from rowers.utils import (
|
||||||
# workflowleftpanel, workflowmiddlepanel,
|
# workflowleftpanel, workflowmiddlepanel,
|
||||||
defaultleft, defaultmiddle, landingpages, landingpages2,
|
defaultleft, defaultmiddle, landingpages, landingpages2,
|
||||||
steps_read_fit, steps_write_fit, ps_dict_order
|
steps_read_fit, steps_write_fit, ps_dict_order, uniqify
|
||||||
)
|
)
|
||||||
from rowers.metrics import axlabels
|
from rowers.metrics import axlabels
|
||||||
from rowers.utils import geo_distance
|
from rowers.utils import geo_distance
|
||||||
@@ -3631,6 +3631,28 @@ class SyncRecord(models.Model):
|
|||||||
self.rower = self.workout.user
|
self.rower = self.workout.user
|
||||||
return super(SyncRecord, self).save(*args, **kwargs)
|
return super(SyncRecord, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
str = 'SyncRecord {i} {r} {w} '.format(
|
||||||
|
i = self.id,
|
||||||
|
r = self.rower,
|
||||||
|
w = self.workout,
|
||||||
|
)
|
||||||
|
|
||||||
|
str2 = ''
|
||||||
|
|
||||||
|
for field in ['stravaid', 'sporttracksid', 'nkid', 'c2id', 'tpid']:
|
||||||
|
value = getattr(self, field, None)
|
||||||
|
if value is not None:
|
||||||
|
str2 += '{w}: {v},'.format(
|
||||||
|
w = field,
|
||||||
|
v = value
|
||||||
|
)
|
||||||
|
|
||||||
|
if str2:
|
||||||
|
str = str+'('+str2+')'
|
||||||
|
|
||||||
|
return str
|
||||||
|
|
||||||
def create_or_update_syncrecord(rower, workout, **kwargs):
|
def create_or_update_syncrecord(rower, workout, **kwargs):
|
||||||
try:
|
try:
|
||||||
kwargs.pop('rower')
|
kwargs.pop('rower')
|
||||||
@@ -3674,7 +3696,12 @@ def create_or_update_syncrecord(rower, workout, **kwargs):
|
|||||||
|
|
||||||
return record
|
return record
|
||||||
|
|
||||||
|
def get_known_ids(rower, field_name):
|
||||||
|
knownids = uniqify(
|
||||||
|
getattr(record, field_name, None) for record in SyncRecord.objects.filter(rower=rower)
|
||||||
|
)
|
||||||
|
|
||||||
|
return knownids
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -405,6 +405,7 @@ def check_tp_workout_id(workout, location, attempts=5, debug=False, **kwargs):
|
|||||||
if status == 'Success':
|
if status == 'Success':
|
||||||
tpid = response.json()['WorkoutIds'][0]
|
tpid = response.json()['WorkoutIds'][0]
|
||||||
workout.uploadedtotp = tpid
|
workout.uploadedtotp = tpid
|
||||||
|
record = create_or_update_syncrecord(workout.user, workout, tpid=tpid)
|
||||||
workout.save()
|
workout.save()
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
@@ -432,6 +433,7 @@ def handle_workout_tp_upload(w, thetoken, tcxfilename, debug=False, **kwargs):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
w.uploadedtotp = res
|
w.uploadedtotp = res
|
||||||
|
record = create_or_update_syncrecord(w.user, w, tpid=tpid)
|
||||||
tpid = res
|
tpid = res
|
||||||
w.save()
|
w.save()
|
||||||
os.remove(tcxfilename)
|
os.remove(tcxfilename)
|
||||||
@@ -729,7 +731,7 @@ def handle_sporttracks_sync(workoutid, url, headers, data, debug=False, **kwargs
|
|||||||
workout = Workout.objects.get(id=workoutid)
|
workout = Workout.objects.get(id=workoutid)
|
||||||
workout.uploadedtosporttracks = id
|
workout.uploadedtosporttracks = id
|
||||||
workout.save()
|
workout.save()
|
||||||
|
record = create_or_update_syncrecord(workout.user, workout, sporttracksid=id)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -798,6 +800,7 @@ def handle_strava_sync(stravatoken,
|
|||||||
|
|
||||||
workout.uploadedtostrava = res.id
|
workout.uploadedtostrava = res.id
|
||||||
workout.save()
|
workout.save()
|
||||||
|
record = create_or_update_syncrecord(workout.user, workout, stravaid=res.id)
|
||||||
try:
|
try:
|
||||||
act = client.update_activity(res.id, activity_type=activity_type,
|
act = client.update_activity(res.id, activity_type=activity_type,
|
||||||
description=description, device_name='Rowsandall.com')
|
description=description, device_name='Rowsandall.com')
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
Reference in New Issue
Block a user