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

include_fields averagingPeriod with json #115

Open
barronh opened this issue Oct 3, 2022 · 3 comments
Open

include_fields averagingPeriod with json #115

barronh opened this issue Oct 3, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@barronh
Copy link

barronh commented Oct 3, 2022

I am currently unable to get averagingPeriod with v2 and output json. I believe that this was previously operational.

For replication, I am copying the URLs built with the "try it" documentation interface (https://api.openaq.org/docs). Each is designed to output one (the same) measurement. Both request averagingPeriod, but only v1 receives it.

Version 1

https://api.openaq.org/v1/measurements?format=json&date_from=2022-10-01T00%3A00%3A00%2B00%3A00&date_to=2022-10-03T18%3A03%3A00%2B00%3A00&limit=1&page=1&offset=0&sort=desc&parameter=pm25&radius=1000&country_id=US&order_by=datetime&isMobile=false&isAnalysis=false&entity=government&sensorType=reference%20grade&include_fields=averagingPeriod

{
  "meta": {
    "name": "openaq-api",
    "license": "CC BY 4.0d",
    "website": "api.openaq.org",
    "page": 1,
    "limit": 1,
    "found": 73204
  },
  "results": [
    {
      "location": "St. Maries",
      "parameter": "pm25",
      "value": 10,
      "date": {
        "utc": "2022-10-03T16:00:00Z",
        "local": "2022-10-03T09:00:00-07:00"
      },
      "unit": "µg/m³",
      "coordinates": {
        "latitude": 47.3167,
        "longitude": -116.570297
      },
      "country": "US",
      "city": "BENEWAH",
      "averagingPeriod": {
        "unit": "seconds",
        "value": 3600
      }
    }
  ]
}

Version 2

https://api.openaq.org/v2/measurements?format=json&date_from=2022-10-01T00%3A00%3A00%2B00%3A00&date_to=2022-10-03T18%3A03%3A00%2B00%3A00&limit=1&page=1&offset=0&sort=desc&parameter=pm25&radius=1000&country_id=US&order_by=datetime&isMobile=false&isAnalysis=false&entity=government&sensorType=reference%20grade&include_fields=averagingPeriod

{
  "meta": {
    "name": "openaq-api",
    "license": "CC BY 4.0d",
    "website": "api.openaq.org",
    "page": 1,
    "limit": 1,
    "found": 73204
  },
  "results": [
    {
      "locationId": 1774,
      "location": "St. Maries",
      "parameter": "pm25",
      "value": 10,
      "date": {
        "utc": "2022-10-03T16:00:00+00:00",
        "local": "2022-10-03T09:00:00-07:00"
      },
      "unit": "µg/m³",
      "coordinates": {
        "latitude": 47.3167,
        "longitude": -116.570297
      },
      "country": "US",
      "city": "BENEWAH",
      "isMobile": false,
      "isAnalysis": false,
      "entity": "government",
      "sensorType": "reference grade"
    }
  ]
}

Thanks for any advice.

@russbiggs
Copy link
Member

Thanks for raising this issue. It looks like v2 has never supported the includes_fields when outputting json. From what I can tell it looks like an oversight in the original implementation. I can take a look and see what it would take to allow it in the v2/measurements without format=csv and see if its feasible.

@russbiggs russbiggs added the enhancement New feature or request label Oct 3, 2022
@barronh
Copy link
Author

barronh commented Oct 3, 2022

What would be the "right" way to include averagingPeriod in csv. I am using JSON because when I first started, CSV didn't support object type subfields. Although it would be nice if this worked in JSON, I could be persuaded to move to CSV. (BTW - that was v1)

@barronh
Copy link
Author

barronh commented Oct 3, 2022

I see now that if I ask for averagingPeriod in CSV, I do get it. It is formatted as a python dictionary field. I can unpack that as columns (averagingPeriod_value and averagingPeriod_unit). If there is a better way, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants