codeforpdx / opentransit-metrics

Prototype of public transit data visualization system
https://opentransit-pdx.herokuapp.com/
MIT License
7 stars 8 forks source link

Benji download arrival data #28

Closed sidetrackedmind closed 2 years ago

sidetrackedmind commented 2 years ago

Fixes #25

Proposed changes

The main goal of this pull request is to create a proof of concept for allowing a user to download arrival data for a particular route + date.

This pull request has 3 main changes:

  1. Adds a function to the ArrivalHistory class - save_date_for_user_download. This function runs get_by_date and then reformats the results into a more user friendly dataframe. The dataframe has renames the raw data headers as follows:

    rename_dict = {'t':'time','e':'departure_time','d':'distance','i':'trip_id', 'v':'vehicle_id'}
  2. Adds a enpoint @app.route('/api/arrival_download', methods=['GET']) to metrics-api flask app. In this proof of concept the route does not take any parameters and it always downloads the same route+date. The flask endpoint calls a function download_arrival_data that uses save_date_for_user_download for route='4' and date='2022-03-10' to create a dataframe and send the dataframe via flask make_response.

  3. Adding very basic placeholder code for a Download frontend tab. This may be all wrong but it gets the job down for testing 😄 .

Screenshot

image

sidetrackedmind commented 2 years ago

After discussing with the team, we decided:

I updated the download_arrival_data in metrics-api.py. The function is hard coded for now but it creates a ArrivalHistory object, calls get_data_frame and then renames some fields and adds others before sending the .csv to the user.

sidetrackedmind commented 2 years ago

My latest commits add the following:

See below screenshot of download arrival data button:

image
sidetrackedmind commented 2 years ago

I'm pulling the trigger on this 🥳