Private
Public Access
1
0

some fixes, after manual testing

This commit is contained in:
2024-05-03 16:56:01 +02:00
parent ada06da0fc
commit ebea0047cc
6 changed files with 61 additions and 18 deletions

View File

@@ -186,10 +186,12 @@ def remove_nulls_pl(data):
data = data.select(pl.all().forward_fill())
data = data.select(pl.all().backward_fill())
data = data.fill_nan(None)
data = data.select(cs.by_dtype(pl.NUMERIC_DTYPES)).collect()
data = data[[s.name for s in data if not s.is_infinite().sum()]]
data = data[[s.name for s in data if not (s.null_count() == data.height)]]
if not data.is_empty():
try:
data = data.drop_nulls()
@@ -207,6 +209,8 @@ def get_video_data(w, groups=['basic'], mode='water'):
columns = list(set(columns))
df = getsmallrowdata_pd(columns, ids=[w.id],
workstrokesonly=False, doclean=False, compute=False)
df.dropna(axis=0, how='all', inplace=True)
df.dropna(axis=1, how='all', inplace=True)
df['time'] = (df['time']-df['time'].min())/1000.
@@ -245,7 +249,6 @@ def get_video_data(w, groups=['basic'], mode='water'):
coordinates['time'] = coordinates['time']-coordinates['time'].min()
latitude = coordinates['latitude']
longitude = coordinates['longitude']
# bundle data
data = {
'boatspeed': boatspeed.values.tolist(),
@@ -263,7 +266,10 @@ def get_video_data(w, groups=['basic'], mode='water'):
else:
sigfigs = dict(rowingmetrics)[c]['sigfigs']
if (c != 'pace'):
da = ((10**sigfigs)*df2[c]).astype(int)/(10**sigfigs)
try:
da = ((10**sigfigs)*df2[c]).astype(int)/(10**sigfigs)
except:
da = df2[c]
else:
da = df2[c]
data[c] = da.values.tolist()
@@ -281,6 +287,14 @@ def get_video_data(w, groups=['basic'], mode='water'):
maxtime = coordinates['time'].max()
data = pd.DataFrame(data)
data.replace([np.inf, -np.inf], np.nan, inplace=True)
data.dropna(inplace=True)
data = pl.from_pandas(data)
data = data.to_dict(as_series=False)
return data, metrics, maxtime
@@ -1490,7 +1504,8 @@ def getrowdata_pl(id=0, doclean=False, convertnewtons=True,
def read_data(columns, ids=[], doclean=True, workstrokesonly=True, debug=False, for_chart=False, compute=True):
def read_data(columns, ids=[], doclean=True, workstrokesonly=True, debug=False, for_chart=False, compute=True,
startenddict={}):
if ids:
csvfilenames = [
'media/strokedata_{id}.parquet.gz'.format(id=id) for id in ids]
@@ -1504,6 +1519,17 @@ def read_data(columns, ids=[], doclean=True, workstrokesonly=True, debug=False,
for id, f in zip(ids, csvfilenames):
if os.path.isfile(f):
df = pl.scan_parquet(f)
if startenddict:
try:
startsecond, endsecond = startenddict[id]
df = df.filter(pl.col("time") >= 1.0e3*startsecond,
pl.col("time") <= 1.0e3*endsecond)
df = df.with_columns(time = pl.col("time")-1.0e3*startsecond)
if 'cumdist' in columns:
df = df.collect()
df = df.with_columns(cumdist = pl.col("cumdist")-df[0, "cumdist"]).lazy()
except KeyError:
pass
data.append(df)
else:
rowdata, row = getrowdata(id=id)
@@ -1516,6 +1542,17 @@ def read_data(columns, ids=[], doclean=True, workstrokesonly=True, debug=False,
bands=True, otwpower=True, barchart=True,
polars=True)
df = pl.scan_parquet(f)
if startenddict:
try:
startsecond, endsecond = startenddict[id]
df = df.filter(pl.col("time") >= 1.0e3*startsecond,
pl.col("time") <= 1.0e3*endsecond)
df = df.with_columns(time = pl.col("time")-1.0e3*startsecond)
if 'cumdist' in columns:
df = df.collect()
df = df.with_columns(cumdist = pl.col("cumdist")-df[0, "cumdist"]).lazy()
except KeyError:
pass
data.append(df)
data = pl.collect_all(data)

View File

@@ -2099,11 +2099,12 @@ def interactive_multiple_compare_chart(ids, xparam, yparam, plottype='line',
promember=0, workstrokesonly=True,
labeldict=None, startenddict={}):
print(startenddict)
columns = [xparam,yparam]
columns_basic = [xparam,yparam]
add_columns = [
'ftime', 'distance', 'fpace',
'spm',
'spm','cumdist',
'time', 'pace', 'workoutstate',
'workoutid'
]
@@ -2117,15 +2118,17 @@ def interactive_multiple_compare_chart(ids, xparam, yparam, plottype='line',
doclean = True
datadf = pd.DataFrame()
datadf = pl.DataFrame()
if promember:
datadf = dataprep.read_data(columns, ids=ids, doclean=doclean,
compute=compute,
workstrokesonly=workstrokesonly, for_chart=True)
workstrokesonly=workstrokesonly, for_chart=True,
startenddict=startenddict)
else:
datadf = dataprep.read_data(columns_basic, ids=ids, doclean=doclean,
compute=compute,
workstrokesonly=workstrokesonly, for_chart=True)
workstrokesonly=workstrokesonly, for_chart=True,
startenddict=startenddict)
datadf = dataprep.remove_nulls_pl(datadf)
@@ -2135,6 +2138,8 @@ def interactive_multiple_compare_chart(ids, xparam, yparam, plottype='line',
datadf = datadf.with_columns(pl.col("workoutid").cast(pl.UInt32).keep_name())
# filter for start end dict
nrworkouts = len(ids)

View File

@@ -116,7 +116,7 @@ function copyText() {
</li>
{% if user.is_authenticated and user == workout.user.user and not locked %}
<li class="grid_2">
<p>Paste link to you tube video below</p>
<p>Paste link to Youtube video below</p>
<p>Use the slider to locate start point for video on workout map</p>
<p>Playing the video will advance the data in synchonization. Use the regular YouTube
controls
@@ -169,9 +169,8 @@ function copyText() {
</li>
<li class="grid_2">
<div id="player"></div>
<script>
// 1. Code for the map
{{ mapscript | safe }}
<script>
// 2. This code loads the IFrame Player API code asynchronously.
@@ -188,7 +187,8 @@ function copyText() {
var dataplaying = false;
var videotime = 0;
var data = JSON.parse('{{ data|safe }}');
var data = JSON.parse('{{ data|safe }}');
{% for id, metric in metrics.items %}
var {{ id }}_values = data["{{ id }}"];
// console.log("{{ id }}_values",{{ id }}_values);

View File

@@ -6,14 +6,9 @@
{% block main %}
<script src="https://cdn.pydata.org/bokeh/release/bokeh-3.1.1.min.js"></script>
<script async="true" type="text/javascript">
Bokeh.set_log_level("info");
</script>
<script src="https://d3js.org/d3.v6.js"></script>
<script>
{{ interactiveplot |safe }}
</script>
<h1>Interactive Comparison</h1>
@@ -22,6 +17,7 @@
<li class="grid_4">
<div>
{{ the_div|safe }}
{{ interactiveplot |safe }}
</div>
</li>

View File

@@ -387,6 +387,9 @@ def trendflexdata(workouts, options, userid=0):
datadf = dataprep.filter_df(datadf, 'driveneergy', workmax,
largerthan=False)
if yparam == 'power':
datadf = dataprep.filter_df(datadf, 'power', 1, largerthan=True)
datadf.dropna(axis=0, how='any', inplace=True)
datemapping = {

View File

@@ -347,6 +347,7 @@ def workout_video_create_view(request, id=0):
# get data
data, metrics, maxtime = dataprep.get_video_data(
w, groups=metricsgroups, mode=mode)
hascoordinates = pd.Series(data['latitude']).std() > 0
# create map
@@ -377,6 +378,7 @@ def workout_video_create_view(request, id=0):
template = 'embedded_video.html'
return render(request,
template,
{