01: /*
02: * Hammurapi
03: * Automated Java code review system.
04: * Copyright (C) 2004 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.hammurapi.org
21: * e-Mail: support@hammurapi.biz
22: */
23: package org.hammurapi.util;
24:
25: import java.sql.Connection;
26: import java.sql.SQLException;
27: import java.text.MessageFormat;
28: import java.util.Iterator;
29:
30: import org.hammurapi.HistoryImpl;
31: import org.hammurapi.HistoryOutputEngine;
32: import org.hammurapi.results.simple.SimpleAggregatedResults;
33:
34: import com.pavelvlasov.sql.SQLProcessor;
35:
36: /**
37: * @author Pavel Vlasov
38: * @version $Revision: 1.1 $
39: */
40: public class SigmaCalculator {
41:
42: private static String sigma(double violationLevel, long reviews) {
43: double p = 1.0 - violationLevel / reviews;
44: if (reviews == 0) {
45: return "No results";
46: } else if (p <= 0) {
47: return "Full incompliance";
48: } else if (p >= 1) {
49: return "Full compliance";
50: } else {
51: return MessageFormat.format("{0,number,#.###}",
52: new Object[] { new Double(SimpleAggregatedResults
53: .normsinv(p) + 1.5) });
54: }
55: }
56:
57: private static String dpmo(double violationLevel, long reviews) {
58: if (reviews == 0) {
59: return "Not available, no reviews";
60: }
61:
62: return String
63: .valueOf((int) (1000000 * violationLevel / reviews));
64: }
65:
66: private static Connection getConnection() throws SQLException {
67: // Implement this method
68: throw new UnsupportedOperationException("Implement!!!");
69: }
70:
71: public static void main(String[] args) throws Exception {
72: Connection con = getConnection();
73: SQLProcessor processor = new SQLProcessor(con, null);
74: HistoryOutputEngine engine = new HistoryOutputEngine(processor);
75: try {
76: Iterator it = engine.getHistory().iterator();
77: while (it.hasNext()) {
78: HistoryImpl history = (HistoryImpl) it.next();
79: if (history.getSigma() == null) {
80: history.setSigma(sigma(history.getViolationLevel(),
81: history.getReviews()));
82: history.setDpmo(dpmo(history.getViolationLevel(),
83: history.getReviews()));
84: history.update(processor, "HISTORY");
85: }
86: }
87: } finally {
88: con.close();
89: }
90: }
91: }
|