Skip to content

[Data] Annotated Data: Create a Shuttle class #262

@0-Rick

Description

@0-Rick

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.py file that creates a Shuttle class, similar to the Shuttle in testing.
Then we'll want to refactor this code to instantiate the Shuttle class and store a list of Shuttle instances 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 the Shuttle instances (convert them into JSON). For this, define a to_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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions