electricitymaps / bloom-contrib

Making carbon footprint data available to everyone.
https://www.bloomclimate.com
MIT License
435 stars 104 forks source link

WIP: Transport for London integration #221

Closed liamgarrison closed 4 years ago

liamgarrison commented 4 years ago

Work in progress.

This currently works for my Oyster account details, and results in the following activities:

Need to figure out how to calculate start and end point, or distance, for Bus journeys

  {
    id: '',
    datetime: '2019-10-13T06:42:56+00:00',
    durationHours: null,
    distanceKilometers: '',
    activityType: 'ACTIVITY_TYPE_TRANSPORTATION',
    transportationMode: 'public_transport',
    carrier: 'Transport For London',
    departureStation: 'Bus',
    destinationStation: 'Bus'
  },
  {
    id: '',
    datetime: '2019-10-14T07:11:18+00:00',
    durationHours: null,
    distanceKilometers: '',
    activityType: 'ACTIVITY_TYPE_TRANSPORTATION',
    transportationMode: 'public_transport',
    carrier: 'Transport For London',
    departureStation: 'Chiswick Park',
    destinationStation: 'Unknown'
  },
  {
    id: '',
    datetime: '2019-10-14T07:11:18+00:00',
    durationHours: 0.5019444444444444,
    distanceKilometers: '',
    activityType: 'ACTIVITY_TYPE_TRANSPORTATION',
    transportationMode: 'public_transport',
    carrier: 'Transport For London',
    departureStation: 'Chiswick Park',
    destinationStation: 'Victoria (London Underground)'
  },
  {
    id: '',
    datetime: '2019-10-14T17:06:56+00:00',
    durationHours: 0.16472222222222221,
    distanceKilometers: '',
    activityType: 'ACTIVITY_TYPE_TRANSPORTATION',
    transportationMode: 'public_transport',
    carrier: 'Transport For London',
    departureStation: 'Victoria (London Underground)',
    destinationStation: 'Vauxhall (London Underground)'
  },
  {
    id: '',
    datetime: '2019-10-14T19:06:15+00:00',
    durationHours: 0.20833333333333334,
    distanceKilometers: '',
    activityType: 'ACTIVITY_TYPE_TRANSPORTATION',
    transportationMode: 'public_transport',
    carrier: 'Transport For London',
    departureStation: 'Vauxhall (National Rail)',
    destinationStation: 'Putney'
  },
  {
    id: '',
    datetime: '2019-10-17T12:26:40+00:00',
    durationHours: 0.4602777777777778,
    distanceKilometers: '',
    activityType: 'ACTIVITY_TYPE_TRANSPORTATION',
    transportationMode: 'public_transport',
    carrier: 'Transport For London',
    departureStation: 'Putney',
    destinationStation: 'Victoria (National Rail Southern)'
  },
  {
    id: '',
    datetime: '2019-10-17T17:40:18+00:00',
    durationHours: 0.3836111111111111,
    distanceKilometers: '',
    activityType: 'ACTIVITY_TYPE_TRANSPORTATION',
    transportationMode: 'public_transport',
    carrier: 'Transport For London',
    departureStation: 'Victoria (National Rail Southern)',
    destinationStation: 'Putney'
  },
  {
    id: '',
    datetime: '2019-10-18T09:06:36+00:00',
    durationHours: 0.5413888888888889,
    distanceKilometers: '',
    activityType: 'ACTIVITY_TYPE_TRANSPORTATION',
    transportationMode: 'public_transport',
    carrier: 'Transport For London',
    departureStation: 'Putney Bridge',
    destinationStation: 'Victoria (London Underground)'
  },
  {
    id: '',
    datetime: '2019-10-20T14:27:48+00:00',
    durationHours: null,
    distanceKilometers: '',
    activityType: 'ACTIVITY_TYPE_TRANSPORTATION',
    transportationMode: 'public_transport',
    carrier: 'Transport For London',
    departureStation: 'Bus',
    destinationStation: 'Bus'
  },
  {
    id: '',
    datetime: '2019-10-20T15:10:02+00:00',
    durationHours: null,
    distanceKilometers: '',
    activityType: 'ACTIVITY_TYPE_TRANSPORTATION',
    transportationMode: 'public_transport',
    carrier: 'Transport For London',
    departureStation: 'Bus',
    destinationStation: 'Bus'
  }
]
liamgarrison commented 4 years ago

Fixes #3

martincollignon commented 4 years ago

https://www.whatdotheyknow.com/request/average_bus_journey_length_in_km

Should we use this data for bus? People could then edit if they wanted.

martincollignon commented 4 years ago

https://www.whatdotheyknow.com/request/bus_passenger_journey_times this looks even better

willtonkin commented 4 years ago

That was quick! Fantastic.

On a serious note:

Is the team comfortable storing another apps ‘AppId’ in the source code?

willtonkin commented 4 years ago

There might be some useful data in the APIs that might offer metrics for estimation, distance between places perhaps? Actually thinking about it, I’d expect duration, as @martincollignon suggests, might be better for an estimation.

https://api.tfl.gov.uk/swagger/ui/index.html

I’m on mobile atm so can’t really dig around much

martincollignon commented 4 years ago

@willtonkin isn't it publicly available?

liamgarrison commented 4 years ago

https://www.whatdotheyknow.com/request/bus_passenger_journey_times this looks even better

This looks good for an average bus journey duration. Seems like ~3140 is what we should put into the model, but it's annoying it doesn't give a unit... I'm guessing it is in seconds? So that gives 52 mins?

liamgarrison commented 4 years ago

Also, how far back do you want this to pull data for? It's currently set to past two weeks...

martincollignon commented 4 years ago

https://www.whatdotheyknow.com/request/bus_passenger_journey_times this looks even better

This looks good for an average bus journey duration. Seems like ~3140 is what we should put into the model, but it's annoying it doesn't give a unit... I'm guessing it is in seconds? So that gives 52 mins?

I would think this is in meters - which is even better!

I think we'd like the data to go back as far as possible, depending on how long it takes to pull that data. Our other integrations only fetch the most recent ones afterward.

liamgarrison commented 4 years ago

Ok, i've added the average bus journey distance, and have got it fetching 56 days of data (max allowed)

liamgarrison commented 4 years ago

Sorry guys, realised that i was committing to master on my forked repository, will create a new MR from a feature branch.