A class named StoppageDetector that predicts stoppages from a GPS data file. The algorithm performs the following steps:
- Reads a GPS data file in the form of a CSV file using the pandas library.
- Initializes some variables for storing start and end timestamps and current and previous locations.
- Loops through the GPS data to find the distance between consecutive points.
- If the distance between two points is less than or equal to a user-defined distance_range, then the end_timestamp is updated and current_location is stored.
- If the distance is greater than the distance_range, then the result list is updated with the start_timestamp, end_timestamp and a list of dictionaries containing the previous and current locations.
- The result list is then returned as a list of tuples.
- The result list is then converted to a Pandas dataframe and written to a CSV file.
The Haversine formula is used to calculate the distance between two GPS coordinates. The script loops through the GPS data and compares the distances between consecutive GPS points. If the distance is less than or equal to the distance_range parameter, the end timestamp is updated and the current location is stored. If the distance is greater than the distance_range, the current stoppage is added to the results and a new stoppage starts.