KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > util > SigmaCalculator


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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 JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28 import java.util.Iterator JavaDoc;
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 JavaDoc 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,#.###}", new Object JavaDoc[] {new Double JavaDoc(SimpleAggregatedResults.normsinv(p)+1.5)});
52         }
53     }
54
55     private static String JavaDoc dpmo(double violationLevel, long reviews) {
56         if (reviews==0) {
57             return "Not available, no reviews";
58         }
59         
60         return String.valueOf((int) (1000000*violationLevel/reviews));
61     }
62     
63     private static Connection JavaDoc getConnection() throws SQLException JavaDoc {
64         // Implement this method
65
throw new UnsupportedOperationException JavaDoc("Implement!!!");
66     }
67
68
69     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
70         Connection JavaDoc con = getConnection();
71         SQLProcessor processor = new SQLProcessor(con, null);
72         HistoryOutputEngine engine=new HistoryOutputEngine(processor);
73         try {
74             Iterator JavaDoc it=engine.getHistory().iterator();
75             while (it.hasNext()) {
76                 HistoryImpl history=(HistoryImpl) it.next();
77                 if (history.getSigma()==null) {
78                     history.setSigma(sigma(history.getViolationLevel(), history.getReviews()));
79                     history.setDpmo(dpmo(history.getViolationLevel(), history.getReviews()));
80                     history.update(processor, "HISTORY");
81                 }
82             }
83         } finally {
84             con.close();
85         }
86     }
87 }
88
Popular Tags