package xyz.benw.plugins.fouriermc.analysis;

import org.apache.commons.math3.stat.descriptive.moment.Mean;
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation;
import org.apache.commons.math3.stat.descriptive.rank.Max;
import org.apache.commons.math3.stat.descriptive.summary.Sum;
import org.bukkit.Bukkit;
import xyz.benw.plugins.fouriermc.ClickData;
import xyz.benw.plugins.fouriermc.analysis.datatests.ClicksPerSecond;
import xyz.benw.plugins.fouriermc.FourierMC;
import xyz.benw.plugins.fouriermc.IClickData;
import xyz.benw.plugins.fouriermc.player.PlayerData;

import java.util.Map;
import java.util.UUID;

/**
 * Logs descriptive statistics about a player's signal.
 * Does not actually perform any datatests.
 * Mostly used for debugging.
 *
 * @author bcbwilla
 */
public class DescriptiveAnalyzer implements Runnable {

    private FourierMC plugin;

    public DescriptiveAnalyzer(FourierMC plugin) {
        this.plugin = plugin;
    }

    @Override
    public void run() {
        if(!plugin.getPlayerDataMap().isEmpty()){

            for (Map.Entry<UUID, PlayerData> entry : plugin.getPlayerDataMap().entrySet()) {
                UUID playerId = entry.getKey();

                for(ClickData data : entry.getValue().getClickSignals()) {
                    String name = Bukkit.getPlayer(playerId).getDisplayName();

                    if(!data.isEmpty()) {

                        double[] dataArray = data.toDoubleArray();
                        double sum = new Sum().evaluate(dataArray);

                        if(sum != 0) {
                            double cps = new ClicksPerSecond(dataArray, plugin.getSamplePeriod()).getClicksPerSecond();
                            double mean = new Mean().evaluate(dataArray);
                            double max = new Max().evaluate(dataArray);
                            double std = new StandardDeviation().evaluate(dataArray);

                            String msg = "Descriptive Analysis of " + data.getClickType().toString();
                            msg +=  " clicking for " + name + ":";
                            plugin.getLogger().info(msg);
                            plugin.getLogger().info(" Size: " + Integer.toString(data.size()));
                            plugin.getLogger().info(" Max:  " + Double.toString(max));
                            plugin.getLogger().info(" Mean: " + Double.toString(mean));
                            plugin.getLogger().info(" Sum:  " + Double.toString(sum));
                            plugin.getLogger().info(" Std:  " + Double.toString(std));
                            plugin.getLogger().info(" CPS:  " + cps);
                        }
                    }
                }
            }
        }
    }
}

@@ -627,16 +627,49 @@
 il.UUID;
+%0Aimport java.util.logging.Logger;
 %0A%0A/**%0A *
@@ -1947,32 +1947,96 @@
 te(dataArray);%0A%0A
+                            Logger logger = plugin.getLogger();%0A
                 
@@ -2216,34 +2216,22 @@
         
-plugin.getL
+l
 ogger
-()
 .info(ms
@@ -2262,34 +2262,22 @@
         
-plugin.getL
+l
 ogger
-()
 .info(%22 
@@ -2346,34 +2346,22 @@
         
-plugin.getL
+l
 ogger
-()
 .info(%22 
@@ -2421,34 +2421,22 @@
         
-plugin.getL
+l
 ogger
-()
 .info(%22 
@@ -2497,34 +2497,22 @@
         
-plugin.getL
+l
 ogger
-()
 .info(%22 
@@ -2572,34 +2572,22 @@
         
-plugin.getL
+l
 ogger
-()
 .info(%22 
@@ -2647,34 +2647,22 @@
         
-plugin.getL
+l
 ogger
-()
 .info(%22 

clean up logging a tiny bit