package his_web_3bity;

/**
 *
 * @author Viliam Krizan
 */


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

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

    public static void main(String[] args) {
        
        Histogram his = new Histogram();
        //his.openFile();
        //his.printResults();
        
        //diff
        int dpc=0;
        try {
            File myFile = new File("C:/Users/Acer/Documents/NetBeansProjects/CaptureWebcamData/WebCamData1.txt");
            FileReader fileReader = new FileReader(myFile);
            BufferedReader reader = new BufferedReader(fileReader);
            File myFile2 = new File("C:/Users/Acer/Documents/NetBeansProjects/CaptureWebcamData/WebCamData2.txt");
            FileReader fileReader2 = new FileReader(myFile2);
            BufferedReader reader2 = new BufferedReader(fileReader2);
            String line = null;
            String line2 = null;
            
            while ((line = reader.readLine()) != null) {
                line2 = reader2.readLine();
                if(line.equals(line2)){
                    dpc++;
                }
               
            }
            //System.out.println(dpc);
        } catch (Exception e) {
            System.out.println("cant read");
        }
        System.out.println(dpc);
    }

    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/CaptureWebcamData/WebCamData2.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 "000" : histogram[0][1]++; break;
                    case "001" : histogram[1][1]++; break;
                    case "010" : histogram[2][1]++; break;
                    case "011" : histogram[3][1]++; break;
                    case "100" : histogram[4][1]++; break;
                    case "101" : histogram[5][1]++; break;
                    case "110" : histogram[6][1]++; break;
                    case "111" : histogram[7][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<8; 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.err.println("counter: " + lineCounter);
        /*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);*/
        
        
    }

}
