department-for-transport-BODS / bods-data-extractor

A python client for downloading and extracting data from the UK Bus Open Data Service
Other
44 stars 8 forks source link

Ensure that final timetables output can handle vehicle journeys overlapping midnight (2) #34

Closed apartner96 closed 1 year ago

apartner96 commented 1 year ago

Describe the bug Currently, due to specific PTI logic that is not accounted for, vehicle journeys that overlap midnight (ie start at 23:50 and end at 01:00), are incorrectly represented in the final timetables output.

To Reproduce Steps to reproduce the behavior: Run the below code then find a vehicle journey that overlaps 00:00

#intiate an object instance called my_bus_data_object with desired parameters
from BODSDataExtractor.extractor import TimetableExtractor

my_bus_data_object = TimetableExtractor(api_key=api # Your API Key Here
                                 ,limit=1 # How many datasets to view
                                 ,status = 'published' # Only view published datasets
                                 ,service_line_level=True # True if you require Service line data 
                                 ,stop_level=True # True if you require stop level data
                                 )

#save the extracted stop level data to stop_level variable
stop_level = my_bus_data_object.timetable_dict

#note that in downloading stop level the  data, the dataset and service line level will also be downloaded. Can access this as below:
dataset_level = my_bus_data_object.metadata
service_line_level = my_bus_data_object.service_line_extract

#save meta data and service line level data to csv file in your downloads directory
my_bus_data_object.save_metadata_to_csv()
my_bus_data_object.save_service_line_extract_to_csv()

#stop_level variable is a dictionary of dataframes, which can be saved to csv as follows (saves in downloads directory)
my_bus_data_object.save_all_timetables_to_csv()

Expected behavior These vehicle journeys that overlap midnight should be represented accurately.

Additional context This bug needs investigating more thoroughly before it can be fixed. Suggest reading PTI 1.1 doc on midnight timetables first.

spencer-b-318 commented 1 year ago

should be included in a wider improvement of timetable calculation #45