blockers through the db
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
from .integrations import SyncIntegration, NoTokenError
|
from .integrations import SyncIntegration, NoTokenError
|
||||||
from rowers.models import User, Rower, Workout, TombStone
|
from rowers.models import User, Rower, Workout, TombStone, SyncRecord
|
||||||
|
from django.db.utils import IntegrityError
|
||||||
|
|
||||||
from rowingdata import rowingdata
|
from rowingdata import rowingdata
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import datetime
|
import datetime
|
||||||
@@ -358,6 +360,16 @@ class C2Integration(SyncIntegration):
|
|||||||
|
|
||||||
def get_workout(self, id, *args, **kwargs):
|
def get_workout(self, id, *args, **kwargs):
|
||||||
_ = self.open()
|
_ = self.open()
|
||||||
|
|
||||||
|
record = SyncRecord(
|
||||||
|
rower = self.rower,
|
||||||
|
c2id = id,
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
record.save()
|
||||||
|
except IntegrityError:
|
||||||
|
return 0
|
||||||
|
|
||||||
_ = myqueue(queuehigh,
|
_ = myqueue(queuehigh,
|
||||||
handle_c2_getworkout,
|
handle_c2_getworkout,
|
||||||
self.user.id,
|
self.user.id,
|
||||||
@@ -413,21 +425,11 @@ 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([
|
|
||||||
w.uploadedtoc2 for w in Workout.objects.filter(user=self.rower)
|
|
||||||
])
|
|
||||||
tombstones = [
|
|
||||||
t.uploadedtoc2 for t in TombStone.objects.filter(user=self.rower)
|
|
||||||
]
|
|
||||||
parkedids = []
|
|
||||||
try:
|
|
||||||
with open('c2blocked.json', 'r') as c2blocked:
|
|
||||||
jsondata = json.load(c2blocked)
|
|
||||||
parkedids = jsondata['ids']
|
|
||||||
except: # pragma: no cover
|
|
||||||
pass
|
|
||||||
|
|
||||||
knownc2ids = uniqify(knownc2ids+tombstones+parkedids)
|
knownc2ids = uniqify([
|
||||||
|
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']
|
||||||
i = item['id']
|
i = item['id']
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from .integrations import SyncIntegration, NoTokenError
|
from .integrations import SyncIntegration, NoTokenError
|
||||||
from rowers.models import User, Rower, Workout, TombStone
|
from rowers.models import User, Rower, Workout, TombStone, SyncRecord
|
||||||
|
from django.db.utils import IntegrityError
|
||||||
|
|
||||||
from rowers import mytypes
|
from rowers import mytypes
|
||||||
from rowers.nkimportutils import *
|
from rowers.nkimportutils import *
|
||||||
@@ -88,6 +89,15 @@ class NKIntegration(SyncIntegration):
|
|||||||
_ = self.open()
|
_ = self.open()
|
||||||
r = self.rower
|
r = self.rower
|
||||||
|
|
||||||
|
record = SyncRecord(
|
||||||
|
rower = r,
|
||||||
|
nkid = id,
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
record.save()
|
||||||
|
except IntegrityError:
|
||||||
|
return 0
|
||||||
|
|
||||||
before = kwargs.get('before',0)
|
before = kwargs.get('before',0)
|
||||||
after = kwargs.get('after',0)
|
after = kwargs.get('after',0)
|
||||||
if not before:
|
if not before:
|
||||||
@@ -181,25 +191,8 @@ 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 = uniqify([
|
||||||
w.uploadedtonk for w in Workout.objects.filter(user=r)
|
record.nkid for record in SyncRecord.objects.filter(rower=r)
|
||||||
])
|
])
|
||||||
tombstones = [
|
|
||||||
t.uploadedtonk for t in TombStone.objects.filter(user=r)
|
|
||||||
]
|
|
||||||
parkedids = []
|
|
||||||
try:
|
|
||||||
with open('nkblocked.json', 'r') as nkblocked:
|
|
||||||
try:
|
|
||||||
jsondatal = json.load(nkblocked)
|
|
||||||
except:
|
|
||||||
jsondatal = {
|
|
||||||
'ids':[]
|
|
||||||
}
|
|
||||||
parkedids = jsondatal['ids']
|
|
||||||
except FileNotFoundError: # pragma: no cover
|
|
||||||
pass
|
|
||||||
|
|
||||||
knownnkids = uniqify(knownnkids+tombstones+parkedids)
|
|
||||||
workouts = []
|
workouts = []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
63
rowers/management/commands/getsyncids.py
Normal file
63
rowers/management/commands/getsyncids.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from rowers.models import Workout, TombStone, SyncRecord
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.db.utils import IntegrityError
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
ws = Workout.objects.all()
|
||||||
|
aantal = ws.count()
|
||||||
|
counter = 0
|
||||||
|
print('----- Workouts ---------')
|
||||||
|
for w in ws:
|
||||||
|
record = SyncRecord(
|
||||||
|
workout = w,
|
||||||
|
)
|
||||||
|
if w.uploadedtostrava:
|
||||||
|
record.stravaid = w.uploadedtostrava
|
||||||
|
if w.uploadedtotp:
|
||||||
|
record.tpid = w.uploadedtotp
|
||||||
|
if w.uploadedtonk:
|
||||||
|
record.nkid = w.uploadedtonk
|
||||||
|
if w.uploadedtosporttracks:
|
||||||
|
record.sporttracksid = w.uploadedtosporttracks
|
||||||
|
if w.uploadedtoc2:
|
||||||
|
record.c2id = w.uploadedtoc2
|
||||||
|
|
||||||
|
try:
|
||||||
|
record.save()
|
||||||
|
except IntegrityError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
counter += 1
|
||||||
|
if counter % 10 == 0:
|
||||||
|
print(counter,'/',aantal)
|
||||||
|
|
||||||
|
print('----- Tombstones -------')
|
||||||
|
ts = TombStone.objects.all()
|
||||||
|
aantal = ts.count()
|
||||||
|
counter = 0
|
||||||
|
for w in ts:
|
||||||
|
record = SyncRecord(
|
||||||
|
)
|
||||||
|
if w.uploadedtostrava:
|
||||||
|
record.stravaid = w.uploadedtostrava
|
||||||
|
if w.uploadedtotp:
|
||||||
|
record.tpid = w.uploadedtotp
|
||||||
|
if w.uploadedtonk:
|
||||||
|
record.nkid = w.uploadedtonk
|
||||||
|
if w.uploadedtosporttracks:
|
||||||
|
record.sporttracksid = w.uploadedtosporttracks
|
||||||
|
if w.uploadedtoc2:
|
||||||
|
record.c2id = w.uploadedtoc2
|
||||||
|
|
||||||
|
try:
|
||||||
|
record.save()
|
||||||
|
except IntegrityError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
counter += 1
|
||||||
|
if counter % 10 == 0:
|
||||||
|
print(counter,'/',aantal)
|
||||||
|
|
||||||
|
|
||||||
@@ -3447,6 +3447,7 @@ rpechoices = (
|
|||||||
(10, '10 Max Effort (You can barely remember your name, you would rather rip out your toenails than go through this)')
|
(10, '10 Max Effort (You can barely remember your name, you would rather rip out your toenails than go through this)')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Workout(models.Model):
|
class Workout(models.Model):
|
||||||
workouttypes = mytypes.workouttypes
|
workouttypes = mytypes.workouttypes
|
||||||
workoutsources = mytypes.workoutsources
|
workoutsources = mytypes.workoutsources
|
||||||
@@ -3608,7 +3609,6 @@ class TombStone(models.Model):
|
|||||||
uploadedtotp = models.BigIntegerField(default=0)
|
uploadedtotp = models.BigIntegerField(default=0)
|
||||||
uploadedtonk = models.BigIntegerField(default=0)
|
uploadedtonk = models.BigIntegerField(default=0)
|
||||||
|
|
||||||
|
|
||||||
@receiver(models.signals.pre_delete, sender=Workout)
|
@receiver(models.signals.pre_delete, sender=Workout)
|
||||||
def create_tombstone_on_delete(sender, instance, **kwargs):
|
def create_tombstone_on_delete(sender, instance, **kwargs):
|
||||||
t = TombStone(
|
t = TombStone(
|
||||||
@@ -3623,6 +3623,23 @@ def create_tombstone_on_delete(sender, instance, **kwargs):
|
|||||||
# delete files belonging to workout instance
|
# delete files belonging to workout instance
|
||||||
# related GraphImage objects should be deleted automatically
|
# related GraphImage objects should be deleted automatically
|
||||||
|
|
||||||
|
class SyncRecord(models.Model):
|
||||||
|
workout = models.ForeignKey(Workout, on_delete=models.CASCADE, null=True)
|
||||||
|
rower = models.ForeignKey(Rower, on_delete=models.CASCADE, null=True)
|
||||||
|
stravaid = models.BigIntegerField(unique=True,null=True,default=None)
|
||||||
|
sporttracksid = models.BigIntegerField(unique=True,null=True,default=None)
|
||||||
|
nkid = models.BigIntegerField(unique=True,null=True,default=None)
|
||||||
|
c2id = models.BigIntegerField(unique=True,null=True,default=None)
|
||||||
|
tpid = models.BigIntegerField(unique=True,null=True,default=None)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if self.workout:
|
||||||
|
self.rower = self.workout.user
|
||||||
|
return super(SyncRecord, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(models.signals.post_delete, sender=Workout)
|
@receiver(models.signals.post_delete, sender=Workout)
|
||||||
def auto_delete_file_on_delete(sender, instance, **kwargs):
|
def auto_delete_file_on_delete(sender, instance, **kwargs):
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ application = get_wsgi_application()
|
|||||||
from rowers.models import (
|
from rowers.models import (
|
||||||
Workout, GeoPolygon, GeoPoint, GeoCourse,
|
Workout, GeoPolygon, GeoPoint, GeoCourse,
|
||||||
VirtualRaceResult, CourseTestResult, Rower,
|
VirtualRaceResult, CourseTestResult, Rower,
|
||||||
GraphImage,
|
GraphImage, SyncRecord
|
||||||
)
|
)
|
||||||
|
|
||||||
import math
|
import math
|
||||||
@@ -84,6 +84,7 @@ import rowers.rowing_workout_metrics_pb2 as metrics_pb2
|
|||||||
import rowers.rowing_workout_metrics_pb2_grpc as metrics_pb2_grpc
|
import rowers.rowing_workout_metrics_pb2_grpc as metrics_pb2_grpc
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db.utils import IntegrityError
|
||||||
|
|
||||||
# extra read of config
|
# extra read of config
|
||||||
|
|
||||||
@@ -522,6 +523,9 @@ def handle_c2_sync(workoutid, url, headers, data, debug=False, **kwargs):
|
|||||||
workout.uploadedtoc2 = c2id
|
workout.uploadedtoc2 = c2id
|
||||||
workout.save()
|
workout.save()
|
||||||
|
|
||||||
|
record = SyncRecord(workout=workout,c2id=c2id)
|
||||||
|
record.save()
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def splitstdata(lijst):
|
def splitstdata(lijst):
|
||||||
@@ -3402,24 +3406,20 @@ def handle_nk_async_workout(alldata, userid, nktoken, nkid, delaysec, defaulttim
|
|||||||
# dologging('nklog.log','NK Workout ID {id}'.format(id=workoutid))
|
# dologging('nklog.log','NK Workout ID {id}'.format(id=workoutid))
|
||||||
workout = Workout.objects.get(id=workoutid)
|
workout = Workout.objects.get(id=workoutid)
|
||||||
newnkid = workout.uploadedtonk
|
newnkid = workout.uploadedtonk
|
||||||
|
sr = SyncRecord.objects.filter(nkid=newnkid)
|
||||||
|
if len(sr):
|
||||||
|
sr[0].workout = workout
|
||||||
|
try:
|
||||||
|
sr[0].save()
|
||||||
|
except IntegrityError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
sr = SyncRecord(workout=workout,nkid=newnkid)
|
||||||
|
try:
|
||||||
|
sr.save()
|
||||||
|
except IntegrityError:
|
||||||
|
pass
|
||||||
|
|
||||||
parkedids = []
|
|
||||||
try:
|
|
||||||
with open('nkblocked.json', 'r') as nkblocked:
|
|
||||||
jsondata = json.load(nkblocked)
|
|
||||||
parkedids = jsondata['ids']
|
|
||||||
except FileNotFoundError: # pragma: no cover
|
|
||||||
pass
|
|
||||||
|
|
||||||
newparkedids = [id for id in parkedids if id != newnkid]
|
|
||||||
with open('nkblocked.json', 'wt') as nkblocked:
|
|
||||||
tdata = {'ids': newparkedids}
|
|
||||||
nkblocked.seek(0)
|
|
||||||
json.dump(tdata, nkblocked)
|
|
||||||
|
|
||||||
# evt update workout summary
|
|
||||||
|
|
||||||
# return
|
|
||||||
return workoutid
|
return workoutid
|
||||||
|
|
||||||
|
|
||||||
@@ -3693,20 +3693,8 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec,
|
|||||||
workout = Workout.objects.get(id=workoutid)
|
workout = Workout.objects.get(id=workoutid)
|
||||||
newc2id = workout.uploadedtoc2
|
newc2id = workout.uploadedtoc2
|
||||||
|
|
||||||
parkedids = []
|
record = SyncRecord(workout=workout,c2id=newc2id)
|
||||||
with open('c2blocked.json', 'a+') as c2blocked:
|
|
||||||
try:
|
|
||||||
jsondata = json.load(c2blocked)
|
|
||||||
parkedids = jsondata['ids']
|
|
||||||
except JSONDecodeError: # pragma: no cover
|
|
||||||
parkedids = []
|
|
||||||
|
|
||||||
|
|
||||||
newparkedids = [id for id in parkedids if id != newc2id]
|
|
||||||
with open('c2blocked.json', 'wt') as c2blocked:
|
|
||||||
tdata = {'ids': newparkedids}
|
|
||||||
c2blocked.seek(0)
|
|
||||||
json.dump(tdata, c2blocked)
|
|
||||||
|
|
||||||
# set distance, time
|
# set distance, time
|
||||||
workout = Workout.objects.get(id=workoutid)
|
workout = Workout.objects.get(id=workoutid)
|
||||||
|
|||||||
@@ -743,6 +743,13 @@ class WorkoutStatsTestNew(TestCase):
|
|||||||
|
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
self.user_workouts = WorkoutFactory.create_batch(5, user=self.r)
|
self.user_workouts = WorkoutFactory.create_batch(5, user=self.r)
|
||||||
|
|
||||||
|
today = datetime.date.today()
|
||||||
|
i = 0
|
||||||
|
for w in self.user_workouts:
|
||||||
|
w.date = today-datetime.timedelta(days=i)
|
||||||
|
i += 1
|
||||||
|
w.save()
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.password = faker.word()
|
self.password = faker.word()
|
||||||
self.u.set_password(self.password)
|
self.u.set_password(self.password)
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -148,6 +148,8 @@ def do_sync(w, options, quick=False):
|
|||||||
if options['nkid'] != 0 and options['nkid'] != '': # pragma: no cover
|
if options['nkid'] != 0 and options['nkid'] != '': # pragma: no cover
|
||||||
w.uploadedtonk = options['nkid']
|
w.uploadedtonk = options['nkid']
|
||||||
w.save()
|
w.save()
|
||||||
|
record = SyncRecord(workout=w,nkid=options['nkid'])
|
||||||
|
record.save()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -182,6 +184,8 @@ def do_sync(w, options, quick=False):
|
|||||||
# upload_to_c2 = False
|
# upload_to_c2 = False
|
||||||
do_c2_export = False
|
do_c2_export = False
|
||||||
w.save()
|
w.save()
|
||||||
|
record = SyncRecord(workout=w,c2id=options['c2id'])
|
||||||
|
record.save()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -931,9 +931,11 @@ def boxplotdata(workouts, options):
|
|||||||
largerthan=False)
|
largerthan=False)
|
||||||
|
|
||||||
datadf.dropna(axis=0, how='any', inplace=True)
|
datadf.dropna(axis=0, how='any', inplace=True)
|
||||||
|
datadf = datadf[datadf['workoutid'].isin(ids) == True]
|
||||||
|
|
||||||
datadf['workoutid'].replace(datemapping, inplace=True)
|
datadf['workoutid'].replace(datemapping, inplace=True)
|
||||||
datadf.rename(columns={"workoutid": "date"}, inplace=True)
|
datadf.rename(columns={"workoutid": "date"}, inplace=True)
|
||||||
|
|
||||||
datadf['date'] = pd.to_datetime(datadf['date'], errors='coerce')
|
datadf['date'] = pd.to_datetime(datadf['date'], errors='coerce')
|
||||||
datadf = datadf.dropna(subset=['date'])
|
datadf = datadf.dropna(subset=['date'])
|
||||||
datadf = datadf.sort_values(['date'])
|
datadf = datadf.sort_values(['date'])
|
||||||
|
|||||||
Reference in New Issue
Block a user