The CreatorCon Call for Content is officially open! Get started here.

Average time to respond: Average function on the Automated Indicator returns weird metrics.

Waldo Lavaut1
Tera Contributor

If we want to measure 'Average time to Respond' from the user's perspective, we should follow a 24-hour schedule, right? (real-time).

There are a few tasks that to my understanding need to be done to achieve this:

1. First, create a new Metric to measure the time difference between incident opened - incident assigned (assigned to specifically).

Here's the script that I took from an SN Performance Analytics book (authored by SN):

if (current.assigned_to != "") {
    createMetric();
}

function createMetric() {
    var mi = new MetricInstance(definition, current);

    if (mi.metricExists()) return;

    var gr = mi.getNewRecord();

    gr.start = current.sys_created_on;
    gr.end = current.sys_updated_on;
	
// 	gr.duration will calculate the time difference between incident creation and incident assigned to
    gr.duration = gs.dateDiff(
        gr.start.getDisplayValue(),
        gr.end.getDisplayValue()
    );
    gr.calculation_complete = true;
    gr.insert();
}

 

2. Once we have this in production and we are collecting data, we can use the mi_duration property of that metric to report on it, right? 

So now we're left with the problem I have:

3. Create an automated Indicator to calculate the Average of all those metrics collected. This is what I did for the Automated Indicator: 

find_real_file.png

 

 

What I noticed after collecting the data is that if I select Hours or Days for the Unit, that's what it will show on the Analytics Hub. Which doesn't make sense to me. 

find_real_file.png

 

So my fear is that the Aggregate Average function on the Automated Indicator is NOT doing a real average calculation. 

 

find_real_file.png

 

The Metric I created initially on step 1 above is collecting UTC strings, so: 

 

- Do I need to convert those UTC strings to milliseconds to be able to calculate a real Average?

- Do I need to create two different automated indicators (count + sum) and then a formula indicator to achieve this?

- If so, how do I do a count and a sum when working with time? Can i sum or count milliseconds to get an average?

 

@Adam Stout , @Thomas Davis , @Slawek.Radziewicz , @Arnoud Kooi , @Ankur Bawiskar HELP PLEASE!

1 ACCEPTED SOLUTION

You need to convert to hours in order to Average Hours or days to Average Days. 

In dateDiff flag TRUE returns seconds and then we calculate hours and save it to record. 

 

start  = new GlideDateTime(gr.sys_created_on);
closed = new GlideDateTime(gr.closed_at);

dur_sec = gs.dateDiff(start, closed,true)
var dur_hours = Math.round(dur_sec / 3600);
  
}

View solution in original post

8 REPLIES 8

If I run the following script on Background Scripts, to check what the Metric I created returns I get this: 

Which looks like a UTC string. So I believe that the metric script is saving UTC strings: 

1- partial script of the Metric script

find_real_file.png

 

Script in Background Scripts that I created to see what does the Metric script is saving to the DB

var gr = new GlideRecord("incident_metric");

gr.addEncodedQuery("mi_definition=009401bb1b59c150684eea4cbc4bcb30");

gr.setLimit(10);

gr.query();

 

var count = 0;

 

while (gr.next()) {

  gs.log("records are: " + gr.getValue("mi_duration"));

  count += gr.getValue("mi_duration");

}

 

gs.log("Total duration is " + count);

 

3 - What the script returns:

 

 

find_real_file.png

So based on this, do I convert those UTC strings into milliseconds to get a real average?

You need to convert to hours in order to Average Hours or days to Average Days. 

In dateDiff flag TRUE returns seconds and then we calculate hours and save it to record. 

 

start  = new GlideDateTime(gr.sys_created_on);
closed = new GlideDateTime(gr.closed_at);

dur_sec = gs.dateDiff(start, closed,true)
var dur_hours = Math.round(dur_sec / 3600);
  
}

Ok, wonderful thanks. My last two questions are: 

1- Modifying the Metric script to obtain hours or days will only count for future collection metrics, what do I do with previously collected metrics? 

Is there a script that allows me to change those UTC strings to Hours or Days for the previous records?

2- Once I'll have Hours or Days collected moving forward for the metric. Will the Average function for the Automated Indicator be accurate? Or do you recommend that I create two different indicators? One for summed dates and another for count dates? Is it possible to do sum and count when working with Dates?

 

find_real_file.png

@Slawek.Radziewicz I'd appreciate if you could give me this last piece of advice. See above my last 2 questions. Thank you so much!