MVC - Bindings to create SAQL queries in a step

This post is to detail a strategy for Analytics Cloud Dashboards that allow the maximum information to be shared in an efficient space framework as possible.

This post started near on Two Years Ago :) When we needed to figure out how to have 5 widgets on a page but change groupings and measures across the whole dashboard on the fly... I now see that a large of this has been added into the Bindings 2.0 Document which is great news... it is acataully a hard model to share with users who need to continue to support once a dashboard has been handed over. This idea of me writing this blog was to get it out of drafts list which it has been since for a while now.

Again the idea here is that depending on what we are wanting to understand on the dashboard , we can change all of the data , widgets and how they are individually displayed on demand.

The simplest form of this is to say that you want to press a simple button ( Static Step and adjust all of the widgets on the screen to the new measure and to take things a little further we would like a static data range step where we pass through relative dates, but we also want to adjust the grouping when we display in the widgets a week vs a quarter. i.e. we would like when we show “Last Week” we want to group a time series graph by day and when we show quarter we would like to show by week.

To do this we created this idea of MVC - Model View Controller in our code. When we think of a normal step we see a SAQL Query that looks something like this:

but what if we wanted to set an number of steps and bind them in at the SAQL / Pigql level.. we would end up something that looks a little like this:

If you look at the code snippet above, you can see that we are actually binding Date , the initial projection and the measure. This is super cool….. this allows just do adjust on demand the grouping, and each part of the projections. As you can see here we are building a controller. The idea here is that we now build out a number of other steps that include the groupings and projections that we would like to pass through into the parent step.

We are going to build a dashboard to show all aspects of this… the idea here is that we want to do a couple of things.

  1. Have a static Date step, where we change the grouping on a time series graph based on which date range is selected.
  2. Pass through different measures via a static step
  3. control multiple graphs with different measures

The first thing to share is what we call the AllMetricStep as you can see it is broken down into different selection bindings so that we can pull from a variety of steps the complete SAQL query to produce the end result. In the example below..You can see we are pulling the grouping from the step_relative_date step and the following projection from both the step_relative_date and StaticMetricStep steps. This is because we want to adjust the grouping of the Timeseries dependent on which of the Date buttons we choose on the step_relative_date step and then want to adjust the measure via the StaticMetricStep step.

Next we have the Static Metric Step, the idea on this step is to be able to control the Compact form and SAQL measures across multiple graphs. As you can see we have different value breakdowns for values in which we want to pass through when either measure is pressed on the Static_Metric_Step pillbox button as per the image above.

We now have the Data_Selection_Step . There are a couple of things we are doing as part of this step:

  1. Using the button to control the relative dates of other Steps i.e a filter ( not in code )
  2. provide both a SAQL and a Compact version to allow different steps to filter on appropriate information
  3. Provide a Date grouping for the SAQL query in the AllMetricStep
  4. Provide a Date grouping for the compact form
  5. Provide the Date specific projection as part of the overall SAQL query in the AllMetricStep.

There is a lot going on in this step... as you can see it is providing a large amount of code for the end step of the AllMetricStep. The idea here again is that we want each step on the page to look differently because we select a specific date range. Again we want:

  1. When we press Month and below... dates to be grouped on the timeseries in days
  2. When we are a month and above we want the dates to be grouped by month in the timeseries.

This is just an example of using multiple values to pass through to a Step - This was something that needed to be proved.

Below is the whole dashboard - Here you can see each of steps and how they create the output for the timeseries AllMetricStep.

The key thing here.. is allowing us to completely change how the dashboard works / looks when we change certain aspects. For example we could change when we change the measure for the dashboard the groupings and widget type because we now have this ability in Bindings 2.0 to place bindings anywhere.