1 23 package org.hammurapi.results.persistent.jdbc; 24 25 import java.sql.PreparedStatement ; 26 import java.sql.SQLException ; 27 import java.text.MessageFormat ; 28 import java.util.Date ; 29 30 import org.hammurapi.results.persistent.jdbc.sql.BasicResultTotal; 31 import org.hammurapi.results.simple.SimpleAggregatedResults; 32 33 import com.pavelvlasov.sql.Parameterizer; 34 35 36 41 public class BasicResults implements org.hammurapi.results.BasicResults { 42 43 public Number getMaxSeverity() { 44 return maxSeverity; 45 } 46 47 protected Parameterizer idParameterizer = new Parameterizer() { 48 public void parameterize(PreparedStatement ps) throws SQLException { 49 ps.setInt(1, getId()); 50 } 51 }; 52 53 public String getSigma() { 54 double p=1.0-violationLevel/reviews; 55 if (reviews==0) { 56 return "No results"; 57 } else if (p<=0) { 58 return "Full incompliance"; 59 } else if (p>=1) { 60 return "Full compliance"; 61 } else { 62 return MessageFormat.format("{0,number,#.###}", new Object [] {new Double (SimpleAggregatedResults.normsinv(p)+1.5)}) + (hasWarnings() ? " (not accurate because of warnings)" : ""); 63 } 64 } 65 66 public String getDPMO() { 67 if (reviews==0) { 68 return "Not available, no reviews"; 69 } 70 71 return String.valueOf((int) (1000000*violationLevel/reviews)) + (hasWarnings() ? " (not accurate because of warnings)" : ""); 72 } 73 74 public boolean hasWarnings() { 75 return hasWarnings; 76 } 77 78 public int getWaivedViolationsNumber() { 79 return waivedViolationsNumber; 80 } 81 82 public Date getDate() { 83 return date; 84 } 85 86 protected Date date = new Date (); 87 88 public int getViolationsNumber() { 89 return violationsNumber; 90 } 91 92 public long getCodeBase() { 93 return codeBase; 94 } 95 96 public long getReviewsNumber() { 97 return reviews; 98 } 99 100 public double getViolationLevel() { 101 return violationLevel; 102 } 103 104 protected int getId() { 105 return id; 106 } 107 108 protected int id; 109 protected ResultsFactory factory; 110 protected boolean hasWarnings = false; 111 protected Number maxSeverity; 112 protected int waivedViolationsNumber = 0; 113 protected int violationsNumber = 0; 114 protected double violationLevel = 0; 115 protected long reviews = 0; 116 protected long codeBase = 0; 117 118 protected BasicResults(ResultsFactory factory) { 119 this.factory=factory; 120 } 121 122 public BasicResults(int id, ResultsFactory factory) throws SQLException { 123 this(factory); 124 this.id=id; 125 factory.addToCache(this); 126 BasicResultTotal data = factory.getResultsEngine().getBasicResultTotal(id); 127 codeBase=data.getCodebase(); 128 date=data.getResultDate(); 129 reviews=data.getReviews(); 130 violationLevel=data.getViolationLevel(); 131 violationsNumber=(int) data.getViolations(); 132 waivedViolationsNumber=(int) data.getWaivedViolations(); 133 maxSeverity=data.getMaxSeverity(); 134 hasWarnings=data.getHasWarnings()>0; 135 } 136 137 } 138 | Popular Tags |