X days ago, we post How to calculate “Lead Time” or “Real Average Resolution Days” with eazyBI and JIRA

Now it’s turn to do the same, or similar, with Javascript fields in eazyBI and JIRA.

First of all we need to configure (or your JIRA Admin) the eazyBI settings to add three new Javascript customfields.

We must put something like this:


[jira.customfield_start_date]
name = "Start endpoint date"
data_type = "date"
measure = true

[jira.customfield_end_date]
name = "End endpoint date"
data_type = "date"
measure = true

[jira.customfield_leadtime]
name = "lead time"
data_type = "decimal"
measure = true

Captura de pantalla 2017-11-04 a las 17.41.37

Once updated the settings of eazyBI...

Then in the Cube import options we can set a javascript like this to make the calculation of the time between two statuses in a X time (for example in the first date of the end status). We can obtain the values from the Changelog of the issue. And, as extra, we can discount the weekends to the final measure to be more accurate.

try {
    var MILLISECONDS_IN_A_DAY = 86400000;

    // Clean changelog
    var his = issue.changelog.histories.map(function(history) {
      history.items = history.items.filter(function(item) {
        return item.field === 'status';
      });
      return history;
    }).filter(function(history) {
      return history.items.length > 0;
    }).reverse();

    var status_changed_to = function(statuses) {
      var filtered_change_log = his.filter(function(history) {
        return history.items.some(function(item) {
            return item.field === 'status' && item.fromString !== item.toString && statuses.indexOf(item.toString) > -1;
        });
      });
      return filtered_change_log.length == 0 ? null : new Date(Date.parse(filtered_change_log[0].created));
    };

    issue.fields.customfield_start_date = status_changed_to(['In Progress']);
    issue.fields.customfield_end_date = status_changed_to(['Resolved','Closed']);

    if (issue.fields.customfield_end_date && issue.fields.customfield_start_date ) {
      issue.fields.customfield_leadtime = ((issue.fields.customfield_end_date.getTime() - issue.fields.customfield_start_date.getTime()) / MILLISECONDS_IN_A_DAY) - getWeekendsDays(new Date(issue.fields.customfield_start_date),new Date(issue.fields.customfield_end_date))
    } else  {
      //issue.fields.customfield_start_date = issue.fields.customfield_end_date;
      issue.fields.customfield_leadtime = 0;
    }  

} catch(err) {
  throw issue.key + " (" + err + ")";
}

 function getWeekendsDays(startDate, endDate){
    var result = 0;

    var currentDate = startDate;
    while (currentDate <= endDate)  {  

        var weekDay = currentDate.getDay();
        if(weekDay == 0 || weekDay == 6)
            result++;

         currentDate.setDate(currentDate.getDate()+1);
    }

    return result;
 }

Captura de pantalla 2017-11-04 a las 17.19.25

Once inserted the code, we can test with a known issue and see the values obtained in the three new javascript customfield.

Captura de pantalla 2017-11-04 a las 17.36.56

Then don’t forgive to check the three new customfields to obtain the data and see the results in the reports.

Captura de pantalla 2017-11-04 a las 17.44.19

Captura de pantalla 2017-11-04 a las 17.44.33

Captura de pantalla 2017-11-04 a las 17.45.51

Now, we can Save and Start the import!

Creating the report, you will see new properties in Measures Dimension, like “Issue End endpoint date” and “Issue Start endpoint date”

Captura de pantalla 2017-11-04 a las 18.28.42

And we can create also a Calculated Measure to get the average real lead time.

[Measures].[Super Lead Time] =[Measures].[lead time with end endpoint date]/[Measures].[Issues with end endpoint date]

Captura de pantalla 2017-11-04 a las 18.28.56

And now, we can see the results!

Captura de pantalla 2017-11-04 a las 18.30.00

Once the project is expanded… we can see the lead time with the dates.

Captura de pantalla 2017-11-04 a las 18.30.21

Thanks for reading this and have a nice Lead time report day!

Captura de pantalla 2017-11-04 a las 18.34.00

If you need more info about eazyBI javascript fields, see this link.

Posted by:.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s