backend improvements
This commit is contained in:
5 files changed
+30
-17
No files matched your search
+1
-1
@@ -1 +1 @@
|
|||||||
{"stations":{"place-wondl":{"stop_id":"place-wondl","stop_code":"","stop_name":"Wonderland","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.413420","stop_lon":"-70.991648","zone_id":"","stop_address":"1300 North Shore Rd, Revere, MA 02151","stop_url":"https://www.mbta.com/stops/place-wondl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Revere","on_street":"","at_street":"","vehicle_type":""},"place-rbmnl":{"stop_id":"place-rbmnl","stop_code":"","stop_name":"Revere Beach","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.407843","stop_lon":"-70.992533","zone_id":"","stop_address":"220 Shirley Ave, Revere, MA","stop_url":"https://www.mbta.com/stops/place-rbmnl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Revere","on_street":"","at_street":"","vehicle_type":""},"place-bmmnl":{"stop_id":"place-bmmnl","stop_code":"","stop_name":"Beachmont","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.397542","stop_lon":"-70.992319","zone_id":"","stop_address":"630 Winthrop Ave, Revere, MA 02151","stop_url":"https://www.mbta.com/stops/place-bmmnl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Revere","on_street":"","at_street":"","vehicle_type":""},"place-sdmnl":{"stop_id":"place-sdmnl","stop_code":"","stop_name":"Suffolk Downs","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.390501","stop_lon":"-70.997123","zone_id":"","stop_address":"1230 Bennington St, East Boston, MA 02128","stop_url":"https://www.mbta.com/stops/place-sdmnl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":""},"place-orhte":{"stop_id":"place-orhte","stop_code":"","stop_name":"Orient Heights","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.386867","stop_lon":"-71.004736","zone_id":"","stop_address":"1000 Bennington St, East Boston, MA 02128","stop_url":"https://www.mbta.com/stops/place-orhte","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":""},"place-wimnl":{"stop_id":"place-wimnl","stop_code":"","stop_name":"Wood Island","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.379640","stop_lon":"-71.022865","zone_id":"","stop_address":"450 Bennington St, East Boston, MA","stop_url":"https://www.mbta.com/stops/place-wimnl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":""},"place-aport":{"stop_id":"place-aport","stop_code":"","stop_name":"Airport","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.374262","stop_lon":"-71.030395","zone_id":"","stop_address":"Transportation Way and Service Rd, Boston, MA 02128","stop_url":"https://www.mbta.com/stops/place-aport","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":""},"place-mvbcl":{"stop_id":"place-mvbcl","stop_code":"","stop_name":"Maverick","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.369119","stop_lon":"-71.039530","zone_id":"","stop_address":"Sumner St and Maverick Sq, East Boston, MA","stop_url":"https://www.mbta.com/stops/place-mvbcl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":""},"place-aqucl":{"stop_id":"place-aqucl","stop_code":"","stop_name":"Aquarium","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.359784","stop_lon":"-71.051652","zone_id":"","stop_address":"Atlantic Ave and State St, Boston, MA 02120","stop_url":"https://www.mbta.com/stops/place-aqucl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":""},"place-state":{"stop_id":"place-state","stop_code":"","stop_name":"State","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.358978","stop_lon":"-71.057598","zone_id":"","stop_address":"200 Washington St, Boston, MA","stop_url":"https://www.mbta.com/stops/place-state","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":""},"place-gover":{"stop_id":"place-gover","stop_code":"","stop_name":"Government Center","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.359705","stop_lon":"-71.059215","zone_id":"","stop_address":"Cambridge St and Court St, Boston, MA","stop_url":"https://www.mbta.com/stops/place-gover","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":""},"Line truncated
|
{"stations":{"place-wondl":{"stop_id":"place-wondl","stop_code":"","stop_name":"Wonderland","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.413420","stop_lon":"-70.991648","zone_id":"","stop_address":"1300 North Shore Rd, Revere, MA 02151","stop_url":"https://www.mbta.com/stops/place-wondl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Revere","on_street":"","at_street":"","vehicle_type":"","routes":["Blue"]},"place-rbmnl":{"stop_id":"place-rbmnl","stop_code":"","stop_name":"Revere Beach","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.407843","stop_lon":"-70.992533","zone_id":"","stop_address":"220 Shirley Ave, Revere, MA","stop_url":"https://www.mbta.com/stops/place-rbmnl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Revere","on_street":"","at_street":"","vehicle_type":"","routes":["Blue"]},"place-bmmnl":{"stop_id":"place-bmmnl","stop_code":"","stop_name":"Beachmont","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.397542","stop_lon":"-70.992319","zone_id":"","stop_address":"630 Winthrop Ave, Revere, MA 02151","stop_url":"https://www.mbta.com/stops/place-bmmnl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Revere","on_street":"","at_street":"","vehicle_type":"","routes":["Blue"]},"place-sdmnl":{"stop_id":"place-sdmnl","stop_code":"","stop_name":"Suffolk Downs","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.390501","stop_lon":"-70.997123","zone_id":"","stop_address":"1230 Bennington St, East Boston, MA 02128","stop_url":"https://www.mbta.com/stops/place-sdmnl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":"","routes":["Blue"]},"place-orhte":{"stop_id":"place-orhte","stop_code":"","stop_name":"Orient Heights","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.386867","stop_lon":"-71.004736","zone_id":"","stop_address":"1000 Bennington St, East Boston, MA 02128","stop_url":"https://www.mbta.com/stops/place-orhte","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":"","routes":["Blue"]},"place-wimnl":{"stop_id":"place-wimnl","stop_code":"","stop_name":"Wood Island","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.379640","stop_lon":"-71.022865","zone_id":"","stop_address":"450 Bennington St, East Boston, MA","stop_url":"https://www.mbta.com/stops/place-wimnl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":"","routes":["Blue"]},"place-aport":{"stop_id":"place-aport","stop_code":"","stop_name":"Airport","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.374262","stop_lon":"-71.030395","zone_id":"","stop_address":"Transportation Way and Service Rd, Boston, MA 02128","stop_url":"https://www.mbta.com/stops/place-aport","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":"","routes":["Blue"]},"place-mvbcl":{"stop_id":"place-mvbcl","stop_code":"","stop_name":"Maverick","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.369119","stop_lon":"-71.039530","zone_id":"","stop_address":"Sumner St and Maverick Sq, East Boston, MA","stop_url":"https://www.mbta.com/stops/place-mvbcl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":"","routes":["Blue"]},"place-aqucl":{"stop_id":"place-aqucl","stop_code":"","stop_name":"Aquarium","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.359784","stop_lon":"-71.051652","zone_id":"","stop_address":"Atlantic Ave and State St, Boston, MA 02120","stop_url":"https://www.mbta.com/stops/place-aqucl","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":"","routes":["Blue"]},"place-state":{"stop_id":"place-state","stop_code":"","stop_name":"State","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.358978","stop_lon":"-71.057598","zone_id":"","stop_address":"200 Washington St, Boston, MA","stop_url":"https://www.mbta.com/stops/place-state","level_id":"","location_type":"1","parent_station":"","wheelchair_boarding":"1","municipality":"Boston","on_street":"","at_street":"","vehicle_type":"","routes":["Blue","Orange"]},"place-gover":{"stop_id":"place-gover","stop_code":"","stop_name":"Government Center","stop_desc":"","platform_code":"","platform_name":"","stop_lat":"42.359705","stop_lon":"-71.059215","zone_id":"","stop_address":"Cambridge St and Court St, Boston, MA","stop_url":"httpsLine truncated
|
||||||
@@ -132,6 +132,16 @@ for (let i = 0; i < stop_times.length - 1; i++) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function routesForStation(station_id) {
|
||||||
|
return [
|
||||||
|
...new Set(
|
||||||
|
Object.values(edges)
|
||||||
|
.filter((e) => e.a == station_id || e.b == station_id)
|
||||||
|
.flatMap((e) => [...e.route])
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
const stations = [
|
const stations = [
|
||||||
...new Set(
|
...new Set(
|
||||||
Object.values(edges)
|
Object.values(edges)
|
||||||
@@ -141,7 +151,7 @@ const stations = [
|
|||||||
];
|
];
|
||||||
const output = {
|
const output = {
|
||||||
stations: indexRecords(
|
stations: indexRecords(
|
||||||
stations.map((s) => indexedStops[s]),
|
stations.map((s) => ({ ...indexedStops[s], routes: routesForStation(s) })),
|
||||||
"stop_id"
|
"stop_id"
|
||||||
),
|
),
|
||||||
edges: Object.values(edges).map((e) => ({ ...e, route: [...e.route] })),
|
edges: Object.values(edges).map((e) => ({ ...e, route: [...e.route] })),
|
||||||
@@ -153,3 +163,5 @@ const output = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await Deno.writeTextFile("cities/boston.json", JSON.stringify(output));
|
await Deno.writeTextFile("cities/boston.json", JSON.stringify(output));
|
||||||
|
|
||||||
|
console.log("done");
|
||||||
+12
-11
@@ -4,22 +4,23 @@ const agency = {
|
|||||||
..._agency,
|
..._agency,
|
||||||
// Convert `route` arrays to `Set`s
|
// Convert `route` arrays to `Set`s
|
||||||
edges: _agency.edges.map((e) => ({ ...e, route: new Set(e.route) })),
|
edges: _agency.edges.map((e) => ({ ...e, route: new Set(e.route) })),
|
||||||
|
stations: Object.fromEntries(
|
||||||
|
Object.entries(_agency.stations).map(([k, s]) => [
|
||||||
|
k,
|
||||||
|
{
|
||||||
|
...s,
|
||||||
|
routes: new Set(s.routes),
|
||||||
|
},
|
||||||
|
])
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
export function linesForStation(station_id) {
|
|
||||||
return new Set(
|
|
||||||
agency.edges
|
|
||||||
.filter((e) => e.a == station_id || e.b == station_id)
|
|
||||||
.flatMap((e) => [...e.route])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function randomStationPair() {
|
export function randomStationPair() {
|
||||||
const keys = Object.keys(agency.stations);
|
const keys = Object.keys(agency.stations);
|
||||||
// select a random source station
|
// select a random source station
|
||||||
const a = keys[Math.floor(Math.random() * keys.length)];
|
const a = keys[Math.floor(Math.random() * keys.length)];
|
||||||
|
|
||||||
const aLines = linesForStation(a);
|
const aLines = agency.stations[a].routes;
|
||||||
|
|
||||||
const stationsOnSameLine = agency.edges
|
const stationsOnSameLine = agency.edges
|
||||||
.filter((e) => !aLines.isDisjointFrom(e.route))
|
.filter((e) => !aLines.isDisjointFrom(e.route))
|
||||||
@@ -45,8 +46,8 @@ function stationNeighbors(station) {
|
|||||||
|
|
||||||
// caleb's patented graph traversal algorithm (tm)
|
// caleb's patented graph traversal algorithm (tm)
|
||||||
function routeGoesBetweenStations(route, stationA, stationB) {
|
function routeGoesBetweenStations(route, stationA, stationB) {
|
||||||
let currentNodes = [stationA];
|
const currentNodes = [stationA];
|
||||||
let visited = [];
|
const visited = [];
|
||||||
let stops = 0;
|
let stops = 0;
|
||||||
|
|
||||||
let possible = false;
|
let possible = false;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount, createEventDispatcher } from "svelte";
|
import { onMount, createEventDispatcher } from "svelte";
|
||||||
import agency, { linesForStation, minStops, randomStationPair, stepsValidForStationPair } from "../agency"
|
import agency, { minStops, randomStationPair, stepsValidForStationPair } from "../agency"
|
||||||
import MbtaLine from "./MbtaLine.svelte";
|
import MbtaLine from "./MbtaLine.svelte";
|
||||||
import RouteBuilder from "./RouteBuilder.svelte";
|
import RouteBuilder from "./RouteBuilder.svelte";
|
||||||
import gsap from "gsap";
|
import gsap from "gsap";
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
<h3 class="text-3xl">
|
<h3 class="text-3xl">
|
||||||
<span class="inline-flex items-center justify-center gap-2">
|
<span class="inline-flex items-center justify-center gap-2">
|
||||||
<span class="font-bold">{agency.stations[from].stop_name}</span>
|
<span class="font-bold">{agency.stations[from].stop_name}</span>
|
||||||
{#each linesForStation(from) as line}
|
{#each agency.stations[from].routes as line}
|
||||||
<MbtaLine name={line} compact />
|
<MbtaLine name={line} compact />
|
||||||
{/each}
|
{/each}
|
||||||
to
|
to
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<span class="inline-flex items-center justify-center gap-2">
|
<span class="inline-flex items-center justify-center gap-2">
|
||||||
<span class="font-bold">{agency.stations[to].stop_name}</span>
|
<span class="font-bold">{agency.stations[to].stop_name}</span>
|
||||||
{#each linesForStation(to) as line}
|
{#each agency.stations[to].routes as line}
|
||||||
<MbtaLine name={line} compact />
|
<MbtaLine name={line} compact />
|
||||||
{/each}
|
{/each}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -53,7 +53,7 @@
|
|||||||
<div class="mb-5 max-w-96">
|
<div class="mb-5 max-w-96">
|
||||||
<h1 class="font-black text-5xl">How It Works</h1>
|
<h1 class="font-black text-5xl">How It Works</h1>
|
||||||
|
|
||||||
<p class="mb-2">We'll show you a pair of T stations in Boston: an origin and a destination.</p>
|
<p class="mb-2">You'll see a pair of T stations in Boston: an origin and a destination.</p>
|
||||||
|
|
||||||
<img src={screenshot.src} class="w-full border rounded-lg mb-2" />
|
<img src={screenshot.src} class="w-full border rounded-lg mb-2" />
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user