Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ridership annual summary endpoint improvements #25

Open
1 of 2 tasks
jaronheard opened this issue May 30, 2018 · 7 comments
Open
1 of 2 tasks

Ridership annual summary endpoint improvements #25

jaronheard opened this issue May 30, 2018 · 7 comments

Comments

@jaronheard
Copy link
Contributor

jaronheard commented May 30, 2018

Two requests:

@bhgrant8
Copy link
Member

bhgrant8 commented Jun 1, 2018

@jaronheard on point 1:

Not yet deployed but added check to function after filtering by year:

Logic:

  • counts number of unique dates
  • divides 52 by this count
  • uses this number as multiplier, instead of 26, to account for potential differences.

code:

try:
                            stops = stops.filter(summary_begin_date__year=this_year)
                            count = stops.values('summary_begin_date').distinct().count()
                            aggregator = 52/count
                            if stops:
                                annual_sums = stops.aggregate(sum_ons=Sum('ons')*aggregator, sum_offs=Sum('offs')*aggregator)
                                weekday_sums = stops.filter(service_key__icontains="W").aggregate(sum_ons=Sum('ons')*5*aggregator, sum_offs=Sum('offs')*5*aggregator)
                                saturday_sums = stops.filter(service_key__icontains="S").aggregate(sum_ons=Sum('ons')*aggregator, sum_offs=Sum('offs')*aggregator)
                                sunday_sums = stops.filter(service_key__icontains="U").aggregate(sum_ons=Sum('ons')*aggregator, sum_offs=Sum('offs')*aggregator)
                                serialized_stops = PassengerCensusSerializer(stops, many=True)
                                return Response({'route_number': this_route_number,
                                    'year': this_year,
                                    'total_stops': stops.count(),
                                    'annual_sums': annual_sums,
                                    'weekday_sums': weekday_sums,
                                    'saturday_sums': saturday_sums,
                                    'sunday_sums': sunday_sums,
                                    'num_of_yearly_census': count
                                    })
                            else:
...

@bhgrant8
Copy link
Member

bhgrant8 commented Jun 1, 2018

I have an idea of what to do on point 2

@jaronheard
Copy link
Contributor Author

jaronheard commented Jun 1, 2018 via email

@bhgrant8
Copy link
Member

ok so a new version of this has been deployed with this logicL

route is a required filter
year optional (if not specified returns all years)

returns:
grouped by year:

  • year (extracted from summary_begin_date
  • weekday ons, offs, stops * 5 days * 52/number of census
  • saturday ons, offs, stops * 52/number of census
  • sunday ons, offs, stops * 52/number of census
  • number of census in the year

annual totals of each of these are then calculated as sums of the weekday, saturday, sunday amounts

routes that do not have either a saturday or sunday count for a given year are given 0 for values for day. additionally boolean fields are given for whether there was a saturday or sunday count for year.

Here is example response:
http://service.civicpdx.org/transportation-systems/passenger-census/passenger-census-routes-annual/?year=2001&route=15

[
  {
    "year": 2001,
    "weekday_sum_ons": 1755130,
    "weekday_sum_offs": 1714310,
    "weekday_total_stops": 33930,
    "saturday_sum_ons": 184990,
    "saturday_sum_offs": 176800,
    "saturday_total_stops": 33670,
    "sunday_sum_ons": 114062,
    "sunday_sum_offs": 111774,
    "sunday_total_stops": 34190,
    "num_of_yearly_census": 2,
    "sunday_census": true,
    "saturday_census": true,
    "annual_sum_ons": 2054182,
    "annual_sum_offs": 2002884,
    "total_annual_stops": 101790
  }
]

Note this does return a list, even with one response. LMK if it needs a separate retrieve

@BrianHGrant
Copy link
Member

talking with @flamingveggies, story cards were referencing daily averages as well as totals. as such created two endpoints, average and totals. calculating this now per route and system.

updated endpoints routing as well:

  • /transportation-systems/passenger-census/routes/annual/average/
  • /transportation-systems/passenger-census/routes/annual/total/
  • /transportation-systems/passenger-census/system/annual/average/
  • /transportation-systems/passenger-census/system/annual/total/

removed stop counts as did not seem relavant

@bhgrant8
Copy link
Member

will work on bus vs. rail. vs streetcar

@znmeb
Copy link
Contributor

znmeb commented Jun 11, 2018

Here's the current route / stop table - data-science-pet-containers/examples/transportation-database/tm_route_stops.csv

I'm pretty sure the streetcar and MAX route numbers haven't changed so everything that isn't a streetcar or a MAX is a bus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants