diff --git a/common/api/slowzones.ts b/common/api/slowzones.ts index 74335490..0e4b375f 100644 --- a/common/api/slowzones.ts +++ b/common/api/slowzones.ts @@ -1,22 +1,18 @@ import type { - DayDelayTotals, SlowZoneAllSlowResponse, SlowZoneDayTotalsResponse, - SlowZoneResponse, SpeedRestriction, } from '../types/dataPoints'; import type { FetchSpeedRestrictionsOptions, FetchSpeedRestrictionsResponse } from '../types/api'; import { getGtfsRailLineId } from '../utils/lines'; import { apiFetch } from './utils/fetch'; -// TODO: Remove the Array option once the slowzone change is mature -export const fetchDelayTotals = (): Promise => { +export const fetchDelayTotals = (): Promise => { const url = new URL(`/static/slowzones/delay_totals.json`, window.location.origin); return fetch(url.toString()).then((resp) => resp.json()); }; -// TODO: Remove the Array option once the slowzone change is mature -export const fetchAllSlow = (): Promise => { +export const fetchAllSlow = (): Promise => { const all_slow_url = new URL(`/static/slowzones/all_slow.json`, window.location.origin); return fetch(all_slow_url.toString()).then((resp) => resp.json()); }; diff --git a/modules/slowzones/SlowZonesDetails.tsx b/modules/slowzones/SlowZonesDetails.tsx index a0243037..edfbd139 100644 --- a/modules/slowzones/SlowZonesDetails.tsx +++ b/modules/slowzones/SlowZonesDetails.tsx @@ -75,7 +75,7 @@ export function SlowZonesDetails() {
{totalSlowTimeReady ? ( { {totalSlowTimeReady ? ( { return ( diff --git a/modules/slowzones/map/SlowZonesMap.tsx b/modules/slowzones/map/SlowZonesMap.tsx index 4954076d..be90fdcb 100644 --- a/modules/slowzones/map/SlowZonesMap.tsx +++ b/modules/slowzones/map/SlowZonesMap.tsx @@ -5,7 +5,7 @@ import { LineMap, createDefaultDiagramForLine } from '@transitmatters/stripmap'; import '@transitmatters/stripmap/dist/style.css'; import { LINE_OBJECTS } from '../../../common/constants/lines'; -import type { SlowZoneResponse, SpeedRestriction } from '../../../common/types/dataPoints'; +import type { SlowZoneAllSlowResponse, SpeedRestriction } from '../../../common/types/dataPoints'; import type { SlowZonesLineName } from '../types'; import { getSlowZoneOpacity } from '../../../common/utils/slowZoneUtils'; @@ -16,7 +16,7 @@ import { SlowSegmentLabel } from './SlowSegmentLabel'; import { SlowZonesTooltip } from './SlowZonesTooltip'; interface SlowZonesMapProps extends Pick, 'direction'> { - slowZones: SlowZoneResponse[]; + slowZones: SlowZoneAllSlowResponse; speedRestrictions: SpeedRestriction[]; lineName: SlowZonesLineName; } diff --git a/modules/slowzones/map/SlowZonesTooltip.module.css b/modules/slowzones/map/SlowZonesTooltip.module.css index 575c13c8..a7b660b3 100644 --- a/modules/slowzones/map/SlowZonesTooltip.module.css +++ b/modules/slowzones/map/SlowZonesTooltip.module.css @@ -1,78 +1,77 @@ .slowZonesTooltip { - display: flex; - align-items: center; - user-select: none; - --tooltip-background: white; + display: flex; + align-items: center; + user-select: none; + --tooltip-background: white; } .reverseVertical { - flex-direction: row; - flex-direction: row-reverse; + flex-direction: row; + flex-direction: row-reverse; } .horizontal { - flex-direction: column-reverse; - align-items: center; - transform: translateY(-5px); + flex-direction: column-reverse; + align-items: center; + transform: translateY(-5px); } .triangle { - width: 0; - height: 0; - z-index: 1; - border-top: 8px solid transparent; - border-bottom: 8px solid transparent; - border-right: 8px solid white; + width: 0; + height: 0; + z-index: 1; + border-top: 8px solid transparent; + border-bottom: 8px solid transparent; + border-right: 8px solid white; } .triangleReverse { - transform: scaleX(-1); + transform: scaleX(-1); } .triangleHorizontal { - width: 0; - height: 0; - z-index: 1; - border-left: 8px solid transparent; - border-right: 8px solid transparent; - border-top: 8px solid white; + width: 0; + height: 0; + z-index: 1; + border-left: 8px solid transparent; + border-right: 8px solid transparent; + border-top: 8px solid white; } .content { - border-radius: 4px; - overflow: hidden; - background: var(--tooltip-background); + border-radius: 4px; + overflow: hidden; + background: var(--tooltip-background); } - .title { - font-weight: 500; - padding: 6px 10px; - background: var(--tooltip-accent-color); - color: white; + font-weight: 500; + padding: 6px 10px; + background: var(--tooltip-accent-color); + color: white; } .body { - display: flex; - flex-direction: column; + display: flex; + flex-direction: column; } .directionTitle { - display: flex; - align-items: center; - gap: 4px; - margin-bottom: 4px; + display: flex; + align-items: center; + gap: 4px; + margin-bottom: 4px; } .speedRestriction { - padding: 6px; - margin: 6px; - margin-top: 0px; - border-radius: 4px; - max-width: 300px; + padding: 6px; + margin: 6px; + margin-top: 0px; + border-radius: 4px; + max-width: 300px; } .speedRestrictionStats { - display: flex; - flex-direction: column; -} \ No newline at end of file + display: flex; + flex-direction: column; +} diff --git a/modules/slowzones/map/segment.ts b/modules/slowzones/map/segment.ts index 3b13aa5a..d49e7362 100644 --- a/modules/slowzones/map/segment.ts +++ b/modules/slowzones/map/segment.ts @@ -1,6 +1,10 @@ import type { Diagram, SegmentLocation } from '@transitmatters/stripmap'; -import type { SlowZoneResponse, SpeedRestriction } from '../../../common/types/dataPoints'; +import type { + SlowZoneAllSlowResponse, + SlowZoneResponse, + SpeedRestriction, +} from '../../../common/types/dataPoints'; import type { LineShort } from '../../../common/types/lines'; import type { Station } from '../../../common/types/stations'; import { getParentStationForStopId, getStationById } from '../../../common/utils/stations'; @@ -26,7 +30,7 @@ type SegmentSlowZonesOptions = { date: Date; diagram: Diagram; speedRestrictions: SpeedRestriction[]; - slowZones: SlowZoneResponse[]; + slowZones: SlowZoneAllSlowResponse; lineName: LineShort; }; @@ -36,13 +40,11 @@ type WithSegmentLocation = { value: T; }; -// TODO(ian): our slow zones calculations currently set the end_date of all active slow zones -// to the moment when the calculation occurs. We can't distinguish these from a slow zone that -// ended in the past, so we clamp addressable dates at the max date in the slow zones json. -// To remove this hack we should set `end` on all active slow zones to null. -const getEffectiveDate = (desiredDate: Date, slowZones: SlowZoneResponse[]) => { - const allEndDates = slowZones.map((zone) => new Date(zone.end)); - const maxEndDate = allEndDates.sort((a, b) => a.valueOf() - b.valueOf()).pop()!; +/** + * Get the latest date that we have data on slow zones for + */ +const getEffectiveDate = (desiredDate: Date, slowZones: SlowZoneAllSlowResponse) => { + const maxEndDate = new Date(slowZones.updated_on); if (desiredDate.valueOf() > maxEndDate.valueOf()) { return maxEndDate; } @@ -132,7 +134,7 @@ export const segmentSlowZones = (options: SegmentSlowZonesOptions): Segmentation const effectiveDate = getEffectiveDate(desiredDate, slowZones); const activeSlowZones = locateIntoSegments( filterActiveElements( - slowZones, + slowZones.data, lineName, effectiveDate, (sz) => [new Date(sz.start), new Date(sz.end)], diff --git a/server/chalicelib/data_funcs.py b/server/chalicelib/data_funcs.py index c3e48800..aff3c044 100644 --- a/server/chalicelib/data_funcs.py +++ b/server/chalicelib/data_funcs.py @@ -125,7 +125,7 @@ def alerts(day: date, params): { "valid_from": alert_version["start"], "valid_to": alert_version["end"], - "text": alert_item["attributes"]["short_header"] or alert_item["attributes"]["header"], + "text": alert_item["attributes"]["header"] or alert_item["attributes"]["short_header"], } ) except KeyError as e: