Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2022-02-17 12:41:12 +01:00
parent 31109da378
commit e9c13d3fe7
3 changed files with 64 additions and 101 deletions

View File

@@ -2,6 +2,7 @@ from rowers.utils import totaltime_sec_to_string
from rowers.metrics import dtypes
import datetime
from scipy.signal import savgol_filter
import os
# This is Data prep used for testing purposes (no Django environment)
# Uses the debug SQLite database for stroke data
@@ -35,6 +36,12 @@ from rowers.utils import lbstoN
import pytz
from timezonefinder import TimezoneFinder
from rowingdata import (
RowProParser, TCXParser, MysteryParser, RowPerfectParser,
ErgDataParser, CoxMateParser, BoatCoachAdvancedParser, BoatCoachOTWParser,
BoatCoachParser, painsledDesktopParser, SpeedCoach2Parser, speedcoachParser,
ErgStickParser, FITParser, fitsummarydata
)
try:
user = DATABASES['default']['USER']
@@ -171,14 +178,12 @@ def create_c2_stroke_data_db(
spm = 20*np.zeros(nr_strokes)
try:
step = totalseconds/float(nr_strokes)
_ = totalseconds/float(nr_strokes)
except ZeroDivisionError:
return 0
elapsed = np.arange(nr_strokes)*totalseconds/(float(nr_strokes-1))
dstep = distance/float(nr_strokes)
d = np.arange(nr_strokes)*distance/(float(nr_strokes-1))
unixtime = starttimeunix + elapsed
@@ -215,12 +220,9 @@ def create_c2_stroke_data_db(
'cum_dist': d
})
timestr = strftime("%Y%m%d-%H%M%S")
df[' ElapsedTime (sec)'] = df['TimeStamp (sec)']
res = df.to_csv(csvfilename, index_label='index',
compression='gzip')
_ = df.to_csv(csvfilename, index_label='index', compression='gzip')
data = dataprep(df, id=workoutid, bands=False, debug=debug)
@@ -300,8 +302,6 @@ def add_c2_stroke_data_db(strokedata, workoutid, starttimeunix, csvfilename,
df.sort_values(by='TimeStamp (sec)', ascending=True)
timestr = strftime("%Y%m%d-%H%M%S")
# Create CSV file name and save data to CSV file
res = df.to_csv(csvfilename, index_label='index',
@@ -447,8 +447,7 @@ def update_empower(id, inboard, oarlength, boattype, df, f1, debug=False): # pr
if debug: # pragma: no cover
print("not updated ", id)
rowdata = dataprep(df, id=id, bands=True, barchart=True, otwpower=True,
debug=debug)
_ = dataprep(df, id=id, bands=True, barchart=True, otwpower=True, debug=debug)
row = rrdata(df=df)
row.write_csv(f1, gzip=True)
@@ -511,7 +510,7 @@ def update_workout_field_sql(workoutid, fieldname, value, debug=False):
table, fieldname, value, workoutid)
with engine.connect() as conn, conn.begin():
result = conn.execute(query)
_ = conn.execute(query)
conn.close()
engine.dispose()
@@ -527,7 +526,7 @@ def update_c2id_sql(id, c2id): # pragma: no cover
table, c2id, id)
with engine.connect() as conn, conn.begin():
result = conn.execute(query)
_ = conn.execute(query)
conn.close()
engine.dispose()
@@ -588,7 +587,7 @@ def getcpdata_sql(rower_id, table='cpdata', debug=False): # pragma: no cover
rower_id=rower_id,
table=table,
))
connection = engine.raw_connection()
_ = engine.raw_connection()
df = pd.read_sql_query(query, engine)
return df
@@ -606,7 +605,7 @@ def deletecpdata_sql(rower_id, table='cpdata', debug=False): # pragma: no cover
))
with engine.connect() as conn, conn.begin():
try:
result = conn.execute(query)
_ = conn.execute(query)
except: # pragma: no cover
print("Database locked")
conn.close()
@@ -627,7 +626,7 @@ def delete_agegroup_db(age, sex, weightcategory, debug=False):
))
with engine.connect() as conn, conn.begin():
try:
result = conn.execute(query)
_ = conn.execute(query)
except: # pragma: no cover
print("Database locked")
conn.close()
@@ -687,7 +686,7 @@ def updatecpdata_sql(rower_id, delta, cp, table='cpdata', distance=pd.Series([],
else:
engine = create_engine(database_url, echo=False)
with engine.connect() as conn, conn.begin():
with engine.connect() as conn, conn.begin():
df.to_sql(table, engine, if_exists='append', index=False)
conn.close()
engine.dispose()
@@ -818,7 +817,7 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
if forceunit == 'lbs':
driveenergy = drivelength*averageforce*lbstoN
else: # pragma: no cover
drivenergy = drivelength*averageforce
driveenergy = drivelength*averageforce
distance = rowdatadf.loc[:, 'cum_dist']
@@ -865,7 +864,7 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
data['hr_bottom'] = 0.0*data['hr']
try:
tel = rowdatadf.loc[:, ' ElapsedTime (sec)']
_ = rowdatadf.loc[:, ' ElapsedTime (sec)']
except KeyError: # pragma: no cover
rowdatadf[' ElapsedTime (sec)'] = rowdatadf['TimeStamp (sec)']