Private
Public Access
1
0

Added StrokeData model

This commit is contained in:
Sander Roosendaal
2016-11-22 23:17:46 +01:00
parent d57ecb495b
commit 73f4c713a0
2 changed files with 82 additions and 2 deletions

View File

@@ -9,6 +9,29 @@ from pandas import DataFrame,Series
import pandas as pd
import numpy as np
from django.conf import settings
from sqlalchemy import create_engine
import sqlalchemy as sa
user = settings.DATABASES['default']['USER']
password = settings.DATABASES['default']['PASSWORD']
database_name = settings.DATABASES['default']['NAME']
host = settings.DATABASES['default']['HOST']
port = settings.DATABASES['default']['PORT']
database_url = 'mysql://{user}:{password}@{host}:{port}/{database_name}'.format(
user=user,
password=password,
database_name=database_name,
host=host,
port=port,
)
if settings.DEBUG:
database_url = 'sqlite:///db.sqlite3'
engine = create_engine(database_url, echo=False)
from scipy.signal import savgol_filter
import datetime
@@ -59,6 +82,14 @@ def rdata(file,rower=rrower()):
return res
def getrowdata_db(id=0):
data = read_df_sql(id)
if data.empty:
rowdata,row = getrowdata(id=id)
data = dataprep(rowdata.df,id=id,bands=True,barchart=True,otwpower=True)
return data
def getrowdata(id=0):
# check if valid ID exists (workout exists)
@@ -79,7 +110,15 @@ def getrowdata(id=0):
return rowdata,row
def dataprep(rowdatadf,bands=False,barchart=False,otwpower=False):
# temporary
def read_df_sql(id):
df = pd.read_sql_query(sa.text('SELECT * FROM strokedata WHERE workoutid={id}'.format(
id=id)), engine)
return df
def dataprep(rowdatadf,id=0,bands=False,barchart=False,otwpower=False):
rowdatadf.set_index([range(len(rowdatadf))],inplace=True)
t = rowdatadf.ix[:,'TimeStamp (sec)']
t = pd.Series(t-rowdatadf.ix[0,'TimeStamp (sec)'])
@@ -193,5 +232,11 @@ def dataprep(rowdatadf,bands=False,barchart=False,otwpower=False):
data = data.replace([-np.inf,np.inf],np.nan)
data = data.fillna(method='ffill')
# write data if id given
if id != 0:
data['workoutid'] = id
with engine.connect() as conn, conn.begin():
data.to_sql('strokedata',engine,if_exists='append',index=False)
return data

View File

@@ -121,6 +121,41 @@ def auto_delete_file_on_delete(sender, instance, **kwargs):
os.remove(instance.csvfilename)
class StrokeData(models.Model):
class Meta:
db_table = 'strokedata'
workoutid = models.IntegerField(null=True)
time = models.TimeField(null=True)
timesecs = models.FloatField(null=True)
hr = models.IntegerField(null=True)
pace = models.TimeField(null=True)
pseconds = models.FloatField(null=True)
spm = models.FloatField(null=True)
cumdist = models.FloatField(null=True)
ftime = models.CharField(max_length=30)
fpace = models.CharField(max_length=30)
driveenergy = models.FloatField(null=True)
power = models.FloatField(null=True)
averageforce = models.FloatField(null=True)
drivelength = models.FloatField(null=True)
peakforce = models.FloatField(null=True)
forceratio = models.FloatField(null=True)
distance = models.FloatField(null=True)
drivespeed = models.FloatField(null=True)
hr_ut2 = models.IntegerField(null=True)
hr_ut1 = models.IntegerField(null=True)
hr_at = models.IntegerField(null=True)
hr_tr = models.IntegerField(null=True)
hr_an = models.IntegerField(null=True)
hr_max = models.IntegerField(null=True)
hr_bottom = models.IntegerField(null=True)
x_right = models.FloatField(null=True)
ergpace = models.TimeField(null=True)
nowindpace = models.TimeField(null=True)
equivergpower = models.FloatField(null=True)
fergpace = models.CharField(max_length=30)
fnowindpace = models.CharField(max_length=30)
class GraphImage(models.Model):
filename = models.CharField(default='',max_length=150,blank=True,null=True)