Skip to content

Added function to return routes and their minimuim and maximum SRMP values. #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion route-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
<th>SR</th>
<th>RRT</th>
<th>RRQ</th>
<th>Direction</th>
<th>Shield</th>
<th>RRT Description</th>
<th>RRQ Description</th>
<th>Direction</th>
<th>Min SRMP</th>
<th>Max SRMP</th>
</tr>
</thead>
<tbody id="route-list"></tbody>
Expand Down
92 changes: 92 additions & 0 deletions src/milepost-info/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
let results: FeatureAttributes[] | undefined;

const srmpFieldName = "SRMP";
const routeIdFieldName = "RouteID";
const directionFieldName = "Direction";
const minSrmpFieldName = "MinSrmp";
const maxSrmpFieldName = "MaxSrmp";

const outStatistics = [
{
statisticType: "MIN",
onStatisticField: srmpFieldName,
outStatisticFieldName: minSrmpFieldName,
},
{
statisticType: "MAX",
onStatisticField: srmpFieldName,
outStatisticFieldName: maxSrmpFieldName,
},
] as const;

interface FeatureAttributes {
RouteID: string;
Direction: "i" | "d";
MinSrmp: number;
MaxSrmp: number;
}

interface Feature {
attributes: FeatureAttributes;
}

interface FeatureSet extends Record<string, unknown> {
displayFieldName: "";
fieldAliases: {
RouteID: typeof routeIdFieldName;
Direction: typeof directionFieldName;
MinSrmp: typeof minSrmpFieldName;
MaxSrmp: typeof maxSrmpFieldName;
};
fields: [
{
name: typeof routeIdFieldName;
type: "esriFieldTypeString";
alias: typeof routeIdFieldName;
length: 12;
},
{
name: typeof directionFieldName;
type: "esriFieldTypeString";
alias: typeof directionFieldName;
length: 2;
},
{
name: typeof minSrmpFieldName;
type: "esriFieldTypeSingle";
alias: typeof minSrmpFieldName;
},
{
name: typeof maxSrmpFieldName;
type: "esriFieldTypeSingle";
alias: typeof maxSrmpFieldName;
},
];
features: Feature[];
}

export const milepostsUrl =
"https://data.wsdot.wa.gov/arcgis/rest/services/Shared/MilepostValues/FeatureServer/3/query/";
/**
* Retrieves a list of all route IDs and their minimum and maximum SRMP values.
* @returns - A list of route IDs and their minimum and maximum SRMP values.
*/
export async function getRouteList() {
if (!results) {
const fieldPairString = `${routeIdFieldName},${directionFieldName}`;
const search = new URLSearchParams([
["outStatistics", JSON.stringify(outStatistics)],
["returnGeometry", "false"],
["groupByFieldsForStatistics", fieldPairString],
["orderByFields", fieldPairString],
["f", "json"],
]);
const url = new URL(`?${search.toString()}`, milepostsUrl);
const response = await fetch(url);
console.debug(response);
results = ((await response.json()) as FeatureSet).features.map(
(feature) => feature.attributes,
);
}
return results;
}
50 changes: 29 additions & 21 deletions src/route-list-page.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { getRoutes } from "./elc";
import { RouteTypes } from "./elc/types";
import { getRouteList } from "./milepost-info";
import "./route-list.css";
import "@fontsource/lato";
import "@wsdot/web-styles/css/wsdot-colors.css";
import { RouteDescription } from "wsdot-route-utils";

const routes = await getRoutes();
const routes = await getRouteList();

const routeDescriptions = Object.entries(routes.Current).map(
([routeName, routeTypes]) => {
const route = new RouteDescription(routeName);
const { sr, rrt, rrq, shield, rrtDescription, rrqDescription } = route;
return {
routeObject: route,
route: route.toString(),
sr,
rrt,
rrq,
shield,
rrtDescription,
rrqDescription,
routeTypes: RouteTypes[routeTypes],
} as const;
},
);
const routeDescriptions = routes.map((r) => {
const { RouteID, MinSrmp, MaxSrmp, Direction } = r;
const route = new RouteDescription(RouteID);

const { sr, rrt, rrq, shield, rrtDescription, rrqDescription } = route;
return {
routeObject: route,
route: route.toString(),
sr,
rrt,
rrq,
direction: Direction,
shield,
rrtDescription,
rrqDescription,
minSrmp: MinSrmp,
maxSrmp: MaxSrmp,
} as const;
});

const sortFunction = (
a: (typeof routeDescriptions)[number],
Expand All @@ -38,6 +39,9 @@ const sortFunction = (
if (a.rrt !== null && b.rrt !== null && a.rrt !== b.rrt) {
return a.rrt.localeCompare(b.rrt);
}
if (a.direction !== b.direction) {
return b.direction.localeCompare(a.direction);
}
return 0;
};
// Sort the routeDescriptions alphabetically by the "route" property, then by rrq, then by rrt.
Expand Down Expand Up @@ -75,7 +79,11 @@ for (const routeDataRow of routeDescriptions) {
const cell = rowElement.insertCell();
cell.classList.add(key);
if (value != null) {
cell.append(value);
if (typeof value === "number") {
cell.append(value.toString());
} else {
cell.append(value);
}
}
}

Expand Down
Loading
Loading