Skip to contents

Constructs a sampling rule specification and returns it as a formatted JSON string. This is typically used to define when and how sensors or monitoring systems should collect data based on conditional logic.

Usage

write_rule(
  id = NULL,
  name = NULL,
  comment = NULL,
  disabled = FALSE,
  criterionType = "query_R",
  criterionOptArg = NULL,
  criterion,
  determinants = "ALL",
  samplingFrequency
)

Arguments

id

Optional numeric identifier for the rule.

name

Optional name of the rule (character string).

comment

Optional descriptive comment (character string).

disabled

Logical. If `TRUE`, the rule is inactive. Default is `FALSE`.

criterionType

Character string specifying the rule evaluation type. Default is `"query_R"`.

criterionOptArg

Optional character string providing additional arguments for the criterion evaluation.

criterion

Character string defining the rule condition. Typically an R-style logical expression (e.g. `"(temp > 15) | (pH > 7)"`).

determinants

Either `"ALL"` or a character vector specifying which variables (e.g. sensor names) the rule applies to.

samplingFrequency

Character string specifying the sampling interval in ISO 8601 duration format (e.g. `"PT10M"` for 10 minutes, `"P1D"` for 1 day).

Value

A formatted JSON string representing the sampling rule, with key-value pairs corresponding to the input arguments.

Details

The `criterion` defines the condition under which the sampling rule is triggered. It is evaluated according to the specified `criterionType` (default `"query_R"`).

The `samplingFrequency` must follow ISO 8601 duration conventions. For example:

  • `"PT1H"` = 1 hour

  • `"PT30M"` = 30 minutes

  • `"P1D"` = 1 day

  • `"P1M"` = 1 month

This function does not validate the correctness of the logical expression or duration format; users should ensure inputs are valid for the target system.

See also

Examples

# Define a sampling rule triggered by temperature or pH
query <- "(Sonde1_Temperature > 15) | (Sonde1_pH > 7)"

json_rule <- write_rule(
  id = 1,
  name = "High variability sampling",
  criterion = query,
  determinants = c("Sonde1_Temperature", "Sonde1_pH"),
  samplingFrequency = "PT10M"
)
#> Error in list(id = id, name = name, comment = comment, disabled = disabled,     criterionType = criterionType, criterionOptArg = criterionOptArg,     criterion = criterion, determinants = determinants, samplingFrequency = samplingFrequency) %>%     jsonlite::toJSON(auto_unbox = TRUE) %>% jsonlite::prettify(): could not find function "%>%"

cat(json_rule)
#> Error: object 'json_rule' not found