1 19 20 package za.org.coefficient.statistics.data; 21 22 import java.util.Calendar ; 23 import java.util.Date ; 24 import java.util.GregorianCalendar ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 28 32 public class ModuleStatistics implements java.io.Serializable { 33 35 private Date statsDate; 36 private Long id; 37 private Long projectId; 38 private String name; 39 private ModuleStatisticsData currentData; 40 private Map archive; 41 42 44 public ModuleStatistics() { 45 currentData = new ModuleStatisticsData(); 46 archive = new HashMap (); 47 } 48 49 51 public boolean archiveStats() { 52 boolean retVal = false; 53 Calendar c1 = new GregorianCalendar (); 54 c1.setTime(this.statsDate); 55 Calendar c2 = new GregorianCalendar (); 56 if (c1.get(Calendar.DAY_OF_YEAR) < c2.get(Calendar.DAY_OF_YEAR)) { 57 retVal = true; 58 this.archive.put(ProjectStatistics.DATE_FORMAT.format(statsDate), 60 currentData); 61 62 ModuleStatisticsData newData = new ModuleStatisticsData(); 63 newData.setCarryOverCreateCount(currentData.getCarryOverCreateCount() 64 + currentData.getCreateCount()); 65 newData.setCarryOverUpdateCount(currentData.getCarryOverUpdateCount() 66 + currentData.getUpdateCount()); 67 newData.setCarryOverCompleteCount(currentData.getCarryOverCompleteCount() 68 + currentData.getCompleteCount()); 69 currentData = newData; 70 statsDate = new Date (System.currentTimeMillis()); 71 } 72 return retVal; 73 } 74 75 80 public void setId(Long argId) { 81 this.id = argId; 82 } 83 84 91 public Long getId() { 92 return this.id; 93 } 94 95 100 public void setName(String name) { 101 this.name = name; 102 } 103 104 111 public String getName() { 112 return this.name; 113 } 114 115 120 public void setProjectId(Long argProjectId) { 121 this.projectId = argProjectId; 122 } 123 124 131 public Long getProjectId() { 132 return this.projectId; 133 } 134 135 140 public void setStatsDate(Date argStatsDate) { 141 this.statsDate = argStatsDate; 142 } 143 144 151 public Date getStatsDate() { 152 return this.statsDate; 153 } 154 155 156 165 public ModuleStatisticsData getCurrentData() { 166 return this.currentData; 167 } 168 169 174 public void setCurrentData(ModuleStatisticsData argCurrentData) { 175 this.currentData = argCurrentData; 176 } 177 178 194 public Map getArchive() { 195 return this.archive; 196 } 197 198 203 public void setArchive(Map argArchive) { 204 this.archive = argArchive; 205 } 206 207 208 public long calculateStats() { 209 long retVal = 0; 210 211 retVal = 213 currentData.getCarryOverCompleteCount() + currentData.getCompleteCount() 214 + currentData.getCarryOverCreateCount() + currentData.getCreateCount() 215 + currentData.getCarryOverUpdateCount() + currentData.getUpdateCount(); 216 217 return retVal; 218 } 219 220 233 public Map getActivityForNumberOfDaysIncludingToday(int days, String type) { 234 HashMap activity = new HashMap (); 235 Date theDate = statsDate; 236 237 for(int i = 0; i < days; i++) { 238 Long val = null; 239 if("create".equalsIgnoreCase(type)) { 240 val = new Long (getCreateStatsForDate(theDate)); 241 } else if("update".equalsIgnoreCase(type)) { 242 val = new Long (getUpdateStatsForDate(theDate)); 243 } else if("complete".equalsIgnoreCase(type)) { 244 val = new Long (getCompleteStatsForDate(theDate)); 245 } else { 246 throw new IllegalArgumentException ("Type: "+type 247 + " is not a valid type"); 248 } 249 activity.put(theDate, val); 250 theDate = new Date (theDate.getTime() - (1000 * 60 * 60 * 24)); 252 } 253 return activity; 254 } 255 256 264 public long getActivityTotalForNumberOfDaysIncludingToday(int days) { 265 long total = 0; 266 Date theDate = statsDate; 267 268 for(int i = 0; i < days; i++) { 269 total += getStatsTotalForDate(theDate); 270 theDate = new Date (theDate.getTime() - (1000 * 60 * 60 * 24)); 272 } 273 return total; 274 } 275 276 public long getStatsTotalForDate(Date date) { 277 return getCreateStatsForDate(date) + getUpdateStatsForDate(date) + 278 getCompleteStatsForDate(date); 279 } 280 281 public long getCreateStatsForDate(Date date) { 282 long retVal = 0; 283 if(ProjectStatistics.DATE_FORMAT.format(statsDate) 284 .equals(ProjectStatistics.DATE_FORMAT.format(date))) { 285 retVal = currentData.getCreateCount(); 287 } else { 288 ModuleStatisticsData modStatData = 290 (ModuleStatisticsData)archive 291 .get(ProjectStatistics.DATE_FORMAT.format(date)); 292 if(modStatData != null) { 293 retVal = modStatData.getCreateCount(); 294 } 295 } 296 297 return retVal; 298 } 299 300 public long getUpdateStatsForDate(Date date) { 301 long retVal = 0; 302 if(ProjectStatistics.DATE_FORMAT.format(statsDate) 303 .equals(ProjectStatistics.DATE_FORMAT.format(date))) { 304 retVal = currentData.getUpdateCount(); 306 } else { 307 ModuleStatisticsData modStatData = 309 (ModuleStatisticsData)archive 310 .get(ProjectStatistics.DATE_FORMAT.format(date)); 311 if(modStatData != null) { 312 retVal = modStatData.getUpdateCount(); 313 } 314 } 315 316 return retVal; 317 } 318 319 public long getCompleteStatsForDate(Date date) { 320 long retVal = 0; 321 if(ProjectStatistics.DATE_FORMAT.format(statsDate) 322 .equals(ProjectStatistics.DATE_FORMAT.format(date))) { 323 retVal = currentData.getCompleteCount(); 325 } else { 326 ModuleStatisticsData modStatData = 328 (ModuleStatisticsData)archive 329 .get(ProjectStatistics.DATE_FORMAT.format(date)); 330 if(modStatData != null) { 331 retVal = modStatData.getCompleteCount(); 332 } 333 } 334 335 return retVal; 336 } 337 338 public boolean equals(Object other) { 339 ModuleStatistics o = (ModuleStatistics) other; 340 341 return (this != null) && (o != null) 342 && (((id == null) && (o.id == null)) || id.equals(o.id)) 343 && (((projectId == null) && (o.projectId == null)) 344 || projectId.equals(o.projectId)) 345 && (((name == null) && (o.name == null)) || name.equals(o.name)) 346 && (((statsDate == null) && (o.statsDate == null)) 347 || statsDate.equals(o.statsDate)); 348 } 349 } 350 | Popular Tags |