Private
Public Access
1
0

removing obsolete rowingdata(csvfile)

This commit is contained in:
Sander Roosendaal
2019-11-11 17:31:56 +01:00
parent 23909feabf
commit 2294603129
6 changed files with 152 additions and 156 deletions

View File

@@ -65,7 +65,7 @@ def rower_sporttracks_token_refresh(user):
r.sporttracksrefreshtoken = refresh_token
r.save()
return r.sporttrackstoken
# Get list of workouts available on SportTracks
@@ -117,10 +117,10 @@ def get_workout(user,sporttracksid):
# Create Workout Data for upload to SportTracks
def createsporttracksworkoutdata(w):
timezone = pytz.timezone(w.timezone)
filename = w.csvfilename
try:
row = rowingdata(filename)
row = rowingdata(csvfile=filename)
except:
return 0
@@ -130,7 +130,7 @@ def createsporttracksworkoutdata(w):
except KeyError:
averagehr = 0
maxhr = 0
duration = w.duration.hour*3600
duration += w.duration.minute*60
duration += w.duration.second
@@ -148,9 +148,9 @@ def createsporttracksworkoutdata(w):
spm = row.df[' Cadence (stokes/min)'].astype(int).values
spm[0] = spm[1]
hr = row.df[' HRCur (bpm)'].astype(int).values
haslatlon=1
try:
lat = row.df[' latitude'].values
lon = row.df[' longitude'].values
@@ -159,7 +159,7 @@ def createsporttracksworkoutdata(w):
except KeyError:
haslatlon = 0
haspower = 1
try:
power = row.df[' Power (watts)'].astype(int).values
@@ -200,7 +200,7 @@ def createsporttracksworkoutdata(w):
w.notes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com'
except TypeError:
w.notes = 'from '+w.workoutsource+' via rowsandall.com'
st = w.startdatetime.astimezone(timezone)
st = st.replace(microsecond=0)
@@ -246,17 +246,17 @@ def getidfromresponse(response):
uri = t['uris'][0]
regex = '.*?sporttracks\.mobi\/api\/v2\/fitnessActivities/(\d+)\.json$'
m = re.compile(regex).match(uri).group(1)
id = int(m)
return int(id)
def default(o):
if isinstance(o, numpy.int64): return int(o)
if isinstance(o, numpy.int64): return int(o)
raise TypeError
def workout_sporttracks_upload(user,w):
message = "Uploading to SportTracks"
stid = 0
@@ -298,7 +298,7 @@ def workout_sporttracks_upload(user,w):
message = "Something went wrong in workout_sporttracks_upload_view: %s" % s.reason
stid = 0
return message,stid
else:
message = "You are not authorized to upload this workout"
stid = 0
@@ -314,7 +314,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
workouttype = data['type']
except KeyError:
workouttype = 'other'
if workouttype not in [x[0] for x in Workout.workouttypes]:
workouttype = 'other'
try:
@@ -322,7 +322,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
except:
comments = ''
r = Rower.objects.get(user=user)
try:
rowdatetime = iso8601.parse_date(data['start_time'])
@@ -359,7 +359,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
try:
l = data['location']
res = splitstdata(l)
times_location = res[0]
latlong = res[1]
@@ -377,7 +377,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
loncoord = np.zeros(len(times_distance))
if workouttype in mytypes.otwtypes:
workouttype = 'rower'
try:
res = splitstdata(data['cadence'])
times_spm = res[0]
@@ -385,7 +385,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
except KeyError:
times_spm = times_distance
spm = 0*times_distance
try:
res = splitstdata(data['heartrate'])
hr = res[1]
@@ -417,7 +417,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
' HRCur (bpm)' : hrseries,
}
df = pd.DataFrame(d)
@@ -427,7 +427,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
df[' ElapsedTime (sec)'] = cum_time
velo = df[' Horizontal (meters)'].diff()/df[' ElapsedTime (sec)'].diff()
df[' Power (watts)'] = 0.0*velo
nr_rows = len(velo.values)
@@ -444,10 +444,10 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
unixtime = cum_time+starttimeunix
unixtime[0] = starttimeunix
df['TimeStamp (sec)'] = unixtime
dt = np.diff(cum_time).mean()
wsize = round(5./dt)
@@ -459,7 +459,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
df = df.fillna(0)
df.sort_values(by='TimeStamp (sec)',ascending=True)
timestr = strftime("%Y%m%d-%H%M%S")
# csvfilename ='media/Import_'+str(importid)+'.csv'