Use Case: Sending a Sightglass Insight

Aunalytics uses an internal Sightglass Solution to monitor the status of key metrics within Aunsight, one of which is the percentage of jobs that succeed per organization. This metric is stored in a small Atlas Record, which is formatted as a Sightglass Data Source and is updated periodically with new information. This information is, at the same time, published to the Sightglass Solution. You can find a static copy of this dataset here.

One key downside of this approach, however, is that it is passive. An administrator will have new information presented to them whenever they open the solution, but there are no set notifications. However, this can be solved using the Insight mechanism of Sightglass, which can send notifications to mobile devices. The only remaining question is whether an insight should be sent. As a “toy” use case, let us suppose that an administrator wants to know if any of the organizations had a success rate below 90%, and they want to know whenever the information is updated.

Our path, then, is clear: create a Workflow that accesses the Atlas Record, interrogates it using an AuQL Rule, and sends an Insight if any organization has a success rate below 90%. Below is such a Workflow, also linked here. This Workflow can then be keyed to run whenever the data is updated, or these components could be placed in the same Workflow that does the updating.

image

The dataset is small, so it can be downloaded either in the Workflow or the Rule, as both limit the download size to 100 rows. For this example, let us download it in the Workflow.

Once the data has been downloaded, we need to set it as a parameter for the Rule. We can do this using the Set Object Path component, where we set the Record data on the “data” key of an object. We also take this opportunity to set another parameter for the Rule, the threshold of success rates below which we have decided that an administrator should be notified. This is set as the “threshold” key, the value of which we have set to 90, for 90%.

From here, we can move onto the Rule evaluation, but first we must define the Rule to be used. The logic of the rule is fairly straightforward. We take the raw data as a parameter and map the array using a mapper function, extracting the successRate field and checking whether it is above or below the threshold parameter. Then, we assert that this condition is true for all rows. The value of this assertion is returned as the output of the Rule. In AuQL, this logic is written thusly:

function main(threshold = int(90), data = Object()){
  mapped = Util.MapArray(data, Util.Function("mapper"), opts = threshold)
  allAbove = Logic.Every(mapped)
  return(value = allAbove)
}

function mapper(value = Object(), opts = int()){
  successRate = Util.Get(value, "successRate")
  aboveThreshold = Logic.GreaterThanEqual(successRate, opts)
  return(value = aboveThreshold)
}

We can write this Rule in the Webapp, noting the uuid, which we use to fill the “rule” input of the “Evaluate Rule” component back in our Workflow. A copy of this Rule can be found here.

Upon execution of the Workflow, one of two things will happen. In the case that all organizations have a job success rate above 90%, the top branch of the Workflow will be taken, with nothing happening except a passive update to the Workflow status. Otherwise, the bottom branch of the Workflow will be taken, in which case an Insight will be sent to the specified users on a similarly specified Sightglass Solution.