mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-26 23:13:22 +00:00
Refactoring
This commit is contained in:
1 parent
cf2ef06862
commit
80441057e3
48 files changed
+290
-270
No files matched your search
@@ -0,0 +1,103 @@
|
||||
package mcp.mobius.opis.data.holders.stats;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
|
||||
public class StatsMod implements ISerializable, Comparable{
|
||||
private String modID;
|
||||
public double meanTime;
|
||||
public double meanGeom;
|
||||
public double variance;
|
||||
public double minTime;
|
||||
public double maxTime;
|
||||
public double median;
|
||||
public double total;
|
||||
public int ntes;
|
||||
|
||||
private double cachedMedian = -1.0;
|
||||
|
||||
public DescriptiveStatistics dstat = new DescriptiveStatistics();
|
||||
|
||||
public StatsMod(String modID){
|
||||
this.modID = modID;
|
||||
|
||||
if (this.modID == null)
|
||||
this.modID = "<Unknown>";
|
||||
}
|
||||
|
||||
public void addStat(StatsTileEntity tes){
|
||||
this.dstat.addValue(tes.getGeometricMean());
|
||||
}
|
||||
|
||||
//public double getMeanTimePerEntity(){
|
||||
// return this.dstat.getMean();
|
||||
//}
|
||||
|
||||
public String getModID(){
|
||||
return this.modID;
|
||||
}
|
||||
|
||||
public double getMedian(){
|
||||
if (this.cachedMedian < 0.0){
|
||||
int ndata = (int)this.dstat.getN();
|
||||
if (ndata == 1)
|
||||
return this.dstat.getElement(0);
|
||||
|
||||
if (ndata % 2 == 1)
|
||||
return this.dstat.getSortedValues()[ndata/2];
|
||||
|
||||
if (ndata % 2 == 0)
|
||||
return (this.dstat.getSortedValues()[ndata/2 - 1] + this.dstat.getSortedValues()[ndata/2]) / 2;
|
||||
}
|
||||
return this.cachedMedian;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
//return this.dstat.getMean() > ((ModStats)o).dstat.getMean() ? -1 : 1;
|
||||
//return this.meanTime > ((ModStats)o).meanTime ? -1 : 1;
|
||||
return this.getMedian() > ((StatsMod)o).getMedian() ? -1 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
Packet.writeString(this.modID, stream);
|
||||
|
||||
stream.writeDouble(dstat.getMean());
|
||||
stream.writeDouble(dstat.getGeometricMean());
|
||||
stream.writeDouble(dstat.getVariance());
|
||||
stream.writeDouble(dstat.getMin());
|
||||
stream.writeDouble(dstat.getMax());
|
||||
stream.writeDouble(dstat.getSum());
|
||||
stream.writeDouble(this.getMedian());
|
||||
stream.writeInt((int)dstat.getN());
|
||||
}
|
||||
|
||||
public static StatsMod readFromStream(DataInputStream stream) throws IOException {
|
||||
String modID = Packet.readString(stream, 255);
|
||||
StatsMod modStats = new StatsMod(modID);
|
||||
|
||||
modStats.meanTime = stream.readDouble();
|
||||
modStats.meanGeom = stream.readDouble();
|
||||
modStats.variance = stream.readDouble();
|
||||
modStats.minTime = stream.readDouble();
|
||||
modStats.maxTime = stream.readDouble();
|
||||
modStats.total = stream.readDouble();
|
||||
modStats.median = stream.readDouble();
|
||||
modStats.ntes = stream.readInt();
|
||||
|
||||
modStats.cachedMedian = modStats.median;
|
||||
return modStats;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return String.format("[ %s ] %d %.2f %.2f", this.modID, this.ntes, this.meanTime, this.dstat.getMean());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user