jq
: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=0current_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 day day_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 distance cumulative_distance=$(echo "[$cumulative_distance, $day_distance]" | jq 'add') # Date and cumulative distance up until current date echo "$current_date,$cumulative_distance" # Move to the next day current_date=$(date -I -d "$current_date + 1 day")done
date,cumulative_distance2024-01-01,02024-01-02,69192024-01-03,69192024-01-04,100342024-01-05,10034...2024-12-27,958647.542024-12-28,973656.542024-12-29,973656.542024-12-30,980075.542024-12-31,1000088.54
set terminal pngcairo size 1024,768 font "iA Writer Quattro V"set output 'cumulative_distance_graph.png' # Set data file separator and time-related settingsset datafile separator ","set xdata timeset timefmt "%Y-%m-%d"set format x "%B"set ylabel "Cumulative Running Distance in 2024"set grid # Customize axis and rangeset xtics rotate by -45set yrange [0:1150]set xrange ['2024-01-01':*] # Set marginsset lmargin 16set rmargin 10set tmargin 5set bmargin 6 # Mark specific races with arrows and labelsset arrow from '2024-06-01',0 to '2024-06-01',1150 nohead lw 1 dashtype 3 linecolor "gray30" # Stockholm marathonset label "🇸🇪" at '2024-06-03',950 set arrow from '2024-09-15',0 to '2024-09-15',1150 nohead lw 1 dashtype 3 linecolor "gray30" # In Flanders Fields marathonset label "🇧🇪" 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"