Skip to content

Commit

Permalink
Merge pull request #36 from sidetrackedmind/try-pyodide-version
Browse files Browse the repository at this point in the history
Merge beta game
  • Loading branch information
sidetrackedmind authored Jan 27, 2025
2 parents 83b85b0 + 3ee8c4a commit 556468b
Show file tree
Hide file tree
Showing 7 changed files with 565 additions and 78 deletions.
39 changes: 39 additions & 0 deletions decodePolyine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function decodePolyline(encoded) {
const len = encoded.length;
let index = 0;
let lat = 0;
let lng = 0;
const decoded = [];

while (index < len) {
let b;
let shift = 0;
let result = 0;

do {
b = encoded.charCodeAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);

const dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
lat += dlat;

shift = 0;
result = 0;

do {
b = encoded.charCodeAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);

const dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
lng += dlng;

decoded.push([lat / 1e5, lng / 1e5]);
}

return decoded;
}

26 changes: 26 additions & 0 deletions getnearbyroutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Description: This file contains the function to get nearby routes from the Trimet API.

function getNearbyRoutes(fromPlace) {
// fromPlace is a string with the format "lat,lon"
const baseUrl = "https://developer.trimet.org/ws/v1/stops";

const params = new URLSearchParams({
json: true,
appId: "8CBD14D520C6026CC7EEE56A9",
showRoutes: true,
meters: 1200,
ll: fromPlace
});
const routeNumbers = new Set();
var xhReq = new XMLHttpRequest();
xhReq.open("GET", `${baseUrl}?${params}`, false);
xhReq.send(null);
var raw_response = JSON.parse(xhReq.responseText);
raw_response.resultSet.location.forEach(loc => {
loc.route.forEach(route => {
routeNumbers.add(route.route);
// console.log(route.route);
});
});
return routeNumbers;
}
37 changes: 37 additions & 0 deletions gettrimettripplan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Description: This script is used to get the trip plan from Trimet API.

function getTrimetPlan(fromPlace, toPlace, maxWalkDistance = 1200, walkSpeed = 1.7, numItineraries = 1) {
const baseUrl = "https://maps.trimet.org/otp_mod/plan";

// 805 meters = 1/2 mile. 1.7 m/s

const now = new Date();

const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed
const day = String(now.getDate()).padStart(2, '0');

const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');

const date = `${year}-${month}-${day}`;
const time = `${hours}:${minutes}`;

const params = new URLSearchParams({
fromPlace,
toPlace,
date,
time,
mode: "WALK,BUS,TRAM,RAIL,GONDOLA",
maxWalkDistance,
walkSpeed,
numItineraries,
});

var xhReq = new XMLHttpRequest();
xhReq.open("GET", `${baseUrl}?${params}`, false);
xhReq.send(null);
var raw_response = JSON.parse(xhReq.responseText);
return raw_response;

}
Loading

0 comments on commit 556468b

Please sign in to comment.