{
  "name": "Timeseries Aggregator",
  "status": "experimental",
  "shortId": "timeseriesaggregator",
  "camelName": "timeseriesAggregator",
  "shortName": "timeseriesAggregator",
  "extends": [
    "_base"
  ],
  "notes": {
    "short": "Supports aggregating timeseries data (especially sensor readings)\nand sending them to a cloud/storage service.\nUsed in DeviceScript.\n\nNote that `f64` values are not necessarily aligned."
  },
  "classIdentifier": 294829516,
  "enums": {},
  "constants": {},
  "packets": [
    {
      "kind": "report",
      "name": "command_not_implemented",
      "identifier": 3,
      "description": "This report may be emitted by a server in response to a command (action or register operation)\nthat it does not understand.\nThe `service_command` and `packet_crc` fields are copied from the command packet that was unhandled.\nNote that it's possible to get an ACK, followed by such an error report.",
      "fields": [
        {
          "name": "service_command",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "packet_crc",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "identifierName": "command_not_implemented",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "const",
      "name": "instance_name",
      "identifier": 265,
      "description": "A friendly name that describes the role of this service instance in the device.\nIt often corresponds to what's printed on the device:\nfor example, `A` for button A, or `S0` for servo channel 0.\nWords like `left` should be avoided because of localization issues (unless they are printed on the device).",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "optional": true,
      "identifierName": "instance_name",
      "packFormat": "s",
      "derived": "_base"
    },
    {
      "kind": "ro",
      "name": "status_code",
      "identifier": 259,
      "description": "Reports the current state or error status of the device. ``code`` is a standardized value from \nthe Jacdac status/error codes. ``vendor_code`` is any vendor specific error code describing the device\nstate. This report is typically not queried, when a device has an error, it will typically\nadd this report in frame along with the announce packet. If a service implements this register,\nit should also support the ``status_code_changed`` event defined below.",
      "fields": [
        {
          "name": "code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "vendor_code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "optional": true,
      "identifierName": "status_code",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "rw",
      "name": "client_variant",
      "identifier": 9,
      "description": "An optional register in the format of a URL query string where the client can provide hints how\nthe device twin should be rendered. If the register is not implemented, the client library can simulate the register client side.",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "optional": true,
      "identifierName": "client_variant",
      "packFormat": "s",
      "derived": "_base"
    },
    {
      "kind": "event",
      "name": "status_code_changed",
      "identifier": 4,
      "description": "Notifies that the status code of the service changed.",
      "fields": [
        {
          "name": "code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "vendor_code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "optional": true,
      "identifierName": "status_code_changed",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "command",
      "name": "clear",
      "identifier": 128,
      "description": "Remove all pending timeseries.",
      "fields": []
    },
    {
      "kind": "command",
      "name": "update",
      "identifier": 131,
      "description": "Add a data point to a timeseries.",
      "fields": [
        {
          "name": "value",
          "isFloat": true,
          "type": "f64",
          "storage": 8
        },
        {
          "name": "label",
          "type": "string",
          "storage": 0
        }
      ],
      "packFormat": "f64 s"
    },
    {
      "kind": "command",
      "name": "set_window",
      "identifier": 132,
      "description": "Set aggregation window.\nSetting to `0` will restore default.",
      "fields": [
        {
          "name": "duration",
          "unit": "ms",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        },
        {
          "name": "label",
          "type": "string",
          "storage": 0
        }
      ],
      "packFormat": "u32 s"
    },
    {
      "kind": "command",
      "name": "set_upload",
      "identifier": 133,
      "description": "Set whether or not the timeseries will be uploaded to the cloud.\nThe `stored` reports are generated regardless.",
      "fields": [
        {
          "name": "upload",
          "type": "bool",
          "storage": 1
        },
        {
          "name": "label",
          "type": "string",
          "storage": 0
        }
      ],
      "packFormat": "u8 s"
    },
    {
      "kind": "report",
      "name": "stored",
      "identifier": 144,
      "description": "Indicates that the average, minimum and maximum value of a given\ntimeseries are as indicated.\nIt also says how many samples were collected, and the collection period.\nTimestamps are given using device's internal clock, which will wrap around.\nTypically, `end_time` can be assumed to be \"now\".\n`end_time - start_time == window`",
      "fields": [
        {
          "name": "num_samples",
          "unit": "#",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        },
        {
          "name": "padding",
          "type": "u8[4]",
          "storage": 4
        },
        {
          "name": "avg",
          "isFloat": true,
          "type": "f64",
          "storage": 8
        },
        {
          "name": "min",
          "isFloat": true,
          "type": "f64",
          "storage": 8
        },
        {
          "name": "max",
          "isFloat": true,
          "type": "f64",
          "storage": 8
        },
        {
          "name": "start_time",
          "unit": "ms",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        },
        {
          "name": "end_time",
          "unit": "ms",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        },
        {
          "name": "label",
          "type": "string",
          "storage": 0
        }
      ],
      "packFormat": "u32 b[4] f64 f64 f64 u32 u32 s"
    },
    {
      "kind": "ro",
      "name": "now",
      "identifier": 384,
      "description": "This can queried to establish local time on the device.",
      "fields": [
        {
          "name": "_",
          "unit": "us",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "volatile": true,
      "packFormat": "u32"
    },
    {
      "kind": "rw",
      "name": "fast_start",
      "identifier": 128,
      "description": "When `true`, the windows will be shorter after service reset and gradually extend to requested length.\nThis is ensure valid data is being streamed in program development.",
      "fields": [
        {
          "name": "_",
          "type": "bool",
          "storage": 1,
          "defaultValue": 1
        }
      ],
      "packFormat": "u8"
    },
    {
      "kind": "rw",
      "name": "default_window",
      "identifier": 129,
      "description": "Window for timeseries for which `set_window` was never called.\nNote that windows returned initially may be shorter if `fast_start` is enabled.",
      "fields": [
        {
          "name": "_",
          "unit": "ms",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true,
          "defaultValue": 60000
        }
      ],
      "packFormat": "u32"
    },
    {
      "kind": "rw",
      "name": "default_upload",
      "identifier": 130,
      "description": "Whether labelled timeseries for which `set_upload` was never called should be automatically uploaded.",
      "fields": [
        {
          "name": "_",
          "type": "bool",
          "storage": 1,
          "defaultValue": 1
        }
      ],
      "packFormat": "u8"
    },
    {
      "kind": "rw",
      "name": "upload_unlabelled",
      "identifier": 131,
      "description": "Whether automatically created timeseries not bound in role manager should be uploaded.",
      "fields": [
        {
          "name": "_",
          "type": "bool",
          "storage": 1,
          "defaultValue": 1
        }
      ],
      "packFormat": "u8"
    },
    {
      "kind": "rw",
      "name": "sensor_watchdog_period",
      "identifier": 132,
      "description": "If no data is received from any sensor within given period, the device is rebooted.\nSet to `0` to disable (default).\nUpdating user-provided timeseries does not reset the watchdog.",
      "fields": [
        {
          "name": "_",
          "unit": "ms",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "packFormat": "u32"
    }
  ],
  "tags": [
    "infrastructure",
    "devicescript"
  ],
  "group": "Iot",
  "restricted": true
}