[Polycasso-commit] SF.net SVN: polycasso:[70] trunk/polycasso/src/com/mebigfatguy/polycasso/ Improv
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-11-27 19:33:03
|
Revision: 70
http://polycasso.svn.sourceforge.net/polycasso/?rev=70&view=rev
Author: dbrosius
Date: 2009-11-27 19:32:52 +0000 (Fri, 27 Nov 2009)
Log Message:
-----------
add toString
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementTypeStats.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementTypeStats.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementTypeStats.java 2009-11-27 14:27:31 UTC (rev 69)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImprovementTypeStats.java 2009-11-27 19:32:52 UTC (rev 70)
@@ -40,6 +40,8 @@
return successes + "/" + totals + " [" + pct + "]";
}
}
+ private int overallSuccesses = 1;
+ private int overallTotals = 1;
private Map<ImprovementType, Stats> typeStats = new EnumMap<ImprovementType, Stats>(ImprovementType.class);
private Random r = new Random();
@@ -60,9 +62,12 @@
*/
public void typeWasSuccessful(ImprovementType type, boolean successful) {
Stats stats = typeStats.get(type);
- if (successful)
+ if (successful) {
stats.successes++;
+ overallSuccesses++;
+ }
stats.totals++;
+ overallTotals++;
failureRun = successful ? 0 : failureRun + 1;
if (failureRun > MAX_FAILURE_RUN) {
initStats();
@@ -80,10 +85,7 @@
public ImprovementType getRandomImprovementType() {
double pct = r.nextDouble();
- double totalPct = 0.0;
- for (Stats stat : typeStats.values()) {
- totalPct += stat.pct;
- }
+ double totalPct = ((double) overallSuccesses) / ((double) overallTotals);
for (Map.Entry<ImprovementType, Stats> entry : typeStats.entrySet()) {
Stats stat = entry.getValue();
@@ -97,6 +99,17 @@
return ImprovementType.CompleteChange;
}
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(100);
+ double pct = ((double) overallSuccesses) / ((double) overallTotals);
+ sb.append("Overall Success %: ").append(pct);
+ for (Map.Entry<ImprovementType, Stats> entry : typeStats.entrySet()) {
+ Stats stat = entry.getValue();
+ sb.append(" ").append(entry.getKey().name()).append(" % = ").append(stat.pct);
+ }
+ return sb.toString();
+ }
/**
* sets the stats to an initial state
*/
@@ -105,6 +118,8 @@
for (ImprovementType type : values) {
typeStats.put(type, new Stats());
}
+ overallSuccesses = 1;
+ overallTotals = 1;
failureRun = 0;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|