# 歷史資料 (https://nolantw.github.io/tdx/reference/historical/)

## `Historical`

### `daily`

```python
def daily(
    archive: DailyArchive[T],
    start: date,
    end: date | None = None,
) -> Generator[T]
```

讀取一天的資料，或含 `end` 在內最多 7 天的資料。

### `snapshot`

```python
def snapshot(snapshot: Snapshot[T], day: date) -> Records[T]
```

取得資料在指定日期的版本。

### `versions`

```python
def versions(
    snapshot: Snapshot[T],
    start: date,
    end: date,
) -> Records[ArchiveVersion]
```

列出資料在兩個日期之間的版本。

### `accidents`

```python
def accidents(
    kind: Literal['A1', 'A2'],
    city: City | str,
    year: int,
    month: int | None = None,
) -> Generator[Accident]
```

讀取一年或一個月的 A1（死亡）或 A2（受傷）類交通事故。

### `accident_parties`

```python
def accident_parties(
    kind: Literal['A1', 'A2', 'A30'],
    city: City | str,
    year: int,
    month: int | None = None,
) -> Generator[AccidentParty]
```

讀取一年或一個月交通事故的當事人。

### `accident_ranking`

```python
def accident_ranking(city: City | str, year: int) -> Generator[AccidentRank]
```

讀取縣市的易肇事路口排行。

### `accident_codes`

```python
def accident_codes() -> Generator[AccidentCode]
```

讀取交通事故代碼的意義。

## `DailyArchive`

```python
class DailyArchive:
    model: type[T]
    version: int
    path: str
```

每日封存的資料。

## `Snapshot`

```python
class Snapshot:
    model: type[T]
    dataset: str
    scope: str
    tabular: bool
```

保存各版本的資料。

### `on`

```python
def on(day: date) -> str
```

### `between`

```python
def between(start: date, end: date) -> str
```

## `ETagVolume`

```python
class ETagVolume(BaseModel):
    interval: MaybeTimestamp
    gantry_id: str
    direction: str | None
    vehicle_type: str | None
    volume: int | None
    source_updated_at: MaybeTimestamp
    updated_at: MaybeTimestamp
```

## `ETagTravelTime`

```python
class ETagTravelTime(BaseModel):
    interval: MaybeTimestamp
    from_gantry_id: str
    to_gantry_id: str
    vehicle_type: str | None
    seconds: int | None
    volume: int | None
    source_updated_at: MaybeTimestamp
    updated_at: MaybeTimestamp
```

## `ETagSpeed`

```python
class ETagSpeed(BaseModel):
    interval: MaybeTimestamp
    from_gantry_id: str
    to_gantry_id: str
    vehicle_type: str | None
    speed: int | None
    volume: int | None
    source_updated_at: MaybeTimestamp
    updated_at: MaybeTimestamp
```

## `ETagTrip`

```python
class ETagTrip(BaseModel):
    vehicle_type: str | None
    started_at: MaybeTimestamp
    from_gantry_id: str
    ended_at: MaybeTimestamp
    to_gantry_id: str | None
    length: MaybeFloat
    complete: str | None
    gantries: str | None
    source_updated_at: MaybeTimestamp
    updated_at: MaybeTimestamp
```

## `ETagTripLength`

```python
class ETagTripLength(BaseModel):
    interval: MaybeTimestamp
    from_gantry_id: str
    vehicle_type: str | None
    length: MaybeFloat
    volume: int | None
    source_updated_at: MaybeTimestamp
    updated_at: MaybeTimestamp
```

## `ETagTripCount`

```python
class ETagTripCount(BaseModel):
    interval: MaybeTimestamp
    from_gantry_id: str
    to_gantry_id: str
    vehicle_type: str | None
    volume: int | None
    source_updated_at: MaybeTimestamp
    updated_at: MaybeTimestamp
```

## `WeatherHazard`

```python
class WeatherHazard(BaseModel):
    location: str | None
    geocode: str | None
    phenomena: str | None
    significance: str | None
    starts_at: MaybeTimestamp
    ends_at: MaybeTimestamp
    source_updated_at: MaybeTimestamp
    updated_at: MaybeTimestamp
```

## `WeatherObservation`

```python
class WeatherObservation(BaseModel):
    station_id: str
    location: str | None
    observed_at: MaybeTimestamp
    longitude: MaybeFloat
    latitude: MaybeFloat
    temperature: MaybeFloat
    humidity: MaybeFloat
    pressure: MaybeFloat
    wind_direction: MaybeFloat
    wind_speed: MaybeFloat
    elevation: MaybeFloat
    rain_24_hours: MaybeFloat
    rain_day: MaybeFloat
    gust_speed: MaybeFloat
    gust_direction: MaybeFloat
    gust_time: str | None
    gust_speed_10_minutes: MaybeFloat
    gust_direction_10_minutes: MaybeFloat
    gust_time_10_minutes: str | None
    uv_index: MaybeFloat
    high_temperature: MaybeFloat
    high_temperature_time: str | None
    low_temperature: MaybeFloat
    low_temperature_time: str | None
    sunshine_hours: MaybeFloat
    visibility: str | None
    city: str | None
    town: str | None
    source_updated_at: MaybeTimestamp
    updated_at: MaybeTimestamp
```

## `Accident`

```python
class Accident(BaseModel):
    key: int
    case_number: str | None
    kind: int | None
    city_code: str | None
    county_id: str | None
    unit: str | None
    happened_at: str | None
    site: str | None
    deaths: int | None
    injuries: int | None
    speed_limit: int | None
    weather_code: int | None
    light_code: int | None
    road_categories_code: int | None
    road_type_code: int | None
    accident_location_code: int | None
    pavement_code: int | None
    pavement_condition_code: int | None
    pavement_defects_code: int | None
    obstacles_code: int | None
    sight_distance_code: int | None
    signal_type_code: int | None
    signal_actions_code: int | None
    traffic_facilities_code: int | None
    traffic_facilities_fast_lane_code: int | None
    traffic_facilities_lane_code: int | None
    traffic_facilities_edge_code: int | None
    accident_patterns_code: int | None
    longitude: MaybeFloat
    latitude: MaybeFloat
    updated_at: MaybeTimestamp
```

## `AccidentParty`

```python
class AccidentParty(BaseModel):
    key: int
    accident_key: int
    case_number: str | None
    person_number: int | None
    age: int | None
    city_code: str | None
    county_id: str | None
    gender_code: int | None
    injured_level_code: int | None
    main_injured_code: int | None
    protective_gear_code: int | None
    cell_have_code: int | None
    action_status_code: int | None
    driving_eligibility_code: int | None
    license_type_code: int | None
    drinking_code: int | None
    impact_first_code: int | None
    impact_other_code: int | None
    cause_judge_code: int | None
    cause_reason_code: int | None
    hit_out_code: int | None
    job_code: int | None
    trip_purpose_code: int | None
    vehicle_code: int | None
    vehicle_usage_code: int | None
    updated_at: MaybeTimestamp
```

## `AccidentRank`

```python
class AccidentRank(BaseModel):
    year: int
    city: str | None
    city_code: str | None
    district: str | None
    rank: int
    road: str | None
    longitude: MaybeFloat
    latitude: MaybeFloat
    accidents: int | None
    a1_accidents: int | None
    a2_accidents: int | None
    updated_at: MaybeTimestamp
```

## `AccidentCode`

```python
class AccidentCode(BaseModel):
    key: int
    type: str
    code: str | None
    name: str | None
```

## `ArchiveVersion`

```python
class ArchiveVersion(BaseModel):
    start: Timestamp
    end: MaybeTimestamp
    version: str
    data_hash: str
    count: int | None
    size: int | None
```

## `ArchivedStationGroup`

```python
class ArchivedStationGroup(BaseModel):
    id: str
    uid: str
    name: Name
    position: MaybePosition
    city: str | None
    city_code: str | None
    town: str | None
    town_code: str | None
```

## `ArchivedBikeStation`

```python
class ArchivedBikeStation(BaseModel):
    uid: str
    id: str
    authority_id: str | None
    name: Name
    position: MaybePosition
    address: Name | None
    capacity: int
    service_type: int
```

## `ArchivedBusShape`

```python
class ArchivedBusShape(BaseModel):
    route_id: str
    route_uid: str
    route_name: Name
    subroute_id: str | None
    subroute_uid: str | None
    direction: int | None
    geometry: str
    encoded_polyline: str | None
    subroute_name: Name | None
```

## `ArchivedMetroBoardEntry`

```python
class ArchivedMetroBoardEntry(BaseModel):
    line_id: str
    line_no: str | None
    line_name: Name
    station_id: str
    station_name: Name
    headsign: str | None
    destination_id: str | None
    destination_name: Name | None
    estimate_seconds: int | None
    source_updated_at: MaybeTimestamp
    updated_at: MaybeTimestamp
```

## `ArchivedRailShape`

```python
class ArchivedRailShape(BaseModel):
    line_id: str
    line_no: str | None
    line_name: Name
    geometry: str
    encoded_polyline: str | None
```

## `ArchivedRailExit`

```python
class ArchivedRailExit(BaseModel):
    station_id: str
    station_name: Name
    id: str
    name: Name | None
    position: MaybePosition
    description: str | None
    stair: bool | None
    escalator: int | None
    elevator: bool | None
```

## `ArchivedRailLine`

```python
class ArchivedRailLine(BaseModel):
    id: str
    number: str | None
    name: str
    name_en: str | None
    section_name: str | None
    section_name_en: str | None
    color: str | None
    is_branch: bool | None
```

## `ArchivedNetworkLine`

```python
class ArchivedNetworkLine(BaseModel):
    id: str
    number: str | None
```

## `ArchivedRailNetwork`

```python
class ArchivedRailNetwork(BaseModel):
    id: str
    name: str | None
    name_en: str | None
    operator_id: str | None
    operator_name: str | None
    operator_name_en: str | None
    map_url: str | None
    lines: tuple[ArchivedNetworkLine, ...]
```

## `ArchivedTicketPrice`

```python
class ArchivedTicketPrice(BaseModel):
    ticket_type: str | None
    price: MaybeFloat
```

## `ArchivedRailFare`

```python
class ArchivedRailFare(BaseModel):
    origin_id: str
    origin_name: Name
    destination_id: str
    destination_name: Name
    direction: int | None
    prices: tuple[ArchivedTicketPrice, ...]
```

## `ArchivedLineStation`

```python
class ArchivedLineStation(BaseModel):
    sequence: int
    station_id: str
    station_name: str | None
    distance: MaybeFloat
```

## `ArchivedLineStations`

```python
class ArchivedLineStations(BaseModel):
    line_id: str
    line_no: str | None
    stations: tuple[ArchivedLineStation, ...]
```

## `ArchivedTrain`

```python
class ArchivedTrain(TrainInfo):
    ...
```

## `ArchivedTimetable`

```python
class ArchivedTimetable(BaseModel):
    train: ArchivedTrain
    stops: tuple[RailStopTime, ...]
    service_days: ServiceDays | None
```

## `Archives`

```python
class Archives:
    ...
```

選擇每日封存的資料。

### `bike_availability`

```python
def bike_availability(city: City | str) -> DailyArchive[BikeAvailability]
```

### `bus_positions`

```python
def bus_positions(city: City | str | None) -> DailyArchive[BusVehiclePosition]
```

### `bus_stop_events`

```python
def bus_stop_events(city: City | str | None) -> DailyArchive[BusStopEvent]
```

### `bus_news`

```python
def bus_news(city: City | str | None) -> DailyArchive[BusNews]
```

### `detectors`

```python
def detectors(area: City | str | TrafficArea) -> DailyArchive[VehicleDetector]
```

### `detector_observations`

```python
def detector_observations(
    area: City | str | TrafficArea,
) -> DailyArchive[DetectorObservation]
```

### `message_signs`

```python
def message_signs(area: City | str | TrafficArea) -> DailyArchive[MessageSign]
```

### `sign_observations`

```python
def sign_observations(
    area: City | str | TrafficArea,
) -> DailyArchive[SignObservation]
```

### `cameras`

```python
def cameras(area: City | str | TrafficArea) -> DailyArchive[TrafficCamera]
```

### `etag_gantries`

```python
def etag_gantries(area: City | str | TrafficArea) -> DailyArchive[ETagGantry]
```

### `etag_pairs`

```python
def etag_pairs(area: City | str | TrafficArea) -> DailyArchive[ETagPair]
```

### `etag_observations`

```python
def etag_observations(
    area: City | str | TrafficArea,
) -> DailyArchive[ETagObservation]
```

### `sections`

```python
def sections(area: City | str | TrafficArea) -> DailyArchive[TrafficSection]
```

### `section_links`

```python
def section_links(area: City | str | TrafficArea) -> DailyArchive[SectionLinks]
```

### `section_shapes`

```python
def section_shapes(area: City | str | TrafficArea) -> DailyArchive[SectionShape]
```

### `congestion_scales`

```python
def congestion_scales(
    area: City | str | TrafficArea,
) -> DailyArchive[CongestionScale]
```

### `section_observations`

```python
def section_observations(
    area: City | str | TrafficArea,
) -> DailyArchive[SectionObservation]
```

### `air_departures`

```python
def air_departures() -> DailyArchive[Departure]
```

### `air_arrivals`

```python
def air_arrivals() -> DailyArchive[Arrival]
```

### `flights`

```python
def flights() -> DailyArchive[Flight]
```

### `airport_weather`

```python
def airport_weather() -> DailyArchive[AirportWeather]
```

### `tourist_shuttle_positions`

```python
def tourist_shuttle_positions() -> DailyArchive[TouristShuttleVehiclePosition]
```

### `tourist_shuttle_stop_events`

```python
def tourist_shuttle_stop_events() -> DailyArchive[TouristShuttleStopEvent]
```

### `tourist_shuttle_news`

```python
def tourist_shuttle_news() -> DailyArchive[BusNews]
```

### `car_park_availability`

```python
def car_park_availability(
    area: City | str | ParkingArea,
) -> DailyArchive[CarParkAvailability]
```

### `street_segment_availability`

```python
def street_segment_availability(
    city: City | str,
) -> DailyArchive[ParkingSegmentAvailability]
```

### `street_spot_availability`

```python
def street_spot_availability(
    city: City | str,
) -> DailyArchive[StreetSpotAvailability]
```

### `railway_boards`

```python
def railway_boards() -> DailyArchive[TrainBoardEntry]
```

### `railway_delays`

```python
def railway_delays() -> DailyArchive[TrainDelay]
```

### `high_speed_alerts`

```python
def high_speed_alerts() -> DailyArchive[RailAlert]
```

### `high_speed_news`

```python
def high_speed_news() -> DailyArchive[RailNews]
```

### `metro_boards`

```python
def metro_boards(system: str) -> DailyArchive[ArchivedMetroBoardEntry]
```

### `metro_news`

```python
def metro_news(system: str) -> DailyArchive[RailNews]
```

### `metro_alerts`

```python
def metro_alerts(system: str) -> DailyArchive[RailAlert]
```

### `etag_volumes`

```python
def etag_volumes() -> DailyArchive[ETagVolume]
```

### `etag_travel_times`

```python
def etag_travel_times() -> DailyArchive[ETagTravelTime]
```

### `etag_speeds`

```python
def etag_speeds() -> DailyArchive[ETagSpeed]
```

### `etag_trips`

```python
def etag_trips() -> DailyArchive[ETagTrip]
```

### `etag_trip_lengths`

```python
def etag_trip_lengths() -> DailyArchive[ETagTripLength]
```

### `etag_trip_counts`

```python
def etag_trip_counts() -> DailyArchive[ETagTripCount]
```

### `weather_hazards`

```python
def weather_hazards() -> DailyArchive[WeatherHazard]
```

### `weather_stations`

```python
def weather_stations() -> DailyArchive[WeatherObservation]
```

### `automatic_weather_stations`

```python
def automatic_weather_stations() -> DailyArchive[WeatherObservation]
```

## `Snapshots`

```python
class Snapshots:
    ...
```

選擇保存各版本的資料。

### `bus_stops`

```python
def bus_stops(city: City | str | None) -> Snapshot[BusStop]
```

### `bus_stations`

```python
def bus_stations(city: City | str | None) -> Snapshot[BusStation]
```

### `bus_routes`

```python
def bus_routes(city: City | str | None) -> Snapshot[BusRoute]
```

### `bus_fares`

```python
def bus_fares(city: City | str | None) -> Snapshot[BusRouteFare]
```

### `bus_schedules`

```python
def bus_schedules(city: City | str | None) -> Snapshot[BusSchedule]
```

### `bus_shapes`

```python
def bus_shapes(city: City | str | None) -> Snapshot[ArchivedBusShape]
```

### `bus_station_groups`

```python
def bus_station_groups(
    city: City | str | None,
) -> Snapshot[ArchivedStationGroup]
```

### `bus_route_stops`

```python
def bus_route_stops(city: City | str | None) -> Snapshot[BusRouteStops]
```

### `bus_display_stops`

```python
def bus_display_stops(city: City | str) -> Snapshot[BusRouteStops]
```

### `bus_first_last_trips`

```python
def bus_first_last_trips(city: City | str) -> Snapshot[BusFirstLastTrips]
```

### `intercity_daily_timetables`

```python
def intercity_daily_timetables() -> Snapshot[BusDailyTimetable]
```

### `bike_stations`

```python
def bike_stations(city: City | str) -> Snapshot[ArchivedBikeStation]
```

### `airports`

```python
def airports() -> Snapshot[Airport]
```

### `airlines`

```python
def airlines() -> Snapshot[Airline]
```

### `domestic_flights`

```python
def domestic_flights() -> Snapshot[RecurringFlight]
```

### `international_flights`

```python
def international_flights() -> Snapshot[RecurringFlight]
```

### `metro_first_last`

```python
def metro_first_last(system: str) -> Snapshot[MetroFirstLast]
```

### `metro_frequencies`

```python
def metro_frequencies(system: str) -> Snapshot[MetroFrequency]
```

### `metro_lines`

```python
def metro_lines(system: str) -> Snapshot[RailLine]
```

### `metro_line_transfers`

```python
def metro_line_transfers(system: str) -> Snapshot[RailLineTransfer]
```

### `metro_shapes`

```python
def metro_shapes(system: str) -> Snapshot[ArchivedRailShape]
```

### `metro_networks`

```python
def metro_networks(system: str) -> Snapshot[RailNetwork]
```

### `metro_fares`

```python
def metro_fares(system: str) -> Snapshot[RailFare]
```

### `metro_routes`

```python
def metro_routes(system: str) -> Snapshot[RailRoute]
```

### `metro_travel_times`

```python
def metro_travel_times(system: str) -> Snapshot[RailRouteTravelTimes]
```

### `metro_stations`

```python
def metro_stations(system: str) -> Snapshot[RailStation]
```

### `metro_exits`

```python
def metro_exits(system: str) -> Snapshot[ArchivedRailExit]
```

### `metro_facilities`

```python
def metro_facilities(system: str) -> Snapshot[RailStationFacilities]
```

### `metro_line_stations`

```python
def metro_line_stations(system: str) -> Snapshot[RailLineStations]
```

### `metro_route_stations`

```python
def metro_route_stations(system: str) -> Snapshot[RailRouteStations]
```

### `metro_station_timetables`

```python
def metro_station_timetables(system: str) -> Snapshot[RailStationTimetable]
```

### `railway_lines`

```python
def railway_lines() -> Snapshot[ArchivedRailLine]
```

### `railway_networks`

```python
def railway_networks() -> Snapshot[ArchivedRailNetwork]
```

### `railway_daily_timetables`

```python
def railway_daily_timetables() -> Snapshot[ArchivedTimetable]
```

### `railway_daily_trains`

```python
def railway_daily_trains() -> Snapshot[ArchivedTrain]
```

### `railway_recurring_timetables`

```python
def railway_recurring_timetables() -> Snapshot[ArchivedTimetable]
```

### `railway_recurring_trains`

```python
def railway_recurring_trains() -> Snapshot[ArchivedTrain]
```

### `railway_fares`

```python
def railway_fares() -> Snapshot[ArchivedRailFare]
```

### `railway_stations`

```python
def railway_stations() -> Snapshot[RailStation]
```

### `railway_line_stations`

```python
def railway_line_stations() -> Snapshot[ArchivedLineStations]
```

### `railway_train_types`

```python
def railway_train_types() -> Snapshot[RailTrainType]
```

### `railway_shapes`

```python
def railway_shapes() -> Snapshot[ArchivedRailShape]
```

### `high_speed_daily_timetables`

```python
def high_speed_daily_timetables() -> Snapshot[ArchivedTimetable]
```

### `high_speed_daily_trains`

```python
def high_speed_daily_trains() -> Snapshot[ArchivedTrain]
```

### `high_speed_recurring_timetables`

```python
def high_speed_recurring_timetables() -> Snapshot[ArchivedTimetable]
```

### `high_speed_fares`

```python
def high_speed_fares() -> Snapshot[RailFare]
```

### `high_speed_stations`

```python
def high_speed_stations() -> Snapshot[RailStation]
```

### `high_speed_exits`

```python
def high_speed_exits() -> Snapshot[ArchivedRailExit]
```

### `high_speed_shapes`

```python
def high_speed_shapes() -> Snapshot[ArchivedRailShape]
```