Created
February 3, 2018 08:55
-
-
Save sisao/afa3fd561213f93e0a6e9cbb424a3fce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import plotly | |
import math | |
from plotly.graph_objs import Layout, Bar | |
activity = GC.activity() | |
metrics = GC.activityMetrics() | |
date = metrics.get("date") | |
zone = GC.athleteZones(date=date, sport="bike") | |
lows = zone.get("zoneslow") | |
colors = zone.get("zonescolor") | |
duration = activity.get("seconds")[-1] | |
p = list(activity.get("power")) | |
n = 50 | |
step = math.ceil(len(p)/math.ceil(len(p)/n)) | |
chunks = [p[x:x+step] for x in range(0, len(p), step)] | |
p2 = list(map(lambda x: sum(x) / len(x), chunks)) | |
ff = np.searchsorted(lows[0], p2, side='right') | |
cc = list(map(lambda x: colors[0][x-1], ff)) | |
time = list(range(len(p2))) | |
f = plotly.offline.plot({ | |
"data": [Bar(x=time, y=p2, marker=dict( | |
color=cc | |
),)], | |
"layout": Layout(title="Power in zones over time") | |
}, auto_open = False) | |
# f[7:] used as workaround for defect Windows uri | |
GC.webpage(f[7:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment