A script example: calculating issue time in each state

Discuss problems installing or using TrackStudio.

A script example: calculating issue time in each state

Postby admin » Fri Nov 03, 2006 1:42 pm

Use this script to create a calculated custom field. All times are in milliseconds.

Code: Select all
        HashMap states = new HashMap();

        ArrayList statusList = AdapterManager.getInstance().getSecuredWorkflowAdapterManager().getStatusList(sc, task.getWorkflowId());

        SecuredStatusBean initial = null;
        for (Iterator it = statusList.iterator(); it.hasNext();){
            SecuredStatusBean status = (SecuredStatusBean)it.next();
            if (status.isStart()) initial = status;
            states.put (status.getName(), new Long(0)); // in milliseconds

        List messages =  task.getMessages();
        if (messages==null || messages.isEmpty()){
            states.put(initial.getName(), new Long(((Long)states.get(initial.getName())).longValue()+(new java.util.Date().getTime() - task.getSubmitdate().getTimeInMillis())));
        }  else {
            SecuredStatusBean current = initial;
            long currentTime = task.getSubmitdate().getTimeInMillis();
for(ListIterator it = messages.listIterator(messages.size()); it.hasPrevious();) {
    SecuredMessageBean msg = (SecuredMessageBean)it.previous();
    ArrayList transitionsList = AdapterManager.getInstance().getSecuredWorkflowAdapterManager().getTransitionList(sc, msg.getMstatusId());
    for (Iterator t = transitionsList.iterator(); t.hasNext();){
        SecuredTransitionBean tr = (SecuredTransitionBean)t.next();
        if (tr.getStart().equals(current)){
            // that's it!
            states.put(current.getName(), new Long(((Long)states.get(current.getName())).longValue()+(msg.getTime().getTimeInMillis() - currentTime)));
            current = tr.getFinish();
            currentTime  = msg.getTime().getTimeInMillis();
            states.put(current.getName(), new Long(((Long)states.get(current.getName())).longValue()+(new java.util.Date().getTime()- currentTime)));
        return states.toString();
Maxim Kramarenko (mailto: maximkr@trackstudio.com)
TrackStudio - Hierarchical Bug & Issue Tracking Software
Site Admin
Posts: 8148
Joined: Thu Jan 01, 1970 3:00 am
Location: Smolensk, Russia

Return to TrackStudio Support

Who is online

Users browsing this forum: Google [Bot] and 12 guests