The Zurich release has arrived! Interested in new features and functionalities? Click here for more

script to determine lead time

kwilson1
Kilo Contributor

Hi Community,

I am VERY novice at creating metrics in PA but getting there so please bear with.   Here is what I need help with.   I need to metric change lead time.   I think I need to create scripts to calculate the time between create date and planned start date of a change record.   I need to then group those times into buckets, 0 days, 1 days, 2 days, 3-7 days, 1-2 weeks, and greater than 2 weeks.   I need to put those in a stacked graph for each month for the last year.

So at the end my graph will show the 6 different lead times stacked by into my total changes for the month over 12 months.   I believe there is some scripting involved.

HELP!!

1 ACCEPTED SOLUTION

Vincent Loffel1
Kilo Guru

Hi Kerry,



The script you are looking for is already delivered out of the box, well at least for the biggest part.


Take a good look at the age days script for changes. As you can see this script detracts the created date from the score end (placeholder for time when job runs) and ruturns the value in days.



So you need to modify this script into something like this:


var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};


var days=function(x,y){return diff(x,y)/(24*60*60*1000);};


days(current.opened_at, start_date)


Make sure you have the planned start date field selected in the Source section of the script!



Than create your buckets with start and end values in days. So 0 days has a start value of 0 and an end value of 1, 1 days has a start value of 1 and an end value of 2, etc.



Then create a breakdown source and select buckets as factstable with a filter applied to select only your custom buckets


Now create a breakdown with the source you just created and in the breakdownmapping select the script you just created.



Cheers,


Vincent


View solution in original post

5 REPLIES 5

Vincent Loffel1
Kilo Guru

Hi Kerry,



The script you are looking for is already delivered out of the box, well at least for the biggest part.


Take a good look at the age days script for changes. As you can see this script detracts the created date from the score end (placeholder for time when job runs) and ruturns the value in days.



So you need to modify this script into something like this:


var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};


var days=function(x,y){return diff(x,y)/(24*60*60*1000);};


days(current.opened_at, start_date)


Make sure you have the planned start date field selected in the Source section of the script!



Than create your buckets with start and end values in days. So 0 days has a start value of 0 and an end value of 1, 1 days has a start value of 1 and an end value of 2, etc.



Then create a breakdown source and select buckets as factstable with a filter applied to select only your custom buckets


Now create a breakdown with the source you just created and in the breakdownmapping select the script you just created.



Cheers,


Vincent


So I chose the fields "created" and "planned start date" in my script and did everything else you suggested.



This is what my script looks like. I know the last line is wrong though. I edited it with the name of the fields but don't think that's correct….



var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};


var days=function(x,y){return diff(x,y)/(246060*1000);};


days(current.created_at, planned_start_date_end)


Hi Keri,



If you use the out of the box field planned start date in your change process. The name of that field is actually "start_date".


If you are not sure what the field name is, just go to an open change. In the form right click on the label of the field planned start date. The context menu should show you the actual field name. Another way to find the filed name is to go to the change table and search for the field.



Also i can see there is a typo on line 2. It should be "24*60*60*1000"



Cheers,


Vincent


thank you so much, once I found out the field names, worked like a charm!!