Skip to main content
summaryrefslogtreecommitdiffstats
blob: ebc9a7a0f11a70d77b4ad27c42b370610eefc791 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Copyright (c) 2012 Robert Bosch Engineering and Business Solutions Ltd India. All rights reserved. This program and
 * the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.eclipse.osee.ats.reports.burndown.issues;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.eclipse.osee.ats.core.client.workflow.AbstractWorkflowArtifact;
import org.eclipse.osee.framework.core.exception.OseeCoreException;

/**
 * This class is used to compute the details wrt.the issue burndown.
 * 
 * @author Praveen Joseph
 */
public class IssueBurndownLog {

   private Date startDate;
   private Date endDate;
   private List<AbstractWorkflowArtifact> artifacts;
   private int totalIssues;
   private double avgIdeal;

   private final List<IssueBurndownEntry> entries;

   /**
    * Constructor to initialise list of Work flow artifacts and Log entries
    */
   public IssueBurndownLog() {
      this.artifacts = new ArrayList<AbstractWorkflowArtifact>();
      this.entries = new ArrayList<IssueBurndownEntry>();
   }

   /**
    * @param artifacts sets the workflow artifacts
    */
   public void setArtifacts(final List<AbstractWorkflowArtifact> artifacts) {
      this.artifacts = artifacts;
   }

   /**
    * @param endDate sets the end date
    */
   public void setEndDate(final Date endDate) {
      this.endDate = endDate;
   }

   /**
    * @param startDate sets the start date
    */
   public void setStartDate(final Date startDate) {
      this.startDate = startDate;
   }

   /**
    * @param totalIssues sets the total issues
    */
   public void setTotalIssues(final int totalIssues) {
      this.totalIssues = totalIssues;
   }

   /**
    * @return the list of workflow atrifacts
    */
   public List<AbstractWorkflowArtifact> getArtifacts() {
      return this.artifacts;
   }

   /**
    * @return the end date
    */
   public Date getEndDate() {
      return this.endDate;
   }

   /**
    * @return the start date
    */
   public Date getStartDate() {
      return this.startDate;
   }

   /**
    * @return the total issues
    */
   public int getTotalIssues() {
      return this.totalIssues;
   }

   /**
    * @param avgIdeal : sets the average ideal value
    */
   public void setAvgIdeal(final double avgIdeal) {
      this.avgIdeal = avgIdeal;
   }

   /**
    * @return the average ideal value
    */
   public double getAvgIdeal() {
      return this.avgIdeal;
   }

   /**
    * @return the issues list
    */
   public List<IssueBurndownEntry> getEntries() {
      return this.entries;
   }

   /**
    * Method to compute total work done and issue entries
    * 
    * @throws OseeCoreException :
    */
   public void compute() throws OseeCoreException {
      this.totalIssues = computeTotalIssues();
      long days = (this.endDate.getTime() - this.startDate.getTime()) / (1000 * 60 * 60 * 24);
      final double idealAvg = (double) this.totalIssues / days;

      // Day-wise work log
      Date inspectDate = this.startDate;
      int remainingIssues = this.totalIssues;
      double idealRemainingIssues = this.totalIssues;

      // Create 0th entry
      IssueBurndownEntry zeroeth = new IssueBurndownEntry(inspectDate);
      zeroeth.setIssuesClosed(0);
      zeroeth.setIssuesRemaining(remainingIssues);
      zeroeth.setBurndownRate(0);
      zeroeth.setIdealIssuesRemaining(idealRemainingIssues);
      this.entries.add(zeroeth);

      inspectDate = incrementDate(inspectDate, 1);

      while (!inspectDate.after(this.endDate)) {
         int totalIssuesClosed = computeTotalIssues(inspectDate);
         remainingIssues = remainingIssues - totalIssuesClosed;
         idealRemainingIssues -= idealAvg;
         double burndown = (double) remainingIssues / days--;
         IssueBurndownEntry entry = new IssueBurndownEntry(inspectDate);
         entry.setIssuesClosed(totalIssuesClosed);
         entry.setIssuesRemaining(remainingIssues);
         entry.setIdealIssuesRemaining(idealRemainingIssues);
         entry.setBurndownRate(burndown);
         this.entries.add(entry);
         // increment
         inspectDate = incrementDate(inspectDate, 1);

      }

   }

   @SuppressWarnings("static-access")
   private Date incrementDate(final Date inspectDate, final int i) {
      // IncrementDate
      Calendar cal = Calendar.getInstance();
      cal.setTime(inspectDate);
      cal.add(cal.DATE, i);
      Date newDate = cal.getTime();
      return newDate;
   }

   private int computeTotalIssues() {
      return this.artifacts.size();
   }

   /**
    * This method returns the number of issues that were completed on a given date.
    */
   @SuppressWarnings("deprecation")
   private int computeTotalIssues(final Date currentDate) throws OseeCoreException {
      int issues = 0;
      for (AbstractWorkflowArtifact artifact : this.artifacts) {
         if (artifact.isCompleted()) {
            Date itemDate = artifact.getCompletedDate();
            if ((itemDate.getDate() == currentDate.getDate()) && (itemDate.getMonth() == currentDate.getMonth()) && (itemDate.getYear() == currentDate.getYear())) {
               issues++;
            }

         }
      }
      return issues;
   }

}

Back to the top