Class LimitClassificationActor

java.lang.Object
com.framed.core.Service
com.framed.cdss.Actor
com.framed.cdss.actors.LimitClassificationActor

public class LimitClassificationActor extends Actor
A specialized Actor that classifies numeric input values per channel based on a configured, ascending-sorted list of upper bounds.

Classification logic: For each channel, the classifier receives a list of upper bounds:

  channelA → [b0, b1, b2, ..., bN]   // sorted ascending
 
Given an incoming numeric value v, the classifier returns the first index i such that:
 v <= b[i]
 
If no such upper bound exists (i.e., v is greater than all bounds), the classifier returns:
  bounds.size()
 

Example: Suppose the configuration is:

  "SpO2": [90, 93, 96, 100]
 
Then:
  • v = 89 → index = 0 (89 ≤ 90)
  • v = 92 → index = 1 (92 ≤ 93)
  • v = 95 → index = 2 (95 ≤ 96)
  • v = 100 → index = 3 (100 ≤ 100)
  • v = 150 → index = 4 (no bound reached → size = 4)

The result is therefore a discrete "classification bin" for each channel.

Input: The actor listens to a set of input channels and expects incoming snapshots in fireFunction(Map) where each channel maps to a numeric value (any Number subtype is accepted).

Output: For each input event, the actor publishes a result message containing:

  • timestamp: ISO timestamp
  • value: the computed classification index
  • className: this classifier's ID
  • channelID: the output channel used

Limits configuration: Provided as a JSON object of the form:

 {
   "channel1": [10, 20, 30],
   "channel2": [5, 7, 9, 12],
   ...
 }
 
All lists are required to be numeric and are automatically sorted ascending.

Constraints:

  • Limited channels must be a subset of the input channels.
  • Each value in the snapshot must be numeric.
  • Missing channel values will result in an exception.

This class generalizes a "limits classifier" into multiple dynamically sized classification bins instead of fixed lower/upper bounds.

  • Constructor Details

    • LimitClassificationActor

      public LimitClassificationActor(EventBus eventBus, String id, org.json.JSONArray firingRules, org.json.JSONArray inputChannels, org.json.JSONArray outputChannels, org.json.JSONObject limits)
      Constructs a LimitClassifier.
      Parameters:
      eventBus - the event bus used for input and output messaging
      id - the identifier for this classifier
      firingRules - firing rules forwarded to Actor
      inputChannels - JSON array of input channel names
      outputChannels - JSON array of output channel names
      limits - a JSON object describing upper-bound lists per channel

      Format of limitsJson:

       {
         "channelA": [limit0, limit1, limit2, ...],
         "channelB": [...],
         ...
       }
       

      The lists must contain numeric values. They will be sorted ascending.

      Throws:
      IllegalArgumentException - if limit channels are not a subset of input channels
  • Method Details

    • checkLimits

      public Map<String,Integer> checkLimits(Map<String,Object> snapshot)
      Classifies each channel's input value using its configured list of ascending upper bounds.

      For each channel, given:

       bounds = [b0, b1, b2, ..., bN]  // sorted ascending
       value = v
       
      the returned index is the first i such that:
       v <= b[i]
       
      If v exceeds all bounds, the result is:
       bounds.size()
       
      Parameters:
      snapshot - a map channel → numeric value (must contain all required channels)
      Returns:
      a map channel → classification index
      Throws:
      IllegalStateException - if snapshot is null or missing a required channel
      ClassCastException - if a snapshot value is not numeric
    • fireFunction

      public void fireFunction(Map<String,Object> latestSnapshot)
      Receives a snapshot from the runtime, classifies all channel values via checkLimits(Map), and publishes one result message per output channel.

      The output message contains:

      • timestamp: ISO-8601 timestamp
      • value: classification index computed by checkLimits(Map)
      • className: this classifier's ID
      • channelID: the output channel the message is published to
      Specified by:
      fireFunction in class Actor
      Parameters:
      latestSnapshot - a map channel → numeric value