CarbonFootprint-API: Initial support for reverse-lookup of emissions
This brings inital support for reverse lookup of emissions in three categories: trees, vehicles and trains. For a given emission value, the API returns a match in the specified section which produces similar emissions. A new route /comparer is to be used for the reverse lookup.
1. Trains:
Request:
{ "emissions" : { "CO2": 180.205172 }, "relativeLocation": { "lat": 19.0760, "lng": 72.8777 }, "section": "trains" }
Response:
{ "success": true, "matches": [ { "train": "", "section": "trains", "match": { "source": "Kurla Junction", "destination": "Tilak Nagar", "passengers": 3651, "distance": 1.198 } } ] }
We need to provide a relative location in order to provide a response that is relatable to the user. A user based in the US cannot relate to comparison results from Sri lanka!
2. Trees:
Request:
{ "emissions" : { "CO2": 180.205172 }, "relativeLocation": { "lat": 47.6062, "lng": -122.3321 }, "section": "trees" }
Response:
{ "success": true, "matches": [ { "match": { "item": "Hackberry", "quantity": 30.543249491525422, "unit": "year" }, "section": "trees" } ] }
3. Vehicles
Request:
{ "emissions" : { "CO2": 180.205172 }, "relativeLocation": { "lat": 47.6062, "lng": -122.3321 }, "section": "vehicles" }
Response:
{ "success": true, "matches": [ { "match": { "source": "Seattle", "sourceState": "Washington", "destination": "Farmersville", "destinationState": "California", "mileage": 16.580229821693486, "distance": 1283.4377864337648 }, "section": "vehicles" } ] }
4. All categories
Request:
{ "emissions" : { "CO2": 180.205172 }, "relativeLocation": { "lat": 19.0760, "lng": 72.8777 }, "section": "all" }
Response:
{ "success": true, "matches": [ [ { "status": "success", "match": { "source": "Kurla Junction", "destination": "Tilak Nagar", "passengers": 3651, "distance": 1.198 }, "section": "trains" }, { "status": "success", "match": { "source": "Mumbai", "sourceState": "Maharashtra", "destination": "Barasat", "destinationState": "West Bengal", "mileage": 21.404898407496944, "distance": 1656.9043810848425 }, "section": "vehicles" }, { "status": "success", "match": { "item": "Ginkgo", "quantity": 5.090541581920904, "unit": "year" }, "section": "trees" } ] ] }
The vehicle reverse-lookup returns results for petrol vehicle by default.
The API with the given data can produce a lot of possible matches, therefore a random match is sent to the user for a variety of comparisons.
Additional requirements Please enable the Google Places API in your Google Cloud Project before testing this.
Fixes #41