-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
This is the third issue of a series. #41 is the corresponding frontend change; #59 is the old JSON format.
In the future, to make some of this code clearer, we're gonna want to create a
data/shuttle.pyfile that creates aShuttleclass, similar to theShuttlein testing.
Then we'll want to refactor this code to instantiate theShuttleclass and store a list ofShuttleinstances for the day. It can still iterate through the location data, but rather than manually modifying the schema, each shuttle should have the following methods:
add_break_location(timestamp)add_loop_location(timestamp)change_state(new_state)is_stopped()- ...
Then, we can replace the manual modification using the schema's format with calls to methods, which should clean up the code significantly.
Lastly, before returning the response, we'll need to serialize theShuttleinstances (convert them into JSON). For this, define ato_json()method, that converts the instance to the JSON schema we use.
Originally posted by @jmccand in #255 (comment)
The Shuttle Class will be used in the data_today() function in server/routes.py . The outputted JSON Format of this function is as follows:
{
"shuttleID1": {
"locations": {
"16:25:53": {
"at_stop": null,
"closest_polyline": 1,
"closest_route": "NORTH",
"closest_route_location": [42.7379143365656, -73.6675641148277],
"distance": 0.0100496703554305,
"latitude": 42.7380042100651,
"longitude": -73.6675511200586,
"status": "loop"
},
"16:26:01": { ... },
"16:26:08": { ... }
// ...
},
"breaks": [
{
"locations": [
"16:28:08", /* break start time */
"16:28:16",
"16:28:23",
"16:28:30",
"16:28:37" /* break end time */
]
},
{
"locations": [ ... ]
}
],
"loops": [
{
"locations": [
"16:25:53", /* loop start time */
"16:26:01",
"16:26:08",
"16:26:15",
"16:26:22" /* loop end time */
]
},
{
"locations": [ ... ]
}
]
},
"shuttleID2": { ... },
"shuttleID3": { ... }
// ...
}Metadata
Metadata
Assignees
Labels
No labels