001: package salomeTMF_plug.requirements.data;
002:
003: import java.io.File;
004: import java.io.IOException;
005: import java.util.Enumeration;
006: import java.util.Hashtable;
007: import java.util.Vector;
008:
009: import org.jfree.chart.ChartFactory;
010: import org.jfree.chart.ChartUtilities;
011: import org.jfree.chart.JFreeChart;
012: import org.jfree.chart.plot.PiePlot3D;
013: import org.jfree.data.general.DefaultPieDataset;
014: import org.jfree.util.Rotation;
015: import org.objectweb.salome_tmf.api.ApiConstants;
016: import org.objectweb.salome_tmf.data.Campaign;
017: import org.objectweb.salome_tmf.data.ExecutionResult;
018: import org.objectweb.salome_tmf.ihm.languages.Language;
019:
020: import salomeTMF_plug.requirements.sqlWrapper.ReqWrapper;
021: import salomeTMF_plug.requirements.sqlWrapper.SQLWrapper;
022:
023: public class ChartProxy {
024:
025: static public void saveChartAsJPEG(JFreeChart chart, File file) {
026: try {
027: ChartUtilities.saveChartAsJPEG(file, chart, 500, 300);
028: } catch (IOException e) {
029:
030: }
031: }
032:
033: /**
034: * Provide a chart representing a pie of requirements covered by Tests
035: * @param filtre
036: * @return
037: */
038: public static JFreeChart getCoveredReqChart(int filtre) {
039: PiePlot3D plot;
040: DefaultPieDataset dataset;
041: dataset = new DefaultPieDataset();
042: JFreeChart chart = ChartFactory.createPieChart3D(Language
043: .getInstance().getText("Exigence_couverte"), // chart title
044: dataset, // data
045: true, // include legend
046: true, false);
047:
048: plot = (PiePlot3D) chart.getPlot();
049: plot.setStartAngle(290);
050: plot.setDirection(Rotation.CLOCKWISE);
051: plot.setForegroundAlpha(0.5f);
052:
053: try {
054: int nbTotalReq = 1;
055: int nbCoveredReq = 0;
056: if (filtre > 0) {
057: Vector leafInCurrentProject = Requirement
058: .getReqWrapperLeafInCurrentProject();
059: nbTotalReq = leafInCurrentProject.size();
060:
061: Vector reqWrapperCovered = Requirement
062: .getReqWrapperCovered();
063: nbCoveredReq = reqWrapperCovered.size();
064: if (filtre != 111) {
065: int nbTotalReq2 = 0;
066: for (int i = 0; i < nbTotalReq; i++) {
067: int reqP = ((ReqWrapper) leafInCurrentProject
068: .elementAt(i)).getPriority();
069: if ((reqP & filtre) > 0) {
070: nbTotalReq2++;
071: }
072: }
073: int nbCoveredReq2 = 0;
074: for (int i = 0; i < nbCoveredReq; i++) {
075: int reqP = ((ReqWrapper) reqWrapperCovered
076: .elementAt(i)).getPriority();
077: if ((reqP & filtre) > 0) {
078: nbCoveredReq2++;
079: }
080: }
081: nbTotalReq = nbTotalReq2;
082: nbCoveredReq = nbCoveredReq2;
083: }
084: }
085: if (nbTotalReq > 0) {
086: Double nbCovered = new Double((nbCoveredReq * 100)
087: / nbTotalReq);
088: Double nbNotCovered = new Double(100
089: - (nbCoveredReq * 100) / nbTotalReq);
090: dataset.setValue(Language.getInstance().getText(
091: "Exigence_non_couverte"), nbNotCovered);
092: dataset.setValue(Language.getInstance().getText(
093: "Exigence_couverte"), nbCovered);
094: plot.setDataset(dataset);
095: }
096:
097: } catch (Exception e) {
098:
099: }
100:
101: return chart;
102: }
103:
104: /**
105: * Provide a chart representing a pie of requirements covered by a campaing
106: * @param pCamp
107: * @param filtre
108: * @return
109: */
110: public static JFreeChart getCoveredCampChart(Campaign pCamp,
111: int filtre) {
112: PiePlot3D plot;
113: DefaultPieDataset dataset = new DefaultPieDataset();
114: JFreeChart chart = ChartFactory.createPieChart3D(Language
115: .getInstance().getText("Exigence_couverte"), // chart title
116: dataset, // data
117: true, // include legend
118: true, false);
119: plot = (PiePlot3D) chart.getPlot();
120: plot.setStartAngle(290);
121: plot.setDirection(Rotation.CLOCKWISE);
122: plot.setForegroundAlpha(0.5f);
123:
124: Vector reqCoveredWrapper;
125: Vector filtredreqCovered = new Vector();
126: int nbReqTotal = 0;
127: int transNumber = -1;
128: try {
129: transNumber = SQLWrapper.beginTransaction();
130: reqCoveredWrapper = Requirement
131: .getReqWrapperCoveredByCamp(pCamp.getIdBdd());
132: int size = reqCoveredWrapper.size();
133: for (int j = 0; j < size; j++) {
134: ReqWrapper pReqWrapper = (ReqWrapper) reqCoveredWrapper
135: .elementAt(j);
136: if (pReqWrapper.getType() == 1) {
137: if (!filtredreqCovered.contains(pReqWrapper)) {
138: int reqP = pReqWrapper.getPriority();
139: if ((reqP & filtre) > 0) {
140: filtredreqCovered.add(pReqWrapper);
141: }
142: }
143: }
144: }
145: int nbReqCovered = filtredreqCovered.size();
146: try {
147: nbReqTotal = Requirement
148: .getReqWrapperLeafInCurrentProject().size();
149:
150: } catch (Exception e) {
151: nbReqTotal = 0;
152: }
153:
154: dataset = new DefaultPieDataset();
155: if (nbReqTotal > 0) {
156: Double nbCovered = new Double((nbReqCovered * 100)
157: / nbReqTotal);
158: Double nbNotCovered = new Double(100
159: - (nbReqCovered * 100) / nbReqTotal);
160: dataset.setValue(Language.getInstance().getText(
161: "Exigence_non_couverte"), nbNotCovered);
162: dataset.setValue(Language.getInstance().getText(
163: "Exigence_couverte"), nbCovered);
164: }
165: plot.setDataset(dataset);
166:
167: SQLWrapper.commitTrans(transNumber);
168: } catch (Exception e) {
169: try {
170: SQLWrapper.rollBackTrans(transNumber);
171: } catch (Exception e1) {
172: }
173: return null;
174: }
175: return chart;
176: }
177:
178: /**
179: * Provide a chart representing a pie of requirements satisfaction in a execution result
180: * @param executionResult
181: * @param filtre
182: * @return
183: */
184: public static JFreeChart getExecutionResultChart(
185: ExecutionResult executionResult, int filtre) {
186: Hashtable allReq = new Hashtable();
187: PiePlot3D plot;
188: DefaultPieDataset dataset = new DefaultPieDataset();
189: JFreeChart chart = ChartFactory.createPieChart3D(Language
190: .getInstance().getText("Exigence_Pass"), // chart title
191: dataset, // data
192: true, // include legend
193: true, false);
194:
195: plot = (PiePlot3D) chart.getPlot();
196: plot.setStartAngle(290);
197: plot.setDirection(Rotation.CLOCKWISE);
198: plot.setForegroundAlpha(0.5f);
199:
200: try {
201: Vector reqPass = new Vector();
202: Vector reqFail = new Vector();
203: Vector reqInco = new Vector();
204:
205: reqPass = Requirement.getReqWrapperInExecByStatus(
206: executionResult.getIdBdd(), ApiConstants.SUCCESS);
207: reqFail = Requirement.getReqWrapperInExecByStatus(
208: executionResult.getIdBdd(), ApiConstants.FAIL);
209: reqInco = Requirement.getReqWrapperInExecByStatus(
210: executionResult.getIdBdd(), ApiConstants.UNKNOWN);
211: int sizePass = reqPass.size();
212: int sizeFail = reqFail.size();
213: int sizeInco = reqInco.size();
214:
215: allReq.clear();
216:
217: for (int i = 0; i < sizePass; i++) {
218: ReqWrapper pReqWrapper = (ReqWrapper) reqPass
219: .elementAt(i);
220: allReq.put(pReqWrapper, ApiConstants.SUCCESS);
221:
222: }
223: for (int i = 0; i < sizeInco; i++) {
224: ReqWrapper pReqWrapper = (ReqWrapper) reqInco
225: .elementAt(i);
226: allReq.put(pReqWrapper, ApiConstants.UNKNOWN);
227:
228: }
229: for (int i = 0; i < sizeFail; i++) {
230: ReqWrapper pReqWrapper = (ReqWrapper) reqFail
231: .elementAt(i);
232: allReq.put(pReqWrapper, ApiConstants.FAIL);
233: }
234: Enumeration enumReq = allReq.keys();
235: int nbFail = 0;
236: int nbPass = 0;
237: int nbInco = 0;
238:
239: while (enumReq.hasMoreElements()) {
240: ReqWrapper pReqWrapper = (ReqWrapper) enumReq
241: .nextElement();
242: int reqP = pReqWrapper.getPriority();
243: if ((reqP & filtre) > 0) {
244: String status = (String) allReq.get(pReqWrapper);
245: if (status.equals(ApiConstants.SUCCESS)) {
246: nbPass++;
247: } else if (status.equals(ApiConstants.FAIL)) {
248: nbFail++;
249: } else {
250: nbInco++;
251: }
252:
253: }
254: }
255:
256: int nbReqTotal = nbFail + nbPass + nbInco;
257:
258: dataset = new DefaultPieDataset();
259: if (nbReqTotal > 0) {
260: Double percentPass = new Double((nbPass * 100)
261: / nbReqTotal);
262: Double percentFail = new Double((nbFail * 100)
263: / nbReqTotal);
264: Double percentInco = new Double((nbInco * 100)
265: / nbReqTotal);
266: dataset.setValue(Language.getInstance().getText(
267: "Exigence_Fail"), percentFail);
268: dataset.setValue(Language.getInstance().getText(
269: "Exigence_Inco"), percentInco);
270: dataset.setValue(Language.getInstance().getText(
271: "Exigence_Pass"), percentPass);
272: }
273: plot.setDataset(dataset);
274:
275: } catch (Exception e) {
276: e.printStackTrace();
277: }
278: return chart;
279: }
280: }
|