1 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 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,#.###}", new Object [] {new Double (SimpleAggregatedResults.normsinv(p)+1.5)}); 52 } 53 } 54 55 private static String 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 getConnection() throws SQLException { 64 throw new UnsupportedOperationException ("Implement!!!"); 66 } 67 68 69 public static void main(String [] args) throws Exception { 70 Connection con = getConnection(); 71 SQLProcessor processor = new SQLProcessor(con, null); 72 HistoryOutputEngine engine=new HistoryOutputEngine(processor); 73 try { 74 Iterator 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 |