package xyz.benw.plugins.fouriermc.DataAnalysis.DataTests;

import org.apache.commons.math3.stat.descriptive.summary.Sum;

/**
 * Computes a player's clicks per second.
 *
 * @author bcbwilla
 */
public class ClicksPerSecond implements IDataTest {

    private double[] data;

    private Long samplePeriod;
    private double clicksPerSecond;

    /**
     * Class constructor.
     *
     * @param data          the clicking data to analyze
     * @param samplePeriod  the period of time that each data element represents
     */
    public ClicksPerSecond(double[] data, Long samplePeriod) {
        this.data = data;
        this.samplePeriod = samplePeriod;
    }

    /**
     * Computes clicks per second and compares to criteria.
     *
     * @param criteria the value which is compared to the computed click speed. If computed value is larger,
     *                 the test is failed.
     * @return         true if test passed, false if test failed.
     *                 A failed test implies suspicious activity.
     */
    @Override
    public boolean evaluate(double criteria) {

        // *20 to convert from ticks to seconds
        int size = data.length;
        if(samplePeriod != 0 && size != 0) {
            clicksPerSecond = (new Sum().evaluate(data) / (samplePeriod * size)) * 20;
        } else {
            clicksPerSecond = 0.0;
        }
        return clicksPerSecond < criteria;
    }

    /**
     * @return the clicks per second value
     */
    public double getClicksPerSecond() {
        return clicksPerSecond;
    }

}

@@ -272,40 +272,8 @@
 ata;
-%0A%0A    private Long samplePeriod;
 %0A   
@@ -306,16 +306,48 @@
 econd;%0A%0A
+    private Long samplePeriod;%0A%0A
     /**%0A
@@ -656,16 +656,73 @@
 Period;%0A
+        this.clicksPerSecond = computeClicksPerSecond();%0A
     %7D%0A%0A 
@@ -744,16 +744,20 @@
 omputes 
+the 
 clicks p
@@ -769,21 +769,400 @@
 cond
- and compares
+%0A     */%0A    public double computeClicksPerSecond() %7B%0A        // *20 to convert from ticks to seconds%0A        int size = data.length;%0A        double cps;%0A        if(samplePeriod != 0 && size != 0) %7B%0A            cps = (new Sum().evaluate(data) / (samplePeriod * size)) * 20;%0A        %7D else %7B%0A            cps = 0.0;%0A        %7D%0A        return cps;%0A    %7D%0A%0A    /**%0A     * Compares clicks per second
  to 
@@ -1167,17 +1167,16 @@
 o criter
-i
 a.%0A     
@@ -1530,25 +1530,24 @@
 eria) %7B%0A
-%0A
         
 // *20 t
@@ -1542,290 +1542,19 @@
     
-// *20 to convert from ticks to seconds%0A        int size = data.length;%0A        if(samplePeriod != 0 && size != 0) %7B%0A            clicksPerSecond = (new Sum().evaluate(data) / (samplePeriod * size)) * 20;%0A        %7D else %7B%0A            clicksPerSecond = 0.0;%0A        %7D%0A        return c
+return getC
 lick
@@ -1563,16 +1563,18 @@
 erSecond
+()
  %3C crite

refactor clicks per second