Skip to content
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

refactor(ts/models/shuttle) implement shuttle prefix using shuttleVariantFromRunId #2862

Open
wants to merge 3 commits into
base: kf/refactor/vehicle-marker-file
Choose a base branch
from
Open
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
67 changes: 46 additions & 21 deletions assets/src/models/shuttle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
import { Vehicle } from "../realtime"
import { RunId, Vehicle } from "../realtime"

export enum ShuttleVariant {
// Rapid Transit Lines
Blue = "Blue",
Green = "Green",
Orange = "Orange",
Red = "Red",

// Other Shuttle Types
CommuterRail = "CR",
Special = "Special",
}

export const shuttleVariantFromRunId = (
runId: RunId
): ShuttleVariant | null => {
switch (runId) {
case "999-0501":
return ShuttleVariant.Blue
case "999-0502":
return ShuttleVariant.Green
case "999-0503":
return ShuttleVariant.Orange
case "999-0504":
return ShuttleVariant.Red
case "999-0505":
return ShuttleVariant.CommuterRail
case "999-0555":
return ShuttleVariant.Special
default:
return null
}
}

const prefix = (variant: ShuttleVariant | null): string => {
switch (variant) {
case null:
return ""
case ShuttleVariant.CommuterRail:
return "Commuter Rail "
default:
return variant + " "
}
}

export const formattedRunNumber = ({ runId }: Vehicle): string => {
if (runId === null) {
Expand All @@ -8,24 +52,5 @@ export const formattedRunNumber = ({ runId }: Vehicle): string => {
const [area, run] = runId.split("-")

// Remove leading zero from the run portion
return `${prefix(run)}${area} ${run.slice(1)}`
}

const prefix = (run: string): string => {
switch (run) {
case "0501":
return "Blue "
case "0502":
return "Green "
case "0503":
return "Orange "
case "0504":
return "Red "
case "0505":
return "Commuter Rail "
case "0555":
return "Special "
default:
return ""
}
return `${prefix(shuttleVariantFromRunId(runId))}${area} ${run.slice(1)}`
}
Loading