gtfs_segments.route_stats
average_active_buses(df_dir)
Calculate the average number of active buses per time interval.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_dir |
DataFrame
|
The input DataFrame containing bus data. |
required |
Returns:
Type | Description |
---|---|
Dict[str, floating[Any]]
|
Dict[str, np.floating[Any]]: A dictionary with the average number of active buses. |
Source code in gtfs_segments/route_stats.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
get_all_peak_times(df_dir)
It takes a dataframe of bus trips and returns the peak number of buses and the time of the peak
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
the dataframe of the route you want to get the peak times for |
required |
Returns:
Type | Description |
---|---|
Dict[str, NDArray[Any]]
|
A dictionary with the peak number of buses in each direction, and the peak times. |
Source code in gtfs_segments/route_stats.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
get_average_headway(df_dir)
For each route, find the shape with the most trips, then find the stop with the most trips on that shape, then find the average headway for that stop
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_route |
a dataframe containing the route you want to analyze |
required |
Returns:
Type | Description |
---|---|
Dict[str, float]
|
A dictionary with the average headway for each direction. |
Source code in gtfs_segments/route_stats.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
get_average_speed(df_dir, route_dict)
It takes a dataframe of a route and a dictionary of route information and returns a dictionary of average speeds for each direction
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_route |
a dataframe of the route |
required | |
route_dict |
dict
|
a dictionary containing the route length and total time for each direction |
required |
Returns:
Type | Description |
---|---|
Dict[str, float]
|
A dictionary with the average speed for each direction. |
Source code in gtfs_segments/route_stats.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
get_bus_spacing(route_dict)
It takes a dataframe of a route and a dictionary of route information and returns a dictionary of the minimum spacing between buses on the route
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_route |
a dataframe of all the trips for a given route |
required | |
route_dict |
dict
|
a dictionary containing the route length and number of buses for each direction |
required |
Returns:
Type | Description |
---|---|
Dict[str, float]
|
A dictionary with the keys 'spacing dir 0' and 'spacing dir 1' |
Source code in gtfs_segments/route_stats.py
251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
get_peak_time(df)
The function get_peak_time
takes a dataframe of bus trips and returns the number of buses and the
time at which the most buses are running.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
The parameter |
required |
such as start_time
and end_time
that represent the start and end times of each bus trip.
Returns:
Type | Description |
---|---|
List
|
a list containing the number of buses and the time at which the most buses are running. |
Source code in gtfs_segments/route_stats.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
get_route_grp(route_df)
It takes a dataframe of route information and returns a dataframe of route information with the first and last stop times for each trip
Parameters:
Name | Type | Description | Default |
---|---|---|---|
route_df |
DataFrame
|
The dataframe containing the route information |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe with the first and last stop of each trip. |
Source code in gtfs_segments/route_stats.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
get_route_lens(df_dir, df_shapes)
It takes a dataframe of trips for a given route and a dataframe of shapes for a given route, and returns a dictionary with the length of the route in each direction
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_route |
a dataframe of the routes.txt file |
required | |
df_shapes |
LineString
|
the shapes dataframe |
required |
Returns:
Type | Description |
---|---|
Dict[str, float]
|
A dictionary with the route lengths for each direction. |
Source code in gtfs_segments/route_stats.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
|
get_route_stats(feed, peak_time=False)
It takes a GTFS feed and a route_id and returns a dataframe with the following columns:
- route_id
- route_length
- route_time
- average_headway
- peak_times
- average_speed
- min_spacing
- stop_spacing
The function is a bit long, but it's not too complicated.
The first thing it does is merge the stop_times and trips tables. This is necessary because the stop_times table doesn't have the route_id column.
The next thing it does is create an empty dictionary called route_dict. This will be used to store the results of the analysis.
For each route, it creates a new dictionary called ret_dict. This will be used to store the results of the analysis for the current
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feed |
Feed
|
the GTFS feed object |
required |
route_id |
The route_id of the route you want to analyze |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe with the route_id as the first column and the rest columns are the stats for the route. |
Source code in gtfs_segments/route_stats.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
get_route_time(df_dir)
For each route, find the shape_id that has the most trips, then find the trip_id that has that shape_id, then find the arrival_time of the first and last stop of that trip_id, then subtract the two to get the total time of the route
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_route |
a dataframe of a route |
required |
Returns:
Type | Description |
---|---|
Dict[str, float]
|
A dictionary with the total time for each direction. |
Source code in gtfs_segments/route_stats.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
get_sec(time_str)
It takes a string in the format of hh:mm:ss and returns the number of seconds
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_str |
str
|
The time string to convert to seconds. |
required |
Returns:
Type | Description |
---|---|
int
|
the total number of seconds in the time string. |
Source code in gtfs_segments/route_stats.py
31 32 33 34 35 36 37 38 39 40 41 42 |
|
get_service_length(df)
The function takes a GTFS feed and a route_id, sorts the dataframe by stop_sequence, adjusts the shape_dist_traveled values if necessary, and returns the maximum shape_dist_traveled value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
The parameter |
required |
Returns:
Type | Description |
---|---|
int
|
The maximum value of the 'shape_dist_traveled' column in for the trip. |
Source code in gtfs_segments/route_stats.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
get_stop_spacing(df_dir, route_dict)
For each route, find the shape with the most trips, and then find the number of stops on that trip. Then divide the route length by the number of stops to get the stop spacing
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_route |
a dataframe of the stops for a given route |
required | |
route_dict |
dict
|
a dictionary containing the route_id, route length in each direction, and the number |
required |
of trips in each direction
Returns:
Type | Description |
---|---|
Dict[str, float]
|
A dictionary with the stop spacing for each direction. |
Source code in gtfs_segments/route_stats.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
get_trips(df, time)
Return all trips that are currently active at a given time
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
the dataframe containing the trips |
required |
time |
int
|
the time in seconds |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe of all trips that start before the time and end after the time. |
Source code in gtfs_segments/route_stats.py
59 60 61 62 63 64 65 66 67 68 69 70 |
|
get_trips_len(df, time)
It returns the number of trips that are currently active at a given time
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
the dataframe of trips |
required |
time |
int
|
the time in seconds |
required |
Returns:
Type | Description |
---|---|
int
|
The number of trips that are active at a given time. |
Source code in gtfs_segments/route_stats.py
45 46 47 48 49 50 51 52 53 54 55 56 |
|
get_zone_epsg_from_ls(geom)
The function takes a dataframe with a geometry column and returns the EPSG code for the UTM zone that contains the geometry
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stop_df |
a dataframe with a geometry column |
required |
Returns:
Type | Description |
---|---|
int
|
The EPSG code for the UTM zone that the stop is in. |
Source code in gtfs_segments/route_stats.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|