awslabs / iot-app-kit

A development library for creating web applications to visualize industrial data
Apache License 2.0
117 stars 60 forks source link

fix(alarm thresholds): only filter threshold values past the viewport end date #3004

Closed corteggiano closed 1 month ago

corteggiano commented 1 month ago

Overview

Static alarm thresholds were being filtered when a viewport was provided. This change updates the logic to always prioritze static alarm threshold values. Thresholds were being filtered to use anything within viewport.

Changes:

  1. prioritize static thresholds
  2. always create mostRecentBeforeEndValueQueries as long as queryMode !== latest
  3. filter all thresholdData that is after the viewport end

test cases + outcomes

Alarm(s) Viewport Outcome
custom alarm property with a static threshold last 10 minutes static threshold is used
custom alarm property with a static threshold none static threshold is used
demo alarm with ingested threshold last 10 minutes will fetch and use last threshold before end of viewport
demo alarm with ingested threshold none will fetch and use last threshold before end of viewport
custom alarm property with a static threshold value + demo alarm with ingested threshold last 10 minutes will use static value for custom alarm and use last threshold before end of viewport
custom alarm property with a static threshold value + demo alarm with ingested threshold none will use static value for custom alarm and use last threshold before end of viewport

example: fetching custom alarm with defined viewport

"thresholds": [
      {
        "value": {
          "doubleValue": 10
        },
        "timestamp": {
          "timeInSeconds": 1727122118
        }
      }
    ]

example: fetching demo data alarm with defined viewport

"thresholds": [
      {
        "quality": "GOOD",
        "timestamp": {
          "offsetInNanos": 0,
          "timeInSeconds": 1727121673
        },
        "value": {
          "doubleValue": 30
        }
      }
    ]

Legal

This project is available under the Apache 2.0 License.