mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-16 12:31:28 +01:00
Fix and extend ActionFrequency.
This commit is contained in:
parent
d36cbe787a
commit
131ad3356f
@ -144,13 +144,21 @@ public class ActionFrequency {
|
|||||||
public final float sliceScore(final int start, final int end, float factor){
|
public final float sliceScore(final int start, final int end, float factor){
|
||||||
float score = buckets[start];
|
float score = buckets[start];
|
||||||
float cf = factor;
|
float cf = factor;
|
||||||
for (int i = start; i < end; i++){
|
for (int i = start + 1; i < end; i++){
|
||||||
score += buckets[i] * cf;
|
score += buckets[i] * cf;
|
||||||
cf *= factor;
|
cf *= factor;
|
||||||
}
|
}
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void setBucket(final int n, final float value){
|
||||||
|
buckets[n] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setTime(final long time){
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get reference time.
|
* Get reference time.
|
||||||
* @return
|
* @return
|
||||||
@ -175,4 +183,31 @@ public class ActionFrequency {
|
|||||||
return durBucket;
|
return durBucket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final String toLine(){
|
||||||
|
final StringBuilder buffer = new StringBuilder(50);
|
||||||
|
buffer.append(buckets.length + ","+durBucket+","+time);
|
||||||
|
for (int i = 0; i < buckets.length; i++){
|
||||||
|
buffer.append("," + buckets[i]);
|
||||||
|
}
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ActionFrequency fromLine(final String line){
|
||||||
|
String[] split = line.split(",");
|
||||||
|
if (split.length < 3) throw new RuntimeException("Bad argument length."); // TODO
|
||||||
|
final int n = Integer.parseInt(split[0]);
|
||||||
|
final long durBucket = Long.parseLong(split[1]);
|
||||||
|
final long time = Long.parseLong(split[2]);
|
||||||
|
final float[] buckets = new float[split.length -3];
|
||||||
|
if (split.length != buckets.length) throw new RuntimeException("Bad argument length."); // TODO
|
||||||
|
for (int i = 3; i < split.length; i ++){
|
||||||
|
buckets[i - 3] = Float.parseFloat(split[i]);
|
||||||
|
}
|
||||||
|
ActionFrequency freq = new ActionFrequency(n, durBucket);
|
||||||
|
freq.setTime(time);
|
||||||
|
for (int i = 0; i < buckets.length; i ++){
|
||||||
|
freq.setBucket(i, buckets[i]);
|
||||||
|
}
|
||||||
|
return freq;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user