Skip to content

Instantly share code, notes, and snippets.

@adielfernandez
Last active April 1, 2023 14:18
Show Gist options
  • Save adielfernandez/6e50250e10cfddeb76a5cc91e8b54e5c to your computer and use it in GitHub Desktop.
Save adielfernandez/6e50250e10cfddeb76a5cc91e8b54e5c to your computer and use it in GitHub Desktop.
Pulls valid activities and compiles mileage with multiplier for the Fun Group™
var url,maxPage=100,activityType="",p=1,done=0,entry=0,startTimeStamp=1673586e3,endTimeStamp=1680321601,totalDist=0,totalSkate=0,totalRide=0,totalRun=0,totalSkateElev=0,totalRideElev=0,totalRunElev=0,totalSkateTime=0,totalRideTime=0,totalRunTime=0,totalDistWithMult=0,totalElevation=0,totalTime=0;function formatNum(t){return t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}function secToHrs(t){return(t/3600).toFixed(2)}for(;p<=maxPage;)url="https://www.strava.com/athlete/training_activities?keywords=&activity_type="+activityType+"&workout_type=&commute=&private_activities=&trainer=&gear=&new_activity_only=false&page="+p+"&per_page=20",jQuery.ajax({url:url,dataType:"json",method:"GET",success:function(t,e,a){for(i in t.models){var l=t.models[i].start_date_local_raw>startTimeStamp&&t.models[i].start_date_local_raw<endTimeStamp,o=t.models[i].type,n="VirtualRide"==o||"Ride"==o||"Hike"==o||"IceSkate"==o||"InlineSkate"==o||"Run"==o||"Snowboard"==o||"AlpineSki"==o;if(l&&n){var m=parseFloat(t.models[i].distance),r=parseFloat(t.models[i].elapsed_time_raw),s=parseFloat(t.models[i].elevation_gain.replace(",",""));totalDist+=m;var u=1;"InlineSkate"==o&&(u=2.5,totalSkate+=m,totalSkateElev+=s,totalSkateTime+=r),"Run"==o&&(u=1.5,totalRun+=m,totalRunElev+=s,totalRunTime+=r),("VirtualRide"==o||"Ride"==o)&&(totalRide+=m,totalRideElev+=s,totalRideTime+=r),totalDistWithMult+=m*u,totalTime+=r,totalElevation+=s,entry++}}if(++done>=maxPage){var T=totalDist-(totalSkate+totalRide+totalRun),d=totalElevation-(totalSkateElev+totalRideElev+totalRunElev),v=totalTime-(totalSkateTime+totalRideTime+totalRunTime);console.log("\n------------------------------------------------\nFound "+entry+" valid entries for challenge!\n------------------------------------------------\n\n- SKATE\n -Mileage: "+formatNum(totalSkate)+" mi \n -Elevation gain: "+formatNum(totalSkateElev)+" ft \n -Time spent: "+secToHrs(totalSkateTime)+" hrs\n- BIKE\n -Mileage: "+formatNum(totalRide)+" mi \n -Elevation gain: "+formatNum(totalRideElev)+" ft \n -Time spent: "+secToHrs(totalRideTime)+" hrs\n- RUNNING\n -Mileage: "+formatNum(totalRun)+" mi \n -Elevation gain: "+formatNum(totalRunElev)+" ft \n -Time spent: "+secToHrs(totalRunTime)+" hrs\n- OTHER\n -Mileage: "+formatNum(T)+" mi \n -Elevation gain: "+formatNum(d)+" ft \n -Time spent: "+secToHrs(v)+" hrs\n\nTotal Mileage: "+formatNum(totalDist)+" mi\nTotal Elevation Gain: "+formatNum(totalElevation)+" ft\nTotal Time Spent: "+secToHrs(totalTime)+" hours\n\n------------------------------------------------\nMILEAGE WITH MULTIPLIERS: "+formatNum(totalDistWithMult)+" miles!\n------------------------------------------------")}}}),p++;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment