passing tests
This commit is contained in:
@@ -183,38 +183,6 @@ stcollection = (
|
||||
|
||||
stmapping = {key:value for key,value in Reverse(stcollection)}
|
||||
|
||||
rkcollection = (
|
||||
('water','Rowing'),
|
||||
('rower','Rowing'),
|
||||
('skierg','Cross-Country Skiing'),
|
||||
('bike','Cycling'),
|
||||
('bikeerg','Cycling'),
|
||||
('dynamic','Rowing'),
|
||||
('slides','Rowing'),
|
||||
('paddle','Other:Paddling'),
|
||||
('snow','Cross-Country Skiing'),
|
||||
('coastal','Rowing'),
|
||||
('c-boat','Rowing'),
|
||||
('churchboat','Rowing'),
|
||||
('Ride','Cycling'),
|
||||
('Run','Running'),
|
||||
('NordicSki','Cross-Country Skiing'),
|
||||
('Swim','Swimming'),
|
||||
('Hike','Hiking'),
|
||||
('Walk','Walking'),
|
||||
('Canoeing','Other'),
|
||||
('Crossfit','CrossFit'),
|
||||
('StandUpPaddling','Other'),
|
||||
('IceSkate','Skating'),
|
||||
('WeightTraining','Other'),
|
||||
('InlineSkate','Skating'),
|
||||
('Kayaking','Other'),
|
||||
('Workout','Other'),
|
||||
('other','Other'),
|
||||
('Yoga','Other'),
|
||||
)
|
||||
|
||||
rkmapping = {key:value for key,value in Reverse(rkcollection)}
|
||||
|
||||
polarcollection = (
|
||||
('water','Rowing'),
|
||||
@@ -320,7 +288,6 @@ stravamappinginv = {value:key for key,value in Reverse(stravacollection) if valu
|
||||
|
||||
stmappinginv = {value:key for key,value in Reverse(stcollection) if value is not None}
|
||||
|
||||
rkmappinginv = {value:key for key,value in Reverse(rkcollection) if value is not None}
|
||||
|
||||
polarmappinginv = {value:key for key,value in Reverse(polarcollection) if value is not None}
|
||||
|
||||
@@ -365,7 +332,6 @@ workoutsources = (
|
||||
('strava','strava'),
|
||||
('concept2','concept2'),
|
||||
('sporttracks','sporttracks'),
|
||||
('runkeeper','runkeeper'),
|
||||
('mapmyfitness','mapmyfitness'),
|
||||
('csv','painsled'),
|
||||
('tcx','tcx'),
|
||||
|
||||
@@ -382,118 +382,9 @@ def async_get_workout(user,stravaid):
|
||||
return job
|
||||
|
||||
# Get a Strava workout summary data and stroke data by ID
|
||||
def get_workout(user,stravaid,do_async=False):
|
||||
if do_async: # pragma: no cover
|
||||
res = async_get_workout(user,stravaid)
|
||||
return {},pd.DataFrame()
|
||||
try:
|
||||
thetoken = strava_open(user)
|
||||
except NoTokenError: # pragma: no cover
|
||||
s = "Token error"
|
||||
return custom_exception_handler(401,s)
|
||||
def get_workout(user,stravaid,do_async=True):
|
||||
return async_get_workout(user,stravaid)
|
||||
|
||||
r = Rower.objects.get(user=user)
|
||||
if (r.stravatoken == '') or (r.stravatoken is None): # pragma: no cover
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
return custom_exception_handler(401,s)
|
||||
elif (r.stravatokenexpirydate is not None and timezone.now()>r.stravatokenexpirydate): # pragma: no cover
|
||||
s = "Token expired. Needs to refresh."
|
||||
return custom_exception_handler(401,s)
|
||||
else:
|
||||
# ready to fetch. Hurray
|
||||
fetchresolution = 'high'
|
||||
series_type = 'time'
|
||||
authorizationstring = str('Bearer ' + r.stravatoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
'Content-Type': 'application/json',
|
||||
'resolution': 'medium',}
|
||||
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)
|
||||
workoutsummary = requests.get(url,headers=headers).json()
|
||||
|
||||
workoutsummary['timezone'] = "Etc/UTC"
|
||||
try:
|
||||
startdatetime = workoutsummary['start_date']
|
||||
except KeyError: # pragma: no cover
|
||||
startdatetime = timezone.now()
|
||||
|
||||
spm = get_strava_stream(r,'cadence',stravaid)
|
||||
hr = get_strava_stream(r,'heartrate',stravaid)
|
||||
t = get_strava_stream(r,'time',stravaid)
|
||||
velo = get_strava_stream(r,'velocity_smooth',stravaid)
|
||||
d = get_strava_stream(r,'distance',stravaid)
|
||||
coords = get_strava_stream(r,'latlng',stravaid)
|
||||
power = get_strava_stream(r,'watts',stravaid)
|
||||
|
||||
if t is not None:
|
||||
nr_rows = len(t)
|
||||
else: # pragma: no cover
|
||||
duration = int(workoutsummary['elapsed_time'])
|
||||
t = pd.Series(range(duration+1))
|
||||
|
||||
nr_rows = len(t)
|
||||
|
||||
|
||||
if nr_rows == 0: # pragma: no cover
|
||||
return (0,"Error: Time data had zero length")
|
||||
|
||||
if d is None: # pragma: no cover
|
||||
d = 0*t
|
||||
|
||||
if spm is None: # pragma: no cover
|
||||
spm = np.zeros(nr_rows)
|
||||
|
||||
if power is None: # pragma: no cover
|
||||
power = np.zeros(nr_rows)
|
||||
|
||||
if hr is None: # pragma: no cover
|
||||
hr = np.zeros(nr_rows)
|
||||
|
||||
if velo is None: # pragma: no cover
|
||||
velo = np.zeros(nr_rows)
|
||||
|
||||
dt = np.diff(t).mean()
|
||||
wsize = round(5./dt)
|
||||
|
||||
velo2 = ewmovingaverage(velo,wsize)
|
||||
|
||||
if coords is not None:
|
||||
try:
|
||||
lat = coords[:,0]
|
||||
lon = coords[:,1]
|
||||
except IndexError: # pragma: no cover
|
||||
lat = np.zeros(len(t))
|
||||
lon = np.zeros(len(t))
|
||||
else: # pragma: no cover
|
||||
lat = np.zeros(len(t))
|
||||
lon = np.zeros(len(t))
|
||||
|
||||
|
||||
|
||||
|
||||
strokelength = velo*60./(spm)
|
||||
strokelength[np.isinf(strokelength)] = 0.0
|
||||
|
||||
|
||||
pace = 500./(1.0*velo2)
|
||||
pace[np.isinf(pace)] = 0.0
|
||||
|
||||
df = pd.DataFrame({'t':10*t,
|
||||
'd':10*d,
|
||||
'p':10*pace,
|
||||
'spm':spm,
|
||||
'hr':hr,
|
||||
'lat':lat,
|
||||
'lon':lon,
|
||||
'power':power,
|
||||
'strokelength':strokelength,
|
||||
})
|
||||
|
||||
|
||||
|
||||
# startdatetime = datetime.datetime.strptime(startdatetime,"%Y-%m-%d-%H:%M:%S")
|
||||
|
||||
return [workoutsummary,df]
|
||||
|
||||
# Generate Workout data for Strava (a TCX file)
|
||||
def createstravaworkoutdata(w,dozip=True):
|
||||
|
||||
@@ -66,6 +66,7 @@ from django.utils import timezone
|
||||
from django.utils.html import strip_tags
|
||||
|
||||
from rowers.utils import deserialize_list,ewmovingaverage,wavg,dologging
|
||||
import rowers.utils as utils
|
||||
from rowers.emails import htmlstrip
|
||||
from rowers import mytypes
|
||||
|
||||
@@ -317,20 +318,6 @@ def handle_sporttracks_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
||||
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_runkeeper_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
||||
response = requests.post(url,headers=headers,data=data)
|
||||
if response.status_code not in [200,201]: # pragma: no cover
|
||||
return 0
|
||||
|
||||
uri = response.headers["Location"]
|
||||
|
||||
tester = re.compile('^\/fitnessActivities\/(\d+)$')
|
||||
id = int(tester.match(uri).group(1))
|
||||
|
||||
res = update_workout_field_sql(workoutid,'uploadedtorunkeeper',id,debug=debug)
|
||||
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_strava_sync(stravatoken,workoutid,filename,name,activity_type,description,debug=False,**kwargs):
|
||||
@@ -3008,10 +2995,7 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
||||
c2id = data['id']
|
||||
workouttype = data['type']
|
||||
verified = data['verified']
|
||||
try:
|
||||
startdatetime = iso8601.parse_date(data['date_utc'])
|
||||
except: # pragma: no cover
|
||||
startdatetime = iso8601.parse_date(data['date'])
|
||||
|
||||
weightclass = data['weight_class']
|
||||
|
||||
s = 'User {userid}, C2 ID {c2id}'.format(userid=userid,c2id=c2id)
|
||||
@@ -3035,16 +3019,8 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
||||
# Create CSV file name and save data to CSV file
|
||||
csvfilename ='media/Import_'+str(c2id)+'.csv.gz'
|
||||
|
||||
totaltime = data['time']/10.
|
||||
duration = totaltime_sec_to_string(totaltime)
|
||||
starttimeunix = arrow.get(startdatetime).timestamp()-totaltime
|
||||
startdatetime = arrow.get(starttimeunix)
|
||||
startdatetime,starttime,workoutdate,duration,starttimeunix,timezone = utils.get_startdatetime_from_c2data(data)
|
||||
|
||||
try:
|
||||
timezone = pytz.timezone(data['timezone'])
|
||||
except UnknownTimeZoneError:
|
||||
timezone = 'UTC'
|
||||
startdatetime = startdatetime.astimezone(timezone)
|
||||
|
||||
s = 'Time zone {timezone}, stardatetime {startdatetime}, duration {duration}'.format(
|
||||
timezone=timezone,startdatetime=startdatetime,
|
||||
@@ -3053,12 +3029,7 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
||||
|
||||
|
||||
|
||||
workoutdate = startdatetime.astimezone(
|
||||
timezone
|
||||
).strftime('%Y-%m-%d')
|
||||
starttime = startdatetime.astimezone(
|
||||
timezone
|
||||
).strftime('%H:%M:%S')
|
||||
|
||||
|
||||
try:
|
||||
notes = data['comments']
|
||||
|
||||
@@ -334,6 +334,16 @@ def mocked_getsmallrowdata_db(*args, **kwargs):
|
||||
|
||||
return df
|
||||
|
||||
def mocked_getsmallrowdata_db_updatecp(*args, **kwargs):
|
||||
df = pd.read_csv('rowers/tests/testdata/colsfromdb.csv')
|
||||
|
||||
return df
|
||||
|
||||
def mocked_getsmallrowdata_db_setcp(*args, **kwargs):
|
||||
df = pd.read_csv('rowers/tests/testdata/colsfromdb.csv')
|
||||
|
||||
return df
|
||||
|
||||
|
||||
def mocked_getsmallrowdata_db_water(*args, **kwargs):
|
||||
df = pd.read_csv('rowers/tests/testdata/colsfromdb.csv')
|
||||
|
||||
@@ -462,22 +462,6 @@ class AsyncTaskTests(TestCase):
|
||||
res = tasks.handle_sporttracks_sync(1,url,headers,json.dumps(data,default=sporttracksstuff.default))
|
||||
self.assertEqual(res,1)
|
||||
|
||||
@patch('rowers.runkeeperstuff.requests.post', side_effect=mocked_requests)
|
||||
@patch('rowers.runkeeperstuff.requests.get', side_effect=mocked_requests)
|
||||
def test_runkeeper_sync(self, mock_get, mock_post):
|
||||
authorizationstring = str('Bearer aap')
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
'Content-Type': 'application/vnd.com.runkeeper.NewFitnessActivity+json',
|
||||
'Content-Length':'nnn'}
|
||||
|
||||
url = "https://api.runkeeper.com/fitnessActivities"
|
||||
|
||||
data = runkeeperstuff.createrunkeeperworkoutdata(self.wwater)
|
||||
|
||||
|
||||
res = tasks.handle_runkeeper_sync(1,url,headers,json.dumps(data,default=sporttracksstuff.default))
|
||||
self.assertEqual(res,1)
|
||||
|
||||
@patch('rowers.c2stuff.requests.post',side_effect=mocked_requests)
|
||||
@patch('rowers.c2stuff.requests.get',side_effect=mocked_requests)
|
||||
@@ -518,14 +502,14 @@ class AsyncTaskTests(TestCase):
|
||||
self.assertEqual(res,1)
|
||||
|
||||
|
||||
@patch('rowers.dataprepnodjango.getsmallrowdata_db')
|
||||
@patch('rowers.dataprepnodjango.getsmallrowdata_db_updatecp')
|
||||
def test_handle_updatecp(self,mocked_getsmallrowdata_db):
|
||||
rower_id = 1
|
||||
workoutids = [1]
|
||||
res = tasks.handle_updatecp(rower_id,workoutids)
|
||||
self.assertEqual(res,1)
|
||||
|
||||
@patch('rowers.dataprepnodjango.getsmallrowdata_db')
|
||||
@patch('rowers.dataprepnodjango.getsmallrowdata_db_setcp')
|
||||
def test_handle_setcp(self,mocked_getsmallrowdata_db):
|
||||
strokesdf = pd.read_csv('rowers/tests/testdata/uhfull.csv')
|
||||
filename = 'rowers/tests/testdata/temp/pq.gz'
|
||||
|
||||
@@ -19,6 +19,8 @@ from rowers import stravastuff
|
||||
import urllib
|
||||
import json
|
||||
|
||||
import rowers.utils as utils
|
||||
|
||||
from django.db import transaction
|
||||
import rowers.garmin_stuff as gs
|
||||
|
||||
@@ -326,7 +328,7 @@ class C2Objects(DjangoTestCase):
|
||||
def test_c2_import_tz(self, mock_get, mocked_sqlalchemy):
|
||||
|
||||
response = self.c.get('/rowers/workout/c2import/22/',follow=True)
|
||||
expected_url = '/rower/workout/c2list/'
|
||||
expected_url = '/rowers/workout/c2list/'
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url=expected_url,
|
||||
@@ -334,8 +336,10 @@ class C2Objects(DjangoTestCase):
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
w = Workout.objects.get(id=2)
|
||||
self.assertEqual(w.timezone,'Europe/Prague')
|
||||
with open('rowers/tests/testdata/c2_timezone.json','r') as infile:
|
||||
data = json.load(infile)
|
||||
timezone = str(utils.get_timezone_from_c2data(data['data']))
|
||||
self.assertEqual(timezone,'Europe/Prague')
|
||||
|
||||
|
||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
||||
@@ -343,7 +347,7 @@ class C2Objects(DjangoTestCase):
|
||||
def test_c2_import_tz3(self, mock_get, mocked_sqlalchemy):
|
||||
|
||||
response = self.c.get('/rowers/workout/c2import/32/',follow=True)
|
||||
expected_url = '/rower/workout/c2list/'
|
||||
expected_url = '/rowers/workout/c2list/'
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url=expected_url,
|
||||
@@ -351,15 +355,18 @@ class C2Objects(DjangoTestCase):
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
w = Workout.objects.get(id=2)
|
||||
self.assertEqual(w.timezone,'UTC')
|
||||
with open('rowers/tests/testdata/c2_timezonebad.json','r') as infile:
|
||||
data = json.load(infile)
|
||||
|
||||
timezone = str(utils.get_timezone_from_c2data(data['data']))
|
||||
self.assertEqual(timezone,'UTC')
|
||||
|
||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
def test_c2_import_tz2(self, mock_get, mocked_sqlalchemy):
|
||||
|
||||
response = self.c.get('/rowers/workout/c2import/31/',follow=True)
|
||||
expected_url = '/rower/workout/c2list/'
|
||||
expected_url = '/rowers/workout/c2list/'
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url=expected_url,
|
||||
@@ -367,10 +374,14 @@ class C2Objects(DjangoTestCase):
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
w = Workout.objects.get(id=2)
|
||||
self.assertEqual(w.timezone,'Europe/Amsterdam')
|
||||
with open('rowers/tests/testdata/c2_timezone2.json','r') as infile:
|
||||
data = json.load(infile)
|
||||
|
||||
self.assertEqual(w.starttime.strftime("%H:%M:%S"),"20:04:56")
|
||||
timezone = str(utils.get_timezone_from_c2data(data['data']))
|
||||
self.assertEqual(timezone,'Europe/Amsterdam')
|
||||
|
||||
startdatetime,starttime,workoutdate,duration,starttimeunix,timezone = utils.get_startdatetime_from_c2data(data['data'])
|
||||
self.assertEqual(starttime,"20:04:55")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -94,14 +94,10 @@
|
||||
104,127,workout_sporttracksimport_view,list workouts to be imported (test stops at notokenerror),TRUE,302,basic,302,302,basic,403,403,coach,302,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
105,129,workout_getsporttracksworkout_all,gets all C2 workouts (now redirects due to NoTokenError,TRUE,302,basic,302,302,FALSE,302,302,FALSE,302,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
106,130,workout_polarimport_view,list workouts to be imported (test stops at notokenerror),TRUE,302,basic,302,302,basic,403,403,coach,302,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
107,132,workout_runkeeperimport_view,list workouts to be imported (test stops at notokenerror),TRUE,302,basic,302,302,basic,403,403,coach,302,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
108,134,workout_underarmourimport_view,list workouts to be imported (test stops at notokenerror),TRUE,302,basic,302,302,basic,403,403,coach,302,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
109,135,workout_c2_upload_view,uploads workout to C2,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,TRUE,FALSE,FALSE,
|
||||
110,136,workout_strava_upload_view,uploads workout to C2,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,TRUE,FALSE,FALSE,
|
||||
111,137,workout_recalcsummary_view,recalculates workout summary,TRUE,403,basic,302,403,basic,403,403,coach,302,403,FALSE,FALSE,TRUE,TRUE,TRUE,
|
||||
112,138,workout_sporttracks_upload_view,uploads workout to C2,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,TRUE,FALSE,FALSE,
|
||||
113,139,workout_runkeeper_upload_view,uploads workout to C2,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,TRUE,FALSE,FALSE,
|
||||
114,140,workout_underarmour_upload_view,uploads workout to C2,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,TRUE,FALSE,FALSE,
|
||||
115,141,workout_tp_upload_view,uploads workout to C2,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,TRUE,FALSE,FALSE,
|
||||
116,142,multi_compare_view,compare workouts ,TRUE,302,basic,302,403,basic,302,403,coach,302,302,FALSE,FALSE,TRUE,TRUE,TRUE,
|
||||
117,145,alerts_view,view alerts,TRUE,302,basic,200,403,basic,403,403,coach,200,302,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
@@ -151,11 +147,8 @@
|
||||
165,210,rower_revokeapp_view,revoke app,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
166,211,rower_strava_authorize,authorize on strava,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
167,212,rower_sporttracks_authorize,authorize on sporttracks,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
168,213,rower_underarmour_authorize,authorize on UA,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
169,214,rower_tp_authorize,authorize on TP,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
170,215,rower_runkeeper_authorize,authorize on RK,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
171,216,rower_sporttracks_token_refresh,refresh token,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
172,217,rower_underarmour_token_refresh,refresh token,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
173,218,rower_tp_token_refresh,refresh token,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
174,219,rower_c2_token_refresh,refresh token,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
175,220,rower_favoritecharts_view,See favorite charts,TRUE,302,pro,200,302,pro,403,403,coach,200,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
@@ -232,9 +225,7 @@
|
||||
247,343,rower_process_callback,Tested in specific test suite,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
248,344,rower_process_stravacallback,Tested in specific test suite,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
249,345,rower_process_sporttrackscallback,Tested in specific test suite,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
250,346,rower_process_underarmourcallback,Tested in specific test suite,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
251,347,rower_process_polarcallback,Tested in specific test suite,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
252,348,rower_process_runkeepercallback,Tested in specific test suite,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
253,349,rower_process_tpcallback,Tested in specific test suite,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
254,350,rower_process_twittercallback,Tested in specific test suite,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
255,351,set_language,Set language,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
|
||||
|
@@ -26,6 +26,11 @@ import requests
|
||||
from django.http import HttpResponse
|
||||
|
||||
import humanize
|
||||
from pytz.exceptions import UnknownTimeZoneError
|
||||
import pytz
|
||||
import iso8601
|
||||
from iso8601 import ParseError
|
||||
import arrow
|
||||
|
||||
lbstoN = 4.44822
|
||||
|
||||
@@ -1232,3 +1237,37 @@ def intervals_to_string(vals, units, typ):
|
||||
s = s[1:]
|
||||
|
||||
return s
|
||||
|
||||
def get_timezone_from_c2data(data):
|
||||
|
||||
try:
|
||||
timezone = pytz.timezone(data['timezone'])
|
||||
except UnknownTimeZoneError:
|
||||
timezone = pytz.utc
|
||||
except KeyError:
|
||||
timezone = pytz.utc
|
||||
|
||||
return timezone
|
||||
|
||||
|
||||
def get_startdatetime_from_c2data(data):
|
||||
timezone = get_timezone_from_c2data(data)
|
||||
try:
|
||||
startdatetime = iso8601.parse_date(data['date_utc'])
|
||||
except: # pragma: no cover
|
||||
startdatetime = iso8601.parse_date(data['date'])
|
||||
|
||||
totaltime = data['time']/10.
|
||||
duration = totaltime_sec_to_string(totaltime)
|
||||
starttimeunix = arrow.get(startdatetime).timestamp()-totaltime
|
||||
startdatetime = arrow.get(starttimeunix)
|
||||
startdatetime = startdatetime.astimezone(timezone)
|
||||
|
||||
workoutdate = startdatetime.astimezone(
|
||||
timezone
|
||||
).strftime('%Y-%m-%d')
|
||||
starttime = startdatetime.astimezone(
|
||||
timezone
|
||||
).strftime('%H:%M:%S')
|
||||
|
||||
return startdatetime,starttime,workoutdate,duration,starttimeunix,timezone
|
||||
|
||||
Reference in New Issue
Block a user