USACE / cwms-data-api

Corps Water Management System RESTful Data Service
MIT License
13 stars 14 forks source link

Allow retrieval of constant value location levels over a date range #599

Open DanielTOsborne opened 6 months ago

DanielTOsborne commented 6 months ago

For non-timeseries location levels, I'd like to specify a date range and see all the values it was set to within that date range.

For example... Assuming the levels table contains these:

LOCATION_LEVEL_ID               LEVEL_DATE  LEVEL_UNIT  CONSTANT_LEVEL
Lake Isabella.Stor.Inst.0.Top of Gross Pool 01-JAN-00   ac-ft       568100.0
Lake Isabella.Stor.Inst.0.Top of Gross Pool 01-OCT-10   ac-ft       361249.99999999994
Lake Isabella.Stor.Inst.0.Top of Gross Pool 13-JUN-23   ac-ft       568100.0

Notice the LEVEL_DATE is different.

I'd like to supply a start and end date, and get a result like this:

{
  "office-id": "SPK",
  "location-level-id": "Lake Isabella.Stor.Inst.0.Top of Gross Pool",
  "seasonal-values": [],
  "constant-value": 568100,
  "constant-values": [
    ["1900-01-01T00:00:00-07:00", 568100],
    ["2010-10-01T00:00:00-07:00", 361249.99999999994],
    ["2024-06-13T00:00:00-07:00", 568100],
  ],
  "level-date-start": "1900-01-01T00:00:00-07:00",
  "level-date-end": "2024-06-13T00:00:00-07:00",
  "level-units-id": "ac-ft",
  "level-date": "2024-06-13T00:00:00-07:00",
  "interval-months": 0,
  "interval-minutes": 0,
  "attribute-units-id": "ac-ft"
}

For the regular single point-in-time query, I'd expect "constant-values" array to be empty, if present at all. At least if compatibility with the current version is desired. If not, making the entire thing an array even for a single result is fine with me. For compatibility, I left the current behavior in there as well, where it returns "constant-value" and "level-date", which is set to the most recent value in the date range requested. That can be changed if desired too.

I'm open to various output formats, I listed the above as an example. Personally, I'd prefer the unix epoch timestamp, like in timeseries, but this levels call already has its own date format. Though, the response doesn't include the timezone, so it's not round-trippable. That's a separate issue though.

adamkorynta commented 1 week ago

The getAll endpoint already accomplishes this. You can pass in the level id and a start and end date. It will create a record with each effective date along with its value. It would be up to the client to ignore seasonal/timeseries levels. I could see an update that restructures the LocationLevels DTO to group all levels with the same id to remove redundant data.