Skip to content

Instantly share code, notes, and snippets.

View squeezer44's full-sized avatar
🎯
Focusing

Christian Matthees squeezer44

🎯
Focusing
View GitHub Profile
# -------------
# Imports
from stravalib.client import Client
import pprint
# -------------
# Get a certain activity
client = Client(access_token='I-AM-THE-TOKEN')
activity = client.get_activity(1234567890)
# -------------
# Imports
import pandas as pd
pd.set_option("display.max_columns", 100)
import pprint
from stravalib.client import Client
# -------------
## with plotly.express
fig_2 = px.line(gpx_df, x='time', y=['speed_kilometers_per_hour',
'distance_total_geodesic_kilometers',
'altitude'],
template='plotly_dark')
fig_2.show()
# ----------------------------
# Get the results
# key points of the session
print('SessionStart: ' + str(gpx_df.iloc[0,0]))
print('SessionStop: ' + str(gpx_df.iloc[-1,0]))
print('SessionDuration (hh:mm:ss): ' + str(gpx_df['time'].max() - gpx_df['time'].min()))
print('SessionDistanceTotal: ' + str(round((gpx_df['distance_delta_geodesic_meters'].sum()
/1000), 3)) + ' km')
print('SessionWayUp: ' + str(altitude_total_up) + ' m')
# ----------------------------
# Calculate sums
# calculate Total altitude_total_up, altitude_total_down
altitude_total_up = 0
altitude_total_down = 0
for i in gpx_df['altitude_delta_meters']:
if i > 0.0:
altitude_total_up += i
print(gpx_df.info())
# ----------------------------
# Calculate delta
# time_delta
## calculate and add column time_delta
gpx_df['time_delta'] = gpx_df['time'].shift(-1)-gpx_df['time']
## translate the time_delta in seconds
gpx_df['time_delta_seconds'] = ((gpx_df['time_delta'].
fillna(pd.Timedelta(seconds=0)).
view('int64')/1000000000))
print(gpx_df.head(5))
print(gpx_df.info())