Last active
June 13, 2023 22:44
-
-
Save greenido/66255c181d79b0c99729a17737d5d705 to your computer and use it in GitHub Desktop.
Find the best Eversting Segments Around The Bay Area (or any other location in the world) π
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get from Strava segments in an area to check for the optimal one for eversting challange π | |
* | |
* @author @greenido | |
* @update May 2020 | |
* | |
* @see | |
* π API: https://www.strava.com/settings/api | |
* | |
* π¦ Get long/lat on map: https://www.latlong.net/ or just google maps | |
* | |
* ππ½ Strava segment view: https://www.strava.com/segments/838277 | |
* | |
* ππΌββοΈ The challange calculator and rules: | |
* https://everesting.cc/ | |
* https://everesting.cc/the-rules/ | |
* | |
*/ | |
const fs = require('fs'); | |
const strava = require('strava-v3'); | |
/** | |
* An Area near Palo Alto / Mountain View: 37.227467, -122.252343 , 37.392468, -122.147393 | |
* | |
* Sunborn: '37.223952, -122.082204 , 37.247273, -122.050983 | |
* Castel Rock: 37.210512, -122.155736 , 37.260993, -122.088351 | |
* Fremont Older: 37.274807, -122.082686 , 37.305592, -122.046764 | |
* Windy Hill: 37.342399, -122.248591 , 37.375964, -122.210654 | |
* Huddart Park: 37.426549, -122.313672 , 37.456754, -122.282049 | |
* El Corte de Madera Creek: 37.380227, -122.335745 , 37.419812, -122.294035 | |
* MtDiablo: 37.827981, -122.003592 , 37.924660, -121.866957 | |
* Joaquin Miller Park: 37.796745, -122.203074 , 37.838225, -122.140281 | |
* Golden Gate Park: 37.818253, -122.571099 , 37.898337, -122.478872 | |
* MtTam: 37.868871, -122.637926 , 37.947287, -122.564110 | |
*/ | |
const areasObj = { | |
// "Sunborn": [37.223952, -122.082204 , 37.247273, -122.050983] , | |
// "CastelRock": [37.210512, -122.155736 , 37.260993, -122.088351] , | |
// "FremontOlder": [37.274807, -122.082686 , 37.305592, -122.046764] , | |
// "WindyHill": [37.342399, -122.248591 , 37.375964, -122.210654] , | |
// "HuddartPark": [37.426549, -122.313672 , 37.456754, -122.282049] , | |
// "ElCortedeMaderaCreek": [37.380227, -122.335745 , 37.419812, -122.294035] , | |
// "MtDiablo": [37.827981, -122.003592 , 37.924660, -121.866957] , | |
// "JoaquinMillerPark": [37.796745, -122.203074 , 37.838225, -122.140281] , | |
// "GoldenGatePark": [37.818253, -122.571099 , 37.898337, -122.478872] , | |
// "MtTam": [37.868871, -122.637926 , 37.947287, -122.564110] | |
"Old La Honda Area": [37.369504, -122.261283 , 37.398757, -122.237941] | |
} | |
const areasArray = Object.entries(areasObj); | |
// | |
// | |
// | |
async function fetchSegments(strava, parkName, geoPoint, csvStr) { | |
strava.segments.explore({ | |
access_token: "TODO-PUT-YOUR-TOKEN", | |
bounds: geoPoint, | |
activity_type: 'riding' // running | |
}, function (err, payload) { | |
if (!err) { | |
const areaName = parkName; | |
console.log('=================== π₯ ======================'); | |
for (let i = 0; i < payload.segments.length; i++) { | |
const segment = payload.segments[i]; | |
let segmentName = segment.name.replace(","," "); | |
let tmpStr = segment.id + " , " + segmentName + " , " + segment.climb_category + " , " + segment.distance + " , " + | |
segment.elev_difference + " , " + (segment.elev_difference / segment.distance * 100).toFixed(3) + "% , " + areaName + " \n"; | |
csvStr += tmpStr; | |
} | |
console.log(csvStr); | |
fs.writeFileSync("./data/" + areaName + ".csv", csvStr); | |
} else { | |
console.log("ERR: " + err); | |
//console.log(err) | |
process.exit(1); | |
} | |
}); | |
} | |
let csvStr = "id , name , climb_category , distance , elevation difference , RATIO , Area \n"; | |
for (const [parkName, geoPoint] of areasArray) { | |
console.log(`π Working on ${parkName}: ${geoPoint} `); | |
fetchSegments(strava, parkName, geoPoint.toString(), csvStr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment