Warsaw ZTM API Fetcher and Data Analyzer
Project description
ZTM Buses Package
Current Features
The package consists of three main functionalities:
- ZTMFetcher
- BusStatistician
- Visualizer
ZTMFetcher
The ZTMFetcher module allows acquiring information from the Warsaw API.
-
Import the module:
from ztm_buses import ZTMFetcher
-
Initialize with multiple API keys (may be beneficial when handling a substantial number of requests.):
fetcher = ZTMFetcher(['your_apikey1', 'your_apikey2'])
API keys can be obtained on https://api.um.warszawa.pl/.
-
Fetch Bus Location:
location = fetcher.fetch_bus_location()
-
Fetch Bus Location Period:
hour_location = fetcher.fetch_bus_location_period(period, "filename_to_save_json.json")
-
Fetch Bus Stop Coordinates and Routes:
fetcher.fetch_busstop_coordinates("filename_to_save_json.json") fetcher.fetch_routes("filename_to_save_json.json")
For all methods, if a filename was not given, the data will be automatically saved with the date to avoid overwriting issues.
-
Fetch Lines for Bus Stop:
list_of_lines = fetcher.fetch_lines_for_busstop(bus_stop_complex_id, bus_stop_id)
-
Fetch Whole Timetable:
fetcher.read_the_whole_schedule("filename_to_save_json.json")
Beware that fetching the whole timetable requires sending about 28,000 requests and may take from 20 to 50 minutes depending on the server load.
BusStatistician
The BusStatistician module allows obtaining information about the speed and punctuality of buses.
-
Import the module:
from ztm_buses import BusStatistician
-
Initialize:
statistician = BusStatistician(bus_coordinates_file, timetable_file, routes_file, bus_stops_file)
-
Get Speed Statistics:
speed_data_frame = statistician.get_speed_statistics()
-
Get Punctuality Statistics:
punctuality_data_frame = statistician.get_punctuality_statistics()
The
speed_data_framecontains the columns: 'speed', 'lon', 'lat', 'vehicle_number', 'line_number'. Thepunctuality_data_framecontains 'Bus_num', 'Line', 'Busstop_id', 'Busstop_name', 'Lon', 'Lat', 'Arrived', 'Expected', 'Delay [min]'.
Due to the complicated structure of bus routes and imperfections of the data, the punctuality data is prone to some larger errors.
Visualizer
The Visualizer module takes the dataframes from the BusStatistician and plots them on the Warsaw map.
-
Import the module:
from ztm_buses import Visualizer
-
Initialize:
vis = Visualizer()
-
Heat Map of Speeds:
vis.heat_map_speeds(speed_data_frame, html_file_to_save)
-
Scatter Map of Speeds:
vis.scatter_map_speeds(speed_data_frame, html_file_to_save)
For speed maps output html file is optional and if not given the result will not be saved
-
Map of Punctuality:
vis.map_punctuality(punctuality_data_frame, html_file_to_save)
For punctuality map the html file is required parameter
It is worth noting that before visualizing the data, it has to be cleaned up as the API sometimes responds with nonrealistic data (time traveling, hypersonic buses).
Installation
pip install ztm_buses
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ztm_buses-0.0.1.tar.gz.
File metadata
- Download URL: ztm_buses-0.0.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
371357863ee70af9751e059c1173332243affb49729372e308e8575959d80226
|
|
| MD5 |
b8d22bb2ea0613646729fec9a8564978
|
|
| BLAKE2b-256 |
7c0cd293a6624bf359faf510dc844b81356991293d77bfd0994a87ac5ceef2b2
|
File details
Details for the file ztm_buses-0.0.1-py3-none-any.whl.
File metadata
- Download URL: ztm_buses-0.0.1-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79441e6e85d4a0bfa8a2fcc4f76b26a49530a7acf026ab40993efa6a7ecc536d
|
|
| MD5 |
6cb20238498aa868e56afe6cac0dd3b2
|
|
| BLAKE2b-256 |
62054f968e3151d2c927d0daf993cf1c151a2a042df308d2d2fbd454d217a510
|