Skip to content

Add a first-class way to fetch observations over HTTP #54

Description

@tipatterson-dev

There's no direct way to read observations from a datastream over HTTP.

Writing one is first-class:

datastream.insert_observation_dict({...})

Reading them back is not — you go through the API helper and name the resource types yourself, and get a raw requests.Response:

node.get_api_helper().get_resource(
    APIResourceTypes.DATASTREAM, datastream.get_id(),
    APIResourceTypes.OBSERVATION, params={"limit": 5},
)

The alternative, api_helpers.list_observations_from_datastream(), makes you re-supply the server URL and credentials the Node already holds, and accepts no query parameters.

Proposal

Add Datastream.get_observations(), mirroring insert_observation_dict:

observations = datastream.get_observations(limit=5)
observations = datastream.get_observations(result_time="latest")

It would use the parent node's configured credentials, take the common CS API query params (limit, resultTime, phenomenonTime) as keyword arguments, and run results through the datastream's cached record schema via decode_observation so the binary wire formats work the same as JSON.

StreamableResource already declares poll() and fetch(time_period) as no-op stubs (resources/base.py), so fetch() could be implemented on top of this.

Open questions

  • Return plain dicts, or parsed ObservationResource models?
  • Follow the links-based pagination, or return just the first page?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions