package his2_4bity;

/**
 *
 * @author Viliam Krizan
 */

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

public class Histogram {
    //histogram pre audio data
    private int[][] histogram = new int[16][2];
    private int lineCounter;
    
    public Histogram(){
        for(int i=0; i<16; i++){
            histogram[i][0]=i;
        }
    }

    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/MDBinary.txt");
            File myFile = new File("C:/Users/Acer/Documents/NetBeansProjects/CaptureMicrophoneData/ADBinary.txt");
            FileReader fileReader = new FileReader(myFile);
            BufferedReader reader = new BufferedReader(fileReader);
            String line = null;
            
            while ((line = reader.readLine()) != null) {
                //System.out.println(line);
                
                switch(line){
                    case "0000" : histogram[0][1]++; break;
                    case "0001" : histogram[1][1]++; break;
                    case "0010" : histogram[2][1]++; break;
                    case "0011" : histogram[3][1]++; break;
                    case "0100" : histogram[4][1]++; break;
                    case "0101" : histogram[5][1]++; break;
                    case "0110" : histogram[6][1]++; break;
                    case "0111" : histogram[7][1]++; break;
                    case "1000" : histogram[8][1]++; break;
                    case "1001" : histogram[9][1]++; break;
                    case "1010" : histogram[10][1]++; break;
                    case "1011" : histogram[11][1]++; break;
                    case "1100" : histogram[12][1]++; break;
                    case "1101" : histogram[13][1]++; break;
                    case "1110" : histogram[14][1]++; break;
                    case "1111" : histogram[15][1]++; break;
                    default: break;
                }
                lineCounter++;
            }
            reader.close();
        } catch (Exception ex) {
            System.out.println("Cant read file");
        }
    }
    
    private void printResults(){
        double percent;
        
        for(int i=0; i<16; 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( + "   ");
        }
        
        /*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);*/
        
        
    }

}
