From 7ab56936dac0e5d57394e8a36f9ca2e1acfa1165 Mon Sep 17 00:00:00 2001
From: Sander Roosendaal
Date: Fri, 29 Mar 2024 08:57:39 +0100
Subject: [PATCH] removed activity_chart
---
rowers/interactiveplots.py | 182 +---------------------------
rowers/templates/history.html | 9 --
rowers/templates/list_workouts.html | 19 +--
rowers/views/workoutviews.py | 2 +-
4 files changed, 7 insertions(+), 205 deletions(-)
diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py
index 09626c66..905e0fe3 100644
--- a/rowers/interactiveplots.py
+++ b/rowers/interactiveplots.py
@@ -441,186 +441,8 @@ def interactive_planchart(data, startdate, enddate):
return script, div
-def interactive_activitychart(workouts, startdate, enddate, stack='type', toolbar_location=None,
- yaxis='trimp'):
- dates = []
- dates_sorting = []
- types = []
- rowers = []
- durations = []
- rscores = []
- trimps = []
- links = []
-
- rowersinitials = {}
- seen = ['seen']
- idseen = []
-
- startdate = datetime.datetime(
- year=startdate.year, month=startdate.month, day=startdate.day)
- enddate = datetime.datetime(
- year=enddate.year, month=enddate.month, day=enddate.day)
-
- duration = enddate-startdate
-
- totaldays = duration.total_seconds()/(24*3600)
-
- for w in workouts:
- aantal = 1
- initials = w.user.user.first_name[0:aantal] + \
- w.user.user.last_name[0:aantal]
- if w.user.id not in idseen:
- while initials in seen: # pragma: no cover
- aantal += 1
- initials = w.user.user.first_name[0:aantal] + \
- w.user.user.last_name[0:aantal]
-
- seen.append(initials)
- idseen.append(w.user.id)
- rowersinitials[w.user.id] = initials
-
- for w in workouts:
- dd = w.date.strftime('%m/%d')
- dd2 = w.date.strftime('%Y/%m/%d')
- dd3 = w.date.strftime('%Y/%m')
- du = w.duration.hour*60+w.duration.minute
- rscore = w.rscore
- trimp = w.trimp
-
- if rscore == 0: # pragma: no cover
- rscore = w.hrtss
-
- if totaldays < 30:
- dates.append(dd)
- dates_sorting.append(dd2)
- else: # pragma: no cover
- dates.append(dd3)
- dates_sorting.append(dd3)
- durations.append(du)
- rscores.append(rscore)
- trimps.append(trimp)
- links.append(
- "{siteurl}/rowers/workout/{code}/".format(
- siteurl=settings.SITE_URL,
- code=encoder.encode_hex(w.id)
- )
- )
-
- types.append(w.workouttype)
- try:
- rowers.append(rowersinitials[w.user.id])
- except IndexError: # pragma: no cover
- rowers.append(str(w.user))
-
- try:
- d = utc.localize(startdate)
- except (ValueError, AttributeError): # pragma: no cover
- d = startdate
-
- try:
- enddate = utc.localize(enddate)
- except (ValueError, AttributeError): # pragma: no cover
- pass
-
- # add dates with no activity
- while d <= enddate:
- dd = d.strftime('%d')
-
- if totaldays < 30:
- dates.append(d.strftime('%m/%d'))
- dates_sorting.append(d.strftime('%Y/%m/%d'))
- else: # pragma: no cover
- dates.append(d.strftime('%Y/%m'))
- dates_sorting.append(d.strftime('%Y/%m'))
- durations.append(0)
- rscores.append(0)
- trimps.append(0)
- links.append('')
- try:
- types.append(types[0])
- except IndexError:
- types.append('rower')
-
- try:
- rowers.append(rowers[0])
- except IndexError:
- try:
- rowers.append(str(workouts[0].user))
- except IndexError:
- rowers.append(' ')
-
- d += datetime.timedelta(days=1)
-
- thedict = {
- 'date': dates,
- 'date_sorting': dates_sorting,
- 'duration': durations,
- 'trimp': trimps,
- 'rscore': rscores,
- 'type': types,
- 'rower': rowers,
- 'link': links,
- }
-
- df = pd.DataFrame(thedict)
-
- df.sort_values('date_sorting', inplace=True)
-
- data_dict = df.to_dict("records")
-
-
- hv.extension('bokeh')
-
- if stack == 'type':
- table = hv.Table(df, [('date', 'Date'), ('type', 'Workout Type')],
- [('duration', 'Minutes'), ('rscore', 'rScore'), ('trimp', 'TRIMP'), ('link', 'link')])
-
- else:
- table = hv.Table(df, [('date', 'Date'), ('rower', 'Rower')],
- [('duration', 'Minutes'), ('rscore', 'rScore'), ('trimp', 'TRIMP'), ('link', 'link')])
-
- bars = table.to.bars(['date', stack], [yaxis])
- if stack == 'type':
- bars.opts(
- opts.Bars(cmap=mytypes.color_map, show_legend=True, stacked=True,
- tools=['tap', 'hover'], width=550, xrotation=45, padding=(0, (0, .1)),
- legend_position='bottom', show_frame=True))
- else:
- bars.opts(
- opts.Bars(cmap='Category10', show_legend=True, stacked=True,
- tools=['tap', 'hover'], width=550, xrotation=45, padding=(0, (0, .1)),
- legend_position='bottom', show_frame=True))
-
- p = hv.render(bars)
-
- p.title.text = 'Activity {d1} to {d2}'.format(
- d1=startdate.strftime("%Y-%m-%d"),
- d2=enddate.strftime("%Y-%m-%d"),
- )
-
- p.width = 550
- p.height = 350
- p.toolbar_location = toolbar_location
- p.y_range.start = 0
- #p.sizing_mode = 'stretch_both'
- taptool = p.select(type=TapTool)
-
- callback = CustomJS(args={'links': df.link}, code="""
- var index = cb_data.source.selected['1d'].indices[0];
- console.log(links);
- console.log(index);
- console.log(links[index]);
- window.location.href = links[index]
- """)
-
- taptool.js_on_event('tap', callback)
-
- script, div = components(p)
- return script, div
-
-
-def interactive_activitychart2(workouts, startdate, enddate, stack='type', toolbar_location=None,
+def interactive_activitychart2(workouts, startdate, enddate, stack='type',
yaxis='duration'):
@@ -687,7 +509,7 @@ def interactive_activitychart2(workouts, startdate, enddate, stack='type', toolb
d2=enddate.strftime("%Y-%m-%d"),
),
'datebin': datebin,
- 'colorby': 'type',
+ 'colorby': stack,
'stackby': stacknames[yaxis],
'doreduce': True,
'dosort': True,
diff --git a/rowers/templates/history.html b/rowers/templates/history.html
index 28635bc5..fc89929e 100644
--- a/rowers/templates/history.html
+++ b/rowers/templates/history.html
@@ -5,19 +5,10 @@
{% block title %}Rowsandall {% endblock %}
{% block main %}
-
-
-
-
-
-
-
diff --git a/rowers/templates/list_workouts.html b/rowers/templates/list_workouts.html
index beeafdad..51e40308 100644
--- a/rowers/templates/list_workouts.html
+++ b/rowers/templates/list_workouts.html
@@ -10,7 +10,7 @@
{% endblock %}
@@ -229,22 +229,11 @@
Total meters: {{ totalmeters }}. Total time {{ totalhours }}:{{ totalminutes }}h.
Dig deeper.
-
- Activity chart by
- TRIMP,
- rScore,
- Time.
-
-
-
-
-
-
- {{ interactiveplot |safe }}
+
{{ the_div |safe }}
+ {{ interactiveplot |safe }}
+
{% if announcements %}
diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py
index 79a151f9..d0e77543 100644
--- a/rowers/views/workoutviews.py
+++ b/rowers/views/workoutviews.py
@@ -2221,7 +2221,7 @@ def workouts_view(request, message='', successmessage='',
if yaxis not in ['duration', 'trimp', 'rscore']: # pragma: no cover
yaxis = 'duration'
- script, div = interactive_activitychart(g_workouts,
+ script, div = interactive_activitychart2(g_workouts,
g_startdate,
g_enddate,
stack=stack,