BASE_URL="https://intervals.icu/api/v1/athlete"OLDEST="2024-01-01"NEWEST="2024-12-31"# Fetch activitiesactivities=$(curl -s -u API_KEY:$API_KEY\
"$BASE_URL/$INTERVALS_UID/activities?oldest=$OLDEST&newest=$NEWEST")# CSV headerecho"date,cumulative_distance"# Initialise cumulative distance and iterate through each datecumulative_distance=0
current_date=$(date -I -d "$OLDEST")end_date=$(date -I -d "$NEWEST + 1 day")while [ $current_date != $end_date ]; do# Calculate total distance for the current dayday_distance=$(echo"$activities" | \
jq --arg date "$current_date"'
map(select(.type == "Run" and
(.start_date_local | startswith($date)))) |
map(.distance) |
add // 0')# return day distance (or return 0 if false or null)# Add day distance to cumulative distancecumulative_distance=$(echo"[$cumulative_distance, $day_distance]" | jq 'add')# Date and cumulative distance up until current dateecho"$current_date,$cumulative_distance"# Move to the next daycurrent_date=$(date -I -d "$current_date + 1 day")done
setterminal pngcairo size 1024,768 font "iA Writer Quattro V"setoutput'cumulative_distance_graph.png'# Set data file separator and time-related settingssetdatafile separator ","setxdata time
settimefmt"%Y-%m-%d"setformat x "%B"setylabel"Cumulative Running Distance in 2024"setgrid# Customize axis and rangesetxtics rotate by -45
setyrange [0:1150]
setxrange ['2024-01-01':*]
# Set marginssetlmargin 16
setrmargin 10
settmargin 5
setbmargin 6
# Mark specific races with arrows and labelssetarrow from '2024-06-01',0 to '2024-06-01',1150 nohead lw 1 dashtype 3 linecolor "gray30"# Stockholm marathonsetlabel"🇸🇪" at '2024-06-03',950
setarrow from '2024-09-15',0 to '2024-09-15',1150 nohead lw 1 dashtype 3 linecolor "gray30"# In Flanders Fields marathonsetlabel"🇧🇪" at '2024-09-17',950
# Plot cumulative distance and 1000 km goal with markers and stylesplot"cumulative_distance.csv"using 1:($2/1000) with lines title"Cumulative Distance (km)" lw 2 linecolor rgb "orange-red", \
0 with lines title"Marathons" lw 1 dashtype 3 linecolor "black", \
1000 with lines notitle"1000 km" lw 1 dashtype 2 linecolor "black"