further timezone magic c2
This commit is contained in:
@@ -238,7 +238,7 @@ def create_async_workout(alldata,user,c2id):
|
|||||||
duration = dataprep.totaltime_sec_to_string(totaltime)
|
duration = dataprep.totaltime_sec_to_string(totaltime)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
timezone_str = tz(data['timezone'])
|
timezone_str = data['timezone']
|
||||||
except:
|
except:
|
||||||
timezone_str = 'UTC'
|
timezone_str = 'UTC'
|
||||||
|
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ def handle_c2_import_stroke_data(c2token,
|
|||||||
duration = datetime.datetime.strptime(duration,'%H:%M:%S.%f').time()
|
duration = datetime.datetime.strptime(duration,'%H:%M:%S.%f').time()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
timezone_str = tz(workoutdata['timezone'])
|
timezone_str = workoutdata['timezone']
|
||||||
except:
|
except:
|
||||||
timezone_str = 'UTC'
|
timezone_str = 'UTC'
|
||||||
|
|
||||||
@@ -2991,7 +2991,7 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
|||||||
c2id = data['id']
|
c2id = data['id']
|
||||||
workouttype = data['type']
|
workouttype = data['type']
|
||||||
verified = data['verified']
|
verified = data['verified']
|
||||||
startdatetime = iso8601.parse_date(data['date'])
|
startdatetime = iso8601.parse_date(data['date_utc'])
|
||||||
weightclass = data['weight_class']
|
weightclass = data['weight_class']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -3013,21 +3013,18 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
|||||||
|
|
||||||
totaltime = data['time']/10.
|
totaltime = data['time']/10.
|
||||||
duration = totaltime_sec_to_string(totaltime)
|
duration = totaltime_sec_to_string(totaltime)
|
||||||
|
starttimeunix = arrow.get(startdatetime).timestamp()-totaltime
|
||||||
|
startdatetime = arrow.get(starttimeunix)
|
||||||
|
|
||||||
try:
|
timezone = pytz.timezone(data['timezone'])
|
||||||
timezone_str = tz(data['timezone'])
|
startdatetime = startdatetime.astimezone(timezone)
|
||||||
except:
|
|
||||||
timezone_str = defaulttimezone
|
|
||||||
|
|
||||||
startdatetime = startdatetime.replace(tzinfo=None)
|
|
||||||
tz = pytz.timezone(timezone_str)
|
|
||||||
startdatetime = tz.localize(startdatetime)
|
|
||||||
|
|
||||||
workoutdate = startdatetime.astimezone(
|
workoutdate = startdatetime.astimezone(
|
||||||
pytz.timezone(timezone_str)
|
timezone
|
||||||
).strftime('%Y-%m-%d')
|
).strftime('%Y-%m-%d')
|
||||||
starttime = startdatetime.astimezone(
|
starttime = startdatetime.astimezone(
|
||||||
pytz.timezone(timezone_str)
|
timezone
|
||||||
).strftime('%H:%M:%S')
|
).strftime('%H:%M:%S')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -3056,8 +3053,6 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
|||||||
cum_time = res[0]
|
cum_time = res[0]
|
||||||
lapidx = res[1]
|
lapidx = res[1]
|
||||||
|
|
||||||
starttimeunix = arrow.get(startdatetime).timestamp()
|
|
||||||
starttimeunix = starttimeunix-cum_time.max()
|
|
||||||
|
|
||||||
unixtime = cum_time+starttimeunix
|
unixtime = cum_time+starttimeunix
|
||||||
# unixtime[0] = starttimeunix
|
# unixtime[0] = starttimeunix
|
||||||
@@ -3134,6 +3129,7 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
|||||||
'workouttype':workouttype,
|
'workouttype':workouttype,
|
||||||
'boattype':'1x',
|
'boattype':'1x',
|
||||||
'c2id':c2id,
|
'c2id':c2id,
|
||||||
|
'timezone':str(timezone)
|
||||||
}
|
}
|
||||||
|
|
||||||
session = requests.session()
|
session = requests.session()
|
||||||
@@ -3165,8 +3161,11 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
|||||||
|
|
||||||
parkedids = []
|
parkedids = []
|
||||||
with open('c2blocked.json','r') as c2blocked:
|
with open('c2blocked.json','r') as c2blocked:
|
||||||
jsondata = json.load(c2blocked)
|
try:
|
||||||
parkedids = jsondata['ids']
|
jsondata = json.load(c2blocked)
|
||||||
|
parkedids = jsondata['ids']
|
||||||
|
except JSONDecodeError:
|
||||||
|
parkedids = []
|
||||||
|
|
||||||
newparkedids = [id for id in parkedids if id != newc2id]
|
newparkedids = [id for id in parkedids if id != newc2id]
|
||||||
with open('c2blocked.json','wt') as c2blocked:
|
with open('c2blocked.json','wt') as c2blocked:
|
||||||
@@ -3364,7 +3363,7 @@ def fetch_strava_workout(stravatoken,oauth_data,stravaid,csvfilename,userid,debu
|
|||||||
comments = ' '
|
comments = ' '
|
||||||
|
|
||||||
try:
|
try:
|
||||||
thetimezone = tz(workoutsummary['timezone'])
|
thetimezone = workoutsummary['timezone']
|
||||||
except:
|
except:
|
||||||
thetimezone = 'UTC'
|
thetimezone = 'UTC'
|
||||||
|
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ class C2Objects(DjangoTestCase):
|
|||||||
self.r.c2token = '12'
|
self.r.c2token = '12'
|
||||||
self.r.c2refreshtoken = 'ab'
|
self.r.c2refreshtoken = 'ab'
|
||||||
self.r.tokenexpirydate = arrow.get(datetime.datetime.now()+datetime.timedelta(days=1)).datetime
|
self.r.tokenexpirydate = arrow.get(datetime.datetime.now()+datetime.timedelta(days=1)).datetime
|
||||||
|
self.r.defaulttimezone = 'Europe/Prague'
|
||||||
self.r.save()
|
self.r.save()
|
||||||
self.c.login(username='john',password='koeinsloot')
|
self.c.login(username='john',password='koeinsloot')
|
||||||
|
|
||||||
@@ -342,6 +343,7 @@ class C2Objects(DjangoTestCase):
|
|||||||
res = tasks.handle_c2_async_workout(alldata,self.u.id,self.r.c2token,33991243,0,self.r.defaulttimezone)
|
res = tasks.handle_c2_async_workout(alldata,self.u.id,self.r.c2token,33991243,0,self.r.defaulttimezone)
|
||||||
self.assertEqual(res,1)
|
self.assertEqual(res,1)
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TESTING=True)
|
@override_settings(TESTING=True)
|
||||||
class C2ObjectsTokenExpired(DjangoTestCase):
|
class C2ObjectsTokenExpired(DjangoTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|||||||
@@ -4813,8 +4813,8 @@ def workout_upload_api(request):
|
|||||||
totalDistance = post_data.get('totalDistance',None)
|
totalDistance = post_data.get('totalDistance',None)
|
||||||
elapsedTime = post_data.get('elapsedTime',None)
|
elapsedTime = post_data.get('elapsedTime',None)
|
||||||
summary = post_data.get('summary',None)
|
summary = post_data.get('summary',None)
|
||||||
|
timezone = post_data.get('timezone',None)
|
||||||
|
|
||||||
r = None
|
r = None
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
t = form.cleaned_data['title']
|
t = form.cleaned_data['title']
|
||||||
@@ -4905,6 +4905,13 @@ def workout_upload_api(request):
|
|||||||
return JSONResponse(status=200,data=message)
|
return JSONResponse(status=200,data=message)
|
||||||
|
|
||||||
w = Workout.objects.get(id=id)
|
w = Workout.objects.get(id=id)
|
||||||
|
if timezone is not None:
|
||||||
|
w.startdatetime = w.startdatetime.astimezone(pytz.timezone(timezone))
|
||||||
|
w.workoutdate = w.startdatetime.strftime('%Y-%m-%d')
|
||||||
|
w.starttime = w.starttime.strftime('%H:%M:%S')
|
||||||
|
w.timezone = timezone
|
||||||
|
w.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if make_plot: # pragma: no cover
|
if make_plot: # pragma: no cover
|
||||||
|
|||||||
Reference in New Issue
Block a user