#Get activity (used to get the date)
activity <- GC.activity.metrics()
#Get zone information at this actvity date
zone <- GC.athlete.zones(date=activity$date, sport="bike")
#Get intervals USER if that one is not find get all intervals
intervals <- GC.activity.intervals(type="USER")
type_title <- "USER"
if (is.data.frame(intervals) && nrow(intervals)==0){
type_title <- "ALL"
intervals <- GC.activity.intervals()
}
#Identify for every interval the zone color
breaks <- c(unlist(zone$zoneslow))
interval_colors <- c(unlist(zone$zonescolor))[findInterval(intervals$Average_Power, vec=breaks)]
#Define chart title
title <- paste0("Average Power per Interval (CP:",zone$cp,") Interval Type=", type_title)
#Define margin (when interval names are not printed propably the names are to long change bottom value(first parameter))
par(mar=c(10,5,5,0))
barplot <- barplot(intervals$Average_Power, axes = FALSE, axisnames = FALSE, col=interval_colors, width=intervals$Duration,
main=title,
ylim=c(0,max(intervals$Average_Power)*1.1)
)
#Add horizontal line at 0
abline(h=0)
#Add interval names at X-as
text(barplot,
mean(intervals$Average_Power)*-0.05,
labels = intervals$name,
srt = 90,
xpd = TRUE,
adj=0,
)
#Add percentage labels
avg_power_pct <- round((intervals$Average_Power / zone$cp)*100,1)
avg_power_pct_label<- paste(avg_power_pct, "%")
text(barplot,
intervals$Average_Power+10,
labels = avg_power_pct_label,
)
axis(2)
#Add legend
zone_names = c("Z1", "Z2", "Z3", "Z4", "Z5", "Z6", "Z7")
legend <- paste(zone_names, "(" , breaks, ")")
legend("topleft",
inset=0.02,
legend=legend,
fill=c(unlist(zone$zonescolor)),
)
import bisect
import plotly
import plotly.graph_objs as go
import numpy as np
#Get activity (used to get the date)
activity = GC.activityMetrics()
#Get zone information at this actvity date
zone = GC.athleteZones(date=activity["date"], sport="bike")
#Get intervals USER if that one is not find get all intervals
intervals = GC.activityIntervals(type="USER")
type_title = "USER"
if not intervals["name"]:
type_title = "ALL"
intervals = GC.activityIntervals()
#Identify for every interval the zone color
breaks = zone["zoneslow"][0]
zone_colors = zone["zonescolor"][0]
interval_color_list = []
avg_power_pct =[]
for interval in intervals["Average_Power"]:
id = bisect.bisect_left(breaks, interval)
interval_color_list.append(zone_colors[id-1])
avg_power_pct.append(str(round((interval / zone["cp"][0])*100,1))+"%")
#Define chart title
title = "Average Power per Interval (CP:" + str(zone["cp"]) + ") Interval Type=" + str(type_title)
#Add percentage labels
zone_names = ["Z1", "Z2", "Z3", "Z4", "Z5", "Z6", "Z7"]
legend = []
zone_index=1
for zone in breaks:
legend.append("Z" + str(zone_index) + "(" + str(zone) + ")")
zone_index += 1
xx = np.asarray(intervals["name"])
yy = np.asarray(intervals["Average_Power"])
ff = np.arange(1,len(xx))
#print(ff)
#print(xx)
#print(yy)
data = []
print(duration)
data.append(go.Bar(
x=xx,
y=yy,
name="avg power",
# width=intervals["Duration"],
text=avg_power_pct,
textposition = 'auto',
showlegend=False,
marker=dict(
color=interval_color_list),
))
#workaround to add legend.
for i in range(len(breaks)):
data.append(
go.Scatter(x=[None], y=[None],
mode='markers',
marker=dict(size=10, color=zone_colors[i]),
legendgroup=str(legend[i]),
showlegend=True,
name=zone_names[i])
)
layout = go.Layout(
title=go.layout.Title(
text=title,
xref='paper',
x=0
),
)
fig = go.Figure(data=data, layout=layout)
barplot = plotly.offline.plot(fig, auto_open = False, filename="D:/temp.html")
## Load Plot
GC.webpage(barplot)
yy = np.asarray(intervals<span style="color: #660;" class="styled-by-pre

import bisect
import plotly
import plotly.graph_objs as go
import numpy as np
#Get activity (used to get the date)
activity = GC.activityMetrics()
#Get zone information at this actvity date
zone = GC.athleteZones(date=activity["date"], sport="bike")
#Get intervals USER if that one is not find get all intervals
intervals = GC.activityIntervals(type="USER")
type_title = "USER"
if not intervals["name"]:
type_title = "ALL"
intervals = GC.activityIntervals()
#Identify for every interval the zone color
breaks = zone["zoneslow"][0]
zone_colors = zone["zonescolor"][0]
interval_colors = []
avg_power_pct =[]
for interval in intervals["Average_Power"]:
id = bisect.bisect_left(breaks, interval)
interval_colors.append(zone_colors[id-1])
avg_power_pct.append(str(round((interval / zone["cp"][0])*100,1))+"%")
#Define chart title
title = "Average Power per Interval (CP:" + str(zone["cp"]) + ") Interval Type=" + str(type_title)
#Add percentage labels
zone_names = ["Z1", "Z2", "Z3", "Z4", "Z5", "Z6", "Z7"]
legend = []
zone_index=1
for zone in breaks:
legend.append("Z" + str(zone_index) + "(" + str(zone) + ")")
zone_index += 1
lap_names = np.asarray(intervals["name"])
watts_y = np.asarray(intervals["Average_Power"])
x = np.asarray(intervals["start"])
duration = np.asarray(intervals["Duration"])
trace0 = go.Scatter(
x=x,
y=watts_y,
mode='text',
showlegend=False,
)
data = [trace0]
for i in np.arange(0,len(legend)):
data.append(go.Scatter(
x=[None],
y=[None],
mode='markers',
marker=dict(size=10, color=zone_colors[i]),
legendgroup=legend[i],
showlegend=True,
name=legend[i])
)
# Create rectangles per interval
shapes = []
annotations = []
for i in np.arange(0,len(lap_names)):
shapes.append(
{
'type': 'rect',
'x0': x[i],
'y0': 0,
'x1': x[i]+duration[i],
'y1': watts_y[i],
'fillcolor': interval_colors[i],
})
annotations.append(
dict(
x=x[i] + (duration[i]/2),
y=watts_y[i],
xref='x',
yref='y',
text=str(lap_names[i]) + "<br>" + str(avg_power_pct[i]) + "<br>" + str(duration[i]) + "s",
showarrow=True,
arrowhead=7,
ax=0,
ay=-40
))
layout = go.Layout(
title = title,
xaxis = dict(
range=[0, max(x)],
showgrid=True,
autorange=True,
zeroline=False,
showline=False,
ticks='',
showticklabels=False
),
yaxis = dict(
range=[0, max(watts_y)]
),
margin=go.layout.Margin(
l=50,
r=50,
b=100,
t=150,
pad=4
),
shapes=shapes,
annotations=annotations,
)
fig = go.Figure(data=data, layout=layout)
plot = plotly.offline.plot(fig, auto_open=False, filename='D:/temp_chart.html')
## Load Plot
GC.webpage(plot)