c2 stuff now using timezone info
This commit is contained in:
@@ -1076,20 +1076,21 @@ def add_workout_from_data(user,importid,data,strokedata,
|
||||
except: # pragma: no cover
|
||||
comments = ' '
|
||||
|
||||
try:
|
||||
thetimezone = tz(data['timezone'])
|
||||
except:
|
||||
thetimezone = 'UTC'
|
||||
|
||||
thetimezone = pytz.timezone(data['timezone'])
|
||||
|
||||
|
||||
r = Rower.objects.get(user=user)
|
||||
|
||||
try:
|
||||
rowdatetime = iso8601.parse_date(data['date_utc'])
|
||||
thetimezone = 'UTC'
|
||||
except KeyError: # pragma: no cover
|
||||
rowdatetime = iso8601.parse_date(data['start_date'])
|
||||
rowdatetime = rowdatetime.make_aware(thetimezone)
|
||||
except ParseError: # pragma: no cover
|
||||
rowdatetime = iso8601.parse_date(data['date'])
|
||||
|
||||
rowdatetime = rowdatetime.make_aware(thetimezone)
|
||||
|
||||
|
||||
try:
|
||||
@@ -1119,7 +1120,9 @@ def add_workout_from_data(user,importid,data,strokedata,
|
||||
cum_time = res[0]
|
||||
lapidx = res[1]
|
||||
|
||||
starttimeunix = starttimeunix - cum_time.max()
|
||||
totaltime = data['time']/10.
|
||||
starttimeunix = starttimeunix - totaltime
|
||||
|
||||
|
||||
unixtime = cum_time+starttimeunix
|
||||
# unixtime[0] = starttimeunix
|
||||
@@ -1161,7 +1164,6 @@ def add_workout_from_data(user,importid,data,strokedata,
|
||||
velo = 1000./pace
|
||||
pace = 500./velo
|
||||
|
||||
|
||||
# save csv
|
||||
# Create data frame with all necessary data to write to csv
|
||||
df = pd.DataFrame({'TimeStamp (sec)':unixtime,
|
||||
@@ -1223,15 +1225,18 @@ def add_workout_from_data(user,importid,data,strokedata,
|
||||
|
||||
w = Workout.objects.get(id=id)
|
||||
|
||||
local_tz = pytz.timezone(data['timezone'])
|
||||
# local_tz = pytz.timezone(thetimezone)
|
||||
|
||||
w.startdatetime = w.startdatetime.astimezone(local_tz)
|
||||
w.starttime = w.startdatetime.strftime('%H:%M:%S')
|
||||
w.timezone = local_tz
|
||||
|
||||
w.duration = dataprep.totaltime_sec_to_string(totaltime)
|
||||
w.distance = totaldist
|
||||
w.startdatetime = rowdatetime
|
||||
w.starttime = rowdatetime.time()
|
||||
w.date = rowdatetime.date()
|
||||
|
||||
|
||||
w.save()
|
||||
|
||||
|
||||
|
||||
return id,message
|
||||
|
||||
@@ -1692,6 +1692,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
|
||||
|
||||
|
||||
|
||||
try:
|
||||
latavg = row.df[' latitude'].mean()
|
||||
lonavg = row.df[' longitude'].mean()
|
||||
@@ -1717,6 +1718,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
except KeyError:
|
||||
timezone_str = r.defaulttimezone
|
||||
|
||||
|
||||
duration = totaltime_sec_to_string(totaltime)
|
||||
|
||||
workoutdate = workoutstartdatetime.astimezone(
|
||||
@@ -1785,6 +1787,8 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
except ValidationError:
|
||||
return (0,'Unable to create your workout')
|
||||
|
||||
|
||||
|
||||
if privacy == 'visible':
|
||||
ts = Team.objects.filter(rower=r)
|
||||
for t in ts:
|
||||
|
||||
@@ -330,7 +330,7 @@ def create_async_workout(alldata,user,stravaid,debug=False):
|
||||
|
||||
starttime = rowdatetime.astimezone(
|
||||
pytz.timezone(thetimezone)
|
||||
).strftime('%H:%m:%S')
|
||||
).strftime('%H:%M:%S')
|
||||
|
||||
totaltime = data['elapsed_time']
|
||||
duration = dataprep.totaltime_sec_to_string(totaltime)
|
||||
|
||||
@@ -713,6 +713,9 @@ def mocked_requests(*args, **kwargs):
|
||||
with open('rowers/tests/testdata/c2jsonworkoutdata.txt','r') as infile:
|
||||
c2workoutdata = json.load(infile)
|
||||
|
||||
with open('rowers/tests/testdata/c2_timezone.json','r') as infile:
|
||||
c2timezoneworkoutdata = json.load(infile)
|
||||
|
||||
with open('rowers/tests/testdata/c2jsonstrokedata.txt','r') as infile:
|
||||
c2strokedata = json.load(infile)
|
||||
|
||||
@@ -1181,7 +1184,10 @@ def mocked_requests(*args, **kwargs):
|
||||
if c2strokestester.match(args[0]):
|
||||
return MockResponse(c2strokedata,200)
|
||||
elif c2importtester.match(args[0]):
|
||||
return MockResponse(c2workoutdata,200)
|
||||
if '12' in args[0]:
|
||||
return MockResponse(c2workoutdata,200)
|
||||
else:
|
||||
return MockResponse(c2timezoneworkoutdata,200)
|
||||
elif c2workoutlisttester.match(args[0]):
|
||||
return MockResponse(c2workoutlist,200)
|
||||
elif 'access_token' in args[0]:
|
||||
|
||||
@@ -261,6 +261,21 @@ class C2Objects(DjangoTestCase):
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
def test_c2_import_tz(self, mock_get, mocked_sqlalchemy):
|
||||
|
||||
response = self.c.get('/rowers/workout/c2import/22/',follow=True)
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url='/rowers/workout/'+encoded2+'/edit/',
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
w = Workout.objects.get(id=2)
|
||||
self.assertEqual(w.timezone,'Europe/Prague')
|
||||
|
||||
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
def test_strokedata(self, mocked_sqlalchemy):
|
||||
|
||||
@@ -2099,6 +2099,7 @@ def workout_getimportview(request,externalid,source = 'c2',do_async=False):
|
||||
|
||||
|
||||
|
||||
|
||||
workoutdate = startdatetime.astimezone(
|
||||
pytz.timezone(timezone_str)
|
||||
).strftime('%Y-%m-%d')
|
||||
|
||||
Reference in New Issue
Block a user