package his_mouse;

/**
 *
 * @author Viliam Krizan
 */


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class Histogram {
    //histogram pre data z mysi
    private int[][] histogram = new int[12][2];
    private int lineCounter;
    private int biggestValue = 0;
    
    public Histogram(){
        for(int i=0; i<12; i++){
            histogram[i][0]=i-5;
        }
    }

    public static void main(String[] args) {
        
        Histogram his = new Histogram();
        his.openFile();
        his.printResults();
    }

    private void openFile() {
        
        try {
            File myFile = new File("C:/Users\\Acer/Documents/NetBeansProjects/MouseMovement/MouseData.txt");
            
            FileReader fileReader = new FileReader(myFile);
            BufferedReader reader = new BufferedReader(fileReader);
            String line = null;
            int value; 
            
            while ((line = reader.readLine()) != null) {
                //System.out.println(line);
                value = Integer.parseInt(line);
                if(Math.abs(value)>biggestValue){
                    biggestValue = value;
                }
                
                
                switch(line){
                    case "-5" : histogram[0][1]++; break;
                    case "-4" : histogram[1][1]++; break;
                    case "-3" : histogram[2][1]++; break;
                    case "-2" : histogram[3][1]++; break;
                    case "-1" : histogram[4][1]++; break;
                    case "0" : histogram[5][1]++; break;
                    case "1" : histogram[6][1]++; break;
                    case "2" : histogram[7][1]++; break;
                    case "3" : histogram[8][1]++; break;
                    case "4" : histogram[9][1]++; break;
                    case "5" : histogram[10][1]++; break;
                    default: histogram[11][1]++; break;
                }
                lineCounter++;
            }
            reader.close();
        } catch (Exception ex) {
            System.out.println("Cant read file");
        }
    }
    
    private void printResults(){
        double percent;
        
        for(int i=0; i<12; i++){
            percent = ((double)histogram[i][1]/lineCounter)*100;
            System.out.format("%d:\t%d\t%.3f%%\n", histogram[i][0], histogram[i][1], percent);
            //System.out.format("%.3f  ",percent);
        }
        System.out.println("\n\n" + lineCounter + "\n\n");
        for(int i=0; i<16; i++){
            //System.out.print( + "   ");
        }
        
        System.out.println("biggest value:"  + biggestValue);
        
        /*percent = ((double)histogram[0][1]/lineCounter)*100;
        System.out.format("%d:\t%d\t%.3f%%\n", histogram[0][0], histogram[0][1], percent);
        percent = ((double)histogram[1][1]/lineCounter)*100;
        System.out.format("%d:\t%d\t%.3f%%\n", histogram[1][0], histogram[1][1], percent);
        percent = ((double)histogram[2][1]/lineCounter)*100;
        System.out.format("%d:\t%d\t%.3f%%\n", histogram[2][0], histogram[2][1], percent);
        percent = ((double)histogram[3][1]/lineCounter)*100;
        System.out.format("%d:\t%d\t%.3f%%\n", histogram[3][0], histogram[3][1], percent);*/
        
        
    }

}
