# 路況 (https://nolantw.github.io/tdx/reference/traffic/)

## `Traffic`

### `authorities`

```python
def authorities(
    *,
    query: Query[TrafficAuthority] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[TrafficAuthority]
```

取得提供路況資料的機關。

### `detectors`

```python
def detectors(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[VehicleDetector] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[VehicleDetector]
```

取得車輛偵測器與監測路段。

### `detector_observations`

```python
def detector_observations(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[DetectorObservation] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[DetectorObservation]
```

取得各車道的即時速率、占有率與車流量。

### `message_signs`

```python
def message_signs(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[MessageSign] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[MessageSign]
```

取得資訊可變標誌。

### `sign_observations`

```python
def sign_observations(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[SignObservation] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[SignObservation]
```

取得資訊可變標誌目前顯示的內容。

### `cameras`

```python
def cameras(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[TrafficCamera] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[TrafficCamera]
```

取得路況攝影機的串流或影像網址。

### `etag_gantries`

```python
def etag_gantries(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[ETagGantry] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[ETagGantry]
```

取得 eTag 偵測站。

### `etag_pairs`

```python
def etag_pairs(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[ETagPair] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[ETagPair]
```

取得 eTag 配對路徑與涵蓋的路段。

### `etag_observations`

```python
def etag_observations(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[ETagObservation] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[ETagObservation]
```

取得 eTag 旅行時間、速率與車流量。

### `sections`

```python
def sections(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[TrafficSection] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[TrafficSection]
```

取得監測路段。

### `section_links`

```python
def section_links(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[SectionLinks] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[SectionLinks]
```

取得監測路段的基礎路段組成。

### `section_shapes`

```python
def section_shapes(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[SectionShape] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[SectionShape]
```

取得監測路段的線型。

### `section_observations`

```python
def section_observations(
    area: City | str | TrafficArea,
    *,
    identifier: str | None = None,
    query: Query[SectionObservation] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[SectionObservation]
```

取得監測路段的即時速率、旅行時間與壅塞程度。

### `congestion_scales`

```python
def congestion_scales(
    area: City | str | TrafficArea,
    *,
    query: Query[CongestionScale] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[CongestionScale]
```

取得壅塞程度的定義。

### `news`

```python
def news(
    area: City | str | TrafficArea,
    *,
    query: Query[TrafficNews] | QueryParams | None = None,
    limit: int | None = None,
    offset: int = 0,
    cache_ttl: float | None = None,
) -> Records[TrafficNews]
```

取得最新路況消息。

## `TrafficArea`

```python
class TrafficArea(Enum):
    FREEWAY = 'Freeway'
    HIGHWAY = 'Highway'
```

## `TrafficAuthority`

```python
class TrafficAuthority(BaseModel):
    code: str
    name: str | None
    english_name: str | None
```

## `TrafficPoint`

```python
class TrafficPoint(BaseModel):
    longitude: float | None
    latitude: float | None
```

## `TrafficRoadSection`

```python
class TrafficRoadSection(BaseModel):
    start: str | None
    end: str | None
```

## `TrafficRoadLocation`

```python
class TrafficRoadLocation(BaseModel):
    road_id: str | None
    road_name: str | None
    road_class: int | None
    direction: str | None
    road_section: TrafficRoadSection | None
    sub_authority_code: str | None
```

## `TrafficDevice`

```python
class TrafficDevice(TrafficRoadLocation):
    longitude: float | None
    latitude: float | None
    link_id: str | None
    location_type: int | None
    mileage: str | None
    layout_map_url: str | None
```

## `DetectionLink`

```python
class DetectionLink(BaseModel):
    id: str
    bearing: str | None
    direction: str | None
    lanes: int | None
    actual_lanes: int | None
```

## `VehicleDetector`

```python
class VehicleDetector(TrafficDevice):
    id: str
    detector_type: int | None
    detection_type: int | None
    bidirectional: int | None
    detection_links: tuple[DetectionLink, ...] | None
```

## `MessageSign`

```python
class MessageSign(TrafficDevice):
    id: str
```

## `CameraView`

```python
class CameraView(BaseModel):
    bearing: str | None
    image: str | None
```

## `TrafficCamera`

```python
class TrafficCamera(TrafficDevice):
    id: str
    stream_url: str | None
    image_url: str | None
    refresh_rate: int | None
    views: tuple[CameraView, ...] | None
    surveillance_type: int | None
    surveillance_description: str | None
```

## `ETagGantry`

```python
class ETagGantry(TrafficDevice):
    id: str
```

## `TrafficLink`

```python
class TrafficLink(BaseModel):
    id: str
```

## `OpenLRLocation`

```python
class OpenLRLocation(BaseModel):
    code: str
```

## `ETagPair`

```python
class ETagPair(BaseModel):
    id: str
    start_gantry_id: str | None
    end_gantry_id: str | None
    start_link_id: str | None
    end_link_id: str | None
    links: tuple[TrafficLink, ...] | None
    description: str | None
    distance: float | None
    section_id: str | None
    geometry: str | None
    sub_authority_code: str | None
```

## `TrafficObservation`

```python
class TrafficObservation(BaseModel):
    sub_authority_code: str | None
    collected_at: MaybeTimestamp
```

## `VehicleFlow`

```python
class VehicleFlow(BaseModel):
    vehicle_type: str | None
    volume: int | None
    speed: float | None
```

## `TrafficLane`

```python
class TrafficLane(BaseModel):
    id: int
    lane_type: int | None
    speed: float | None
    occupancy: float | None
    vehicles: tuple[VehicleFlow, ...] | None
    error_type: str | None
```

## `LinkFlow`

```python
class LinkFlow(BaseModel):
    id: str
    lanes: tuple[TrafficLane, ...] | None
```

## `DetectorObservation`

```python
class DetectorObservation(TrafficObservation):
    id: str
    links: tuple[LinkFlow, ...] | None
    status: int | None
```

## `SignMessage`

```python
class SignMessage(BaseModel):
    text: str | None
    image: str | None
    type: int | None
    priority: int | None
```

## `SignObservation`

```python
class SignObservation(TrafficObservation):
    id: str
    messages: tuple[SignMessage, ...] | None
    status: int | None
    message_status: int | None
```

## `ETagFlow`

```python
class ETagFlow(BaseModel):
    vehicle_type: int | None
    travel_time: int | None
    standard_deviation: int | None
    speed: float | None
    vehicle_count: int | None
```

## `ETagObservation`

```python
class ETagObservation(TrafficObservation):
    id: str
    start_status: int | None
    end_status: int | None
    flows: tuple[ETagFlow, ...] | None
    start_time: MaybeTimestamp
    end_time: MaybeTimestamp
```

## `SectionMileage`

```python
class SectionMileage(BaseModel):
    start: str | None
    end: str | None
```

## `TrafficSection`

```python
class TrafficSection(TrafficRoadLocation):
    id: str
    name: str | None
    length: float | None
    speed_limit: int | None
    links: tuple[TrafficLink, ...] | None
    open_lr: tuple[OpenLRLocation, ...] | None
    mileage: SectionMileage | None
    start: TrafficPoint | None
    end: TrafficPoint | None
```

## `SectionLinks`

```python
class SectionLinks(BaseModel):
    id: str
    sub_authority_code: str | None
    start_link_id: str | None
    end_link_id: str | None
    links: tuple[TrafficLink, ...] | None
```

## `SectionShape`

```python
class SectionShape(BaseModel):
    id: str
    sub_authority_code: str | None
    geometry: str | None
```

## `TrafficDataSources`

```python
class TrafficDataSources(BaseModel):
    historical: int | None
    detector: int | None
    avi: int | None
    etag: int | None
    gvp: int | None
    cvp: int | None
    other: int | None
```

## `SectionObservation`

```python
class SectionObservation(TrafficObservation):
    id: str
    travel_time: int | None
    speed: float | None
    congestion_level_id: str | None
    congestion_level: str | None
    links: tuple[TrafficLink, ...] | None
    open_lr: tuple[OpenLRLocation, ...] | None
    sources: TrafficDataSources | None
```

## `CongestionBand`

```python
class CongestionBand(BaseModel):
    level: int
    name: str | None
    upper_bound: int | None
    lower_bound: int | None
```

## `CongestionScale`

```python
class CongestionScale(BaseModel):
    id: str
    sub_authority_code: str | None
    name: str | None
    description: str | None
    measure: str | None
    levels: tuple[CongestionBand, ...] | None
```

## `TrafficNews`

```python
class TrafficNews(BaseModel):
    id: str
    sub_authority_code: str | None
    language: str | None
    department: str | None
    title: str | None
    category: int | None
    description: str | None
    url: str | None
    attachment_url: str | None
    published_at: MaybeTimestamp
    starts_at: MaybeTimestamp
    ends_at: MaybeTimestamp
    updated_at: MaybeTimestamp
```