mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-14 08:38:45 +00:00
All activity functions working with data series, both standard and xdata, now include an optional compareindex=-1 parameter. When compare mode is enabled compareindex parameter is used as an index to get data for the corresponding compare item, be an activity or an interval. Sample chart contributed by Marcen at the users forum Fixes #4346
20 lines
2.8 KiB
Plaintext
20 lines
2.8 KiB
Plaintext
{
|
|
"CHART":{
|
|
"VERSION":"1",
|
|
"VIEW":"analysis",
|
|
"TYPE":"43",
|
|
"PROPERTIES":{
|
|
"title":"Watt over Duration ",
|
|
"subtitle":" ",
|
|
"widthFactor":"2",
|
|
"heightFactor":"2",
|
|
"style":"0",
|
|
"resizable":"0",
|
|
"script":"##\n## Python program will run on selection.\n##\n## \nimport plotly.graph_objects as go\nimport pandas as pd\nimport tempfile\nimport pathlib\nimport plotly\nimport time\nimport datetime\n\n# Define tempory file\ntemp_file = tempfile.NamedTemporaryFile(mode=\"w+t\", prefix=\"GC_\", suffix=\".html\", delete=False)\n\n## Create dataframe\ndf = pd.DataFrame()\n\n## Get GC Data for activity and metrics\nmetricsAll = GC.activityMetrics(compare=True)\n\ntime = []\nfor i in range(0, len(metricsAll)):\n time.append(str(datetime.timedelta(seconds=int(metricsAll[i][0]['Duration']))))\n df.at[i, 'dateLocal'] = metricsAll[i][0]['date'].strftime('%a %x')\n df.at[i, 'colors'] = metricsAll[i][1]\n\ndf['time'] = time\n\nduration = []\npower = []\nisPower = []\nfor i in range(0, len(metricsAll)):\n activityAll = GC.activity(compareindex =i)\n sec = list(activityAll['seconds'])\n\n durationTemp = []\n for seconds in sec:\n minutes, seconds = divmod(seconds, 60)\n hours, minutes = divmod(minutes, 60)\n durationTemp.append(\"%02i:%02i:%02i\" % (hours, minutes, seconds))\n\n if 'power' in activityAll:\n power.append(list(activityAll['power']))\n isPower.append(1)\n\n else:\n power.append(list([0]))\n isPower.append(0)\n\n duration.append(durationTemp)\n\n## Add Data to the dataframe\ndf['duration'] = duration\ndf['power'] = power\ndf['isPower'] = isPower\n\n## Filter out data without power\ndfFilter = df.loc[df['isPower'] > 0]\n\n## Plot Data\nfig = go.Figure()\n\nfor i in dfFilter.index:\n fig.add_trace(go.Scatter(\n x = dfFilter['duration'][i],\n y = dfFilter['power'][i],\n mode = 'lines',\n name = str(dfFilter['dateLocal'][i]) +\n \"<br>\" 'Duration: ' +\n str(dfFilter['time'][i]),\n\n marker_color = dfFilter['colors'][i],\n hovertemplate =\n '<b>Power<\/b>: %{y} watts' +\n '<br><b>Duration<\/b>: %{x}',\n ))\n\nfig.update_xaxes(\n tickmode = 'auto',\n nticks = 10,\n ticks = \"outside\",\n tickwidth = 2,\n ticklen = 10,\n tickcolor = 'white',\n linewidth = 2,\n linecolor = 'white',\n)\n\n## Update layout properties\nfig.update_layout(\n xaxis_title=\"Duration\",\n yaxis_title=\"Watts\",\n template='plotly_dark',\n xaxis_showgrid=False,\n yaxis_showgrid=True,\n #hovermode=\"x unified\",\n)\n\n## Prepare Plot\nplotly.offline.plot(fig, auto_open=False, filename=temp_file.name)\n\n## Load the webpage\nGC.webpage(pathlib.Path(temp_file.name).as_uri())\n ",
|
|
"state":" ",
|
|
"showConsole":"0",
|
|
"asWeb":"1",
|
|
"__LAST__":"1"
|
|
}
|
|
}
|
|
} |