Private
Public Access
1
0

removed activity_chart

This commit is contained in:
2024-03-29 08:57:39 +01:00
parent 26ad051cf5
commit 7ab56936da
4 changed files with 7 additions and 205 deletions

View File

@@ -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,

View File

@@ -5,19 +5,10 @@
{% block title %}Rowsandall {% endblock %}
{% block main %}
<div id="id_css_res">
<link rel="stylesheet" href="https://cdn.pydata.org/bokeh/release/bokeh-3.1.1.min.css" type="text/css" />
<link rel="stylesheet" href="https://cdn.pydata.org/bokeh/release/bokeh-widgets-3.1.1.min.css" type="text/css" />
</div>
<div id="id_js_res">
<script src="https://cdn.pydata.org/bokeh/release/bokeh-3.1.1.min.js"></script>
<script src="https://cdn.pydata.org/bokeh/release/bokeh-widgets-3.1.1.min.js"></script>
<script src="https://d3js.org/d3.v7.min.js"></script>
</div>
<script async="true" type="text/javascript">
Bokeh.set_log_level("info");
</script>
<div id="id_script">
</div>

View File

@@ -10,7 +10,7 @@
</script>
<script
type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
</script>
{% endblock %}
@@ -229,22 +229,11 @@
Total meters: {{ totalmeters }}. Total time {{ totalhours }}:{{ totalminutes }}h.
<a href="/rowers/history/">Dig deeper</a>.
</p>
<p>
Activity chart by
<a href="{{ request.get_path }}?yaxis=trimp">TRIMP</a>,
<a href="{{ request.get_path }}?yaxis=rscore">rScore</a>,
<a href="{{ request.get_path }}?yaxis=duration">Time</a>.
</p>
<link rel="stylesheet" href="https://cdn.pydata.org/bokeh/release/bokeh-3.1.1.min.css" type="text/css" />
<link rel="stylesheet" href="https://cdn.pydata.org/bokeh/release/bokeh-widgets-3.1.1.min.css" type="text/css" />
<script src="https://cdn.pydata.org/bokeh/release/bokeh-3.1.1.min.js"></script>
<script async="true" type="text/text/javascript">
Bokeh.set_log_level("info")
</script>
{{ interactiveplot |safe }}
<script src="https://d3js.org/d3.v7.min.js"></script>
{{ the_div |safe }}
{{ interactiveplot |safe }}
</li>
{% if announcements %}
<li class="grid_4">

View File

@@ -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,