Skip to main content
summaryrefslogtreecommitdiffstats
blob: ab5744125a1983e36202a809f6dcf75108097f95 (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
/*
 * 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.reports.efficiency.team;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.osee.ats.api.version.IAtsVersion;
import org.eclipse.osee.ats.core.client.config.VersionsClient;
import org.eclipse.osee.ats.core.client.team.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.core.client.workflow.HoursSpentUtil;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.reports.efficiency.Activator;


/**
 * Class to collect the list of artifacts and compute work done
 * 
 * @author Praveen Joseph
 */
public class VersionEfficiency {

	 private final IAtsVersion version;
	 private final Map<String, Double> efficiency;
  /**
   * Constructor to set the version
   * 
   * @param version :
   */
  public VersionEfficiency(final IAtsVersion version) {
	    this.version = version;
	    this.efficiency = new HashMap<String, Double>();
	  }

  /**
   * Method to collect the list of artifacts and compute work done
   * 
   * @throws OseeCoreException :
   */
  public void compute() throws OseeCoreException {
	    final Map<String, List<TeamWorkFlowArtifact>> teams = new HashMap<String, List<TeamWorkFlowArtifact>>();

	    // 1. For each team, collect the list of artifacts.
	    for (TeamWorkFlowArtifact teamWorkflow : VersionsClient.getTargetedForTeamWorkflows(this.version)) {
	      if (teams.containsKey(teamWorkflow.getTeamName())) {
	        teams.get(teamWorkflow.getTeamName()).add(teamWorkflow);
	      }
	      else {
	        List<TeamWorkFlowArtifact> team = new ArrayList<TeamWorkFlowArtifact>();
	        team.add(teamWorkflow);
	        teams.put(teamWorkflow.getTeamName(), team);
	      }
	    }
	    // 2. compute work done
	    Iterator<String> teamNames = teams.keySet().iterator();
	    while (teamNames.hasNext()) {
	      String teamName = teamNames.next();
	      double estimated = 0;
	      double actual = 0;
	      for (TeamWorkFlowArtifact twa : teams.get(teamName)) {
	        estimated += twa.getEstimatedHoursTotal();
	        actual += HoursSpentUtil.getHoursSpentTotal(twa);
	      }
	      if (actual != 0) {
	        this.efficiency.put(teamName, estimated / actual);
	      }
	      else {
	        Activator.getDefault().getLog()
	            .log(new Status(IStatus.INFO, Activator.PLUGIN_ID, "Actual hours spent by team : " + teamName + " was 0"));
	      }
	    }

	  }

  /**
   * @return the map
   */
  public Map<String, Double> getEfficiency() {
    return this.efficiency;
  }

  /**
   * @return the version artifact
   */
  public IAtsVersion getVersion() {
    return this.version;
  }
}

Back to the top