wawbus package

Subpackages

Submodules

wawbus.constants module

wawbus.constants.BUS_LENGTH

biggest ZTM bus is 18m long, Source: https://pl.wikipedia.org/wiki/Autobusy_miejskie_w_Warszawie

Type:

int

wawbus.constants.MAX_SPEED

maximum physically possible speed for a bus, Source: https://pl.wikipedia.org/wiki/Autobusy_miejskie_w_Warszawie

Type:

int

wawbus.constants.M_TO_KM

meters to kilometers

Type:

float

wawbus.constants.CRS

Coordinate Reference System used by the UM API

Type:

str

wawbus.main module

class wawbus.main.WawBus(*, apikey: str | None = None, dataset: str | None = None, retry_count: int = 3)

Bases: object

Main class for collecting and processing bus data

api

ZtmApi instance

Type:

ZtmApi

tt

Timetable dataframe

Type:

pd.DataFrame

stops

Stop locations dataframe

Type:

pd.DataFrame

dataset

Dataset of bus positions dataframe

Type:

pd.DataFrame

tt_worker_count

Number of timetable collection workers when collecting timetables

Type:

int

api: ZtmApi | None = None
calculate_late(tolerance: Timedelta = Timedelta('0 days 00:15:00')) DataFrame

Calculate how late buses are

Parameters:

tolerance (pd.Timedelta) – time tolerance for merging timetable and dataset

Returns:

A union of dataset and timetable with new “dist” column added specifying distance to the stop the bus was supposed to be at.

calculate_speed() DataFrame

Calculate speed from dataset

Returns:

A copy of self.dataset dataframe with new “Speed” column added.

collect_positions(count: int, sleep_between: int = 10)

Collect bus positions

Parameters:
  • count (int) –

    • number of collections

  • sleep_between (int) –

    • time between collections

Updates:

self.dataset (pd.DataFrame): Dataset of bus positions dataframe

Raises:
  • ZtmApiException – when API returns an error more than self.retry_count times

  • ValueError – when API key is not provided

  • InvalidColumnName – when API returns an invalid column name

collect_stops()

Collect stop positions

Updates:

self.stops (pd.DataFrame): Stop locations dataframe

Raises:
  • ValueError – when API key is not provided

  • ZtmApiException – when API returns an error more than self.retry_count times

  • InvalidColumnName – when API returns an invalid column name

collect_timetables()

Collect ALL timetables for all stops

Updates:

self.tt (pd.DataFrame): Timetable dataframe

Raises:

ValueError – when API key is not provided

dataset: DataFrame = Empty DataFrame Columns: [] Index: []
stops: DataFrame | None = None
tt: DataFrame | None = None
tt_worker_count: int = 5

Module contents