Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted field to calculate average cycle time of a story in a Epic

Sai Praveen Aminigadda June 24, 2020

Hello,

 

I'm looking for a groovy script that can give average cycle time of a story in an epic.

for instance, if an epic has a story and it closed in 2 hrs, the average cycle time will be 2 hrs.

if an epic has two stories and one closed in 1 hr and another one closed in 3 hrs, the average cycle time will be different.

any help would be appreciated.  

Note: we already have two scripted fields one gives the total cycle time of an issue and another one gives the number of issues in an epic.

3 answers

1 vote
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 24, 2020

You should simply merge the two existing scripts into a third:

return (output of number of issues script / output of total cycle change script)

Note that the other option people may think of here is to calculate the third field from the first and second - do not do that, as fields are not always calculated in the order you think they are, so you could end up with the wrong answer.

0 votes
Suji Shyam June 25, 2020

import com.atlassian.jira.ComponentManager is not working ! is there any alternative package for this. since it is deprecated.

Version is V8.5

0 votes
Sai Praveen Aminigadda June 24, 2020

@Nic Brough -Adaptavist-  could you help me to merge these two scripts please.

number of stories: 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor;
def componentManager = ComponentManager.getInstance()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()

double completedSP = 0
enableCache = {-> false}

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->

if (issueLink.issueLinkType.name == "Epic-Story Link") {
completedSP= 1 + completedSP;
}
}
completedSP=completedSP.trunc()
return completedSP

 

Time spent:

import com.atlassian.core.util.DateUtils
def resolvedNames = ["Resolved", "Closed"]
def timeDiff;
if (issue.getStatus().name in resolvedNames) {
timeDiff = issue.getResolutionDate().getTime() - issue.getCreated().getTime()
} else {
timeDiff = System.currentTimeMillis() - issue.getCreated().getTime()
}
return (double) timeDiff/(1000*60*60)

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 24, 2020

Rearrange the imports up to the top.  Remove the line "return completedSP", and change the last line so it divides by completedSP

Sai Praveen Aminigadda June 24, 2020

I tried like this:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.core.util.DateUtils
def componentAccessor = ComponentManager.getInstance()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()

double completedSP = 0
enableCache = {-> false}

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->

if (issueLink.issueLinkType.name == "Epic-Story Link") {
completedSP= 1 + completedSP;
}
}
completedSP=completedSP.trunc()

def resolvedNames = ["Resolved", "Closed"]
def timeDiff;
if (issue.getStatus().name in resolvedNames) {
timeDiff = issue.getResolutionDate().getTime() - issue.getCreated().getTime()
} else {
timeDiff = System.currentTimeMillis() - issue.getCreated().getTime()
}
return (double) timeDiff/(1000*60*60)

 

And i'm getting this error

$jiraDurationUtils.getFormattedDuration($value, $jiraAuthenticationContext.getLocale())

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 25, 2020

You're using the wrong template for the output of the field.  Return (double) should probably be going out through a numeric field.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.13.1
TAGS
AUG Leaders

Atlassian Community Events