<commit_before>package grapher;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Timer;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.DynamicTimeSeriesCollection;
import org.jfree.data.time.Second;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
//import javax.comm.*;

public class RTGrapher extends ApplicationFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6580194594526535628L;
	private static String TITLE;
	private static final boolean IS_DEBUG=true;
    private static final String START = "Start";
    private static final String STOP = "Stop";
    private static final float MINMAX = 100;
    private static final int COUNT = 60;
    private File file;
    private FileInputStream fis;
    private FileOutputStream fos;
    private final String PATH;
    private final DynamicTimeSeriesCollection dataset;
    private byte[] b;
    public JLabel noticeLabel;
//    private static final int FAST = 100;
//    private static final int SLOW = FAST * 5;
    private static final Random random = new Random();
    private final int seriesCount;
    private Timer timer;
    public RTGrapher(){
    	super("Untitled");
    	noticeLabel=new JLabel();
    	if(IS_DEBUG){
    		TITLE=new String("Ha");
    		PATH=new String("/dev/tty.SC04-DevB");
    		seriesCount=4;
    	}else{
    		TITLE=JOptionPane.showInputDialog(this,"Graph name:","HA");
    		PATH=JOptionPane.showInputDialog(this,"Path name:",null);
    	}
    	
    	
    	String s;
    	
//    	do{
//    		s=JOptionPane.showInputDialog(this, "Number of graph:",2);
//    	}while(!isInteger(s));
    	file=new File(PATH);
    	try {
			fis = new FileInputStream(file);
			fos = new FileOutputStream(file);
//			System.out.println("Total file size to read (in bytes) : "
//					+ fis.available());
 
//			int content;
//			while ((content = fis.read()) != -1) {
//				// convert to char and display it
//				addData((float)content,1);
//			}
 
		} catch (IOException e) {
			e.printStackTrace();
		} 
    	dataset =
                new DynamicTimeSeriesCollection(seriesCount, COUNT, new Second());
    	//this.seriesCount=Integer.parseInt(s);
            dataset.setTimeBase(new Second());
            float[] f=new float[]{0};
            dataset.addSeries(f, 0, "Fake data");
            dataset.addSeries(f, 1, "Custom Data");
            JFreeChart chart = createChart(dataset);
            final JButton run = new JButton(STOP);
            run.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    String cmd = e.getActionCommand();
                    if (STOP.equals(cmd)) {
                        timer.stop();
                        run.setText(START);
                    } else {
                        timer.start();
                        run.setText(STOP);
                    }
                }
            });
            final JButton addValue=new JButton("Add value");
            addValue.addActionListener(new ActionListener(){
            	@Override
            	public void actionPerformed(ActionEvent e){
            		
                        float newData = randomValue();
                        //dataset.advanceTime();
                        dataset.addValue(1,dataset.getNewestIndex(),newData);
            	}
            });
//            final JComboBox combo = new JComboBox();
//            combo.addItem("Fast");
//            combo.addItem("Slow");
//            combo.addActionListener(new ActionListener() {
//                @Override
//                public void actionPerformed(ActionEvent e) {
//                    if ("Fast".equals(combo.getSelectedItem())) {
//                        timer.setDelay(FAST);
//                    } else {
//                        timer.setDelay(SLOW);
//                    }
//                }
//            });
//            final JTextField intervalTextField=new JTextField("115200");
//            intervalTextField.addActionListener(new ActionListener(){
//            	@Override
//            	public void actionPerformed(ActionEvent e){
//            		if(isInteger(intervalTextField.getText())){
//            			btManager.baudRate=Integer.parseInt(intervalTextField.getText());
//            		}
//            	}
//            });
            //JList<CommPortIdentifier> btList=new JList<CommPortIdentifier>(BTManager.getPortIdentifiers());
            //this.add(btList,BorderLayout.EAST);
            this.add(new ChartPanel(chart), BorderLayout.CENTER);
            this.add(noticeLabel, BorderLayout.NORTH);
            JPanel btnPanel = new JPanel(new FlowLayout());
            btnPanel.add(run);
            btnPanel.add(addValue);
            btnPanel.add(new JLabel("Baud Rate:"));
//          btnPanel.add(intervalTextField);
            this.add(btnPanel, BorderLayout.SOUTH);
            timer = new Timer(100, new ActionListener(){
            	@Override
            	public void actionPerformed(ActionEvent e){
            		//float[] newData = new float[1];<commit_msg>remove unused expression<commit_after>package grapher;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Timer;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.DynamicTimeSeriesCollection;
import org.jfree.data.time.Second;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
//import javax.comm.*;

public class RTGrapher extends ApplicationFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6580194594526535628L;
	private static String TITLE;
	private static final boolean IS_DEBUG=true;
    private static final String START = "Start";
    private static final String STOP = "Stop";
    private static final float MINMAX = 100;
    private static final int COUNT = 60;
    private File file;
    private FileInputStream fis;
    private FileOutputStream fos;
    private final String PATH;
    private final DynamicTimeSeriesCollection dataset;
    private byte[] b;
    public JLabel noticeLabel;
//    private static final int FAST = 100;
//    private static final int SLOW = FAST * 5;
    private static final Random random = new Random();
    private final int seriesCount;
    private Timer timer;
    public RTGrapher(){
    	super("Untitled");
    	noticeLabel=new JLabel();
    	if(IS_DEBUG){
    		TITLE=new String("Ha");
    		PATH=new String("/dev/tty.SC04-DevB");
    		seriesCount=4;
    	}else{
    		TITLE=JOptionPane.showInputDialog(this,"Graph name:","HA");
    		PATH=JOptionPane.showInputDialog(this,"Path name:",null);
    	}
    	
    	
    	String s;
    	
//    	do{
//    		s=JOptionPane.showInputDialog(this, "Number of graph:",2);
//    	}while(!isInteger(s));
    	file=new File(PATH);
    	try {
			fis = new FileInputStream(file);
			fos = new FileOutputStream(file);
//			System.out.println("Total file size to read (in bytes) : "
//					+ fis.available());
 
//			int content;
//			while ((content = fis.read()) != -1) {
//				// convert to char and display it
//				addData((float)content,1);
//			}
 
		} catch (IOException e) {
			e.printStackTrace();
		} 
    	dataset =
                new DynamicTimeSeriesCollection(seriesCount, COUNT, new Second());
    	//this.seriesCount=Integer.parseInt(s);
            dataset.setTimeBase(new Second());
            float[] f=new float[]{0};
            dataset.addSeries(f, 0, "Fake data");
            dataset.addSeries(f, 1, "Custom Data");
            JFreeChart chart = createChart(dataset);
            final JButton run = new JButton(STOP);
            run.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    String cmd = e.getActionCommand();
                    if (STOP.equals(cmd)) {
                        timer.stop();
                        run.setText(START);
                    } else {
                        timer.start();
                        run.setText(STOP);
                    }
                }
            });
            final JButton addValue=new JButton("Add value");
            addValue.addActionListener(new ActionListener(){
            	@Override
            	public void actionPerformed(ActionEvent e){
            		
                        float newData = randomValue();
                        //dataset.advanceTime();
                        dataset.addValue(1,dataset.getNewestIndex(),newData);
            	}
            });
//            final JComboBox combo = new JComboBox();
//            combo.addItem("Fast");
//            combo.addItem("Slow");
//            combo.addActionListener(new ActionListener() {
//                @Override
//                public void actionPerformed(ActionEvent e) {
//                    if ("Fast".equals(combo.getSelectedItem())) {
//                        timer.setDelay(FAST);
//                    } else {
//                        timer.setDelay(SLOW);
//                    }
//                }
//            });
//            final JTextField intervalTextField=new JTextField("115200");
//            intervalTextField.addActionListener(new ActionListener(){
//            	@Override
//            	public void actionPerformed(ActionEvent e){
//            		if(isInteger(intervalTextField.getText()))
//            			btManager.baudRate=Integer.parseInt(intervalTextField.getText());
//            		}
//            	}
//            });
            //JList<CommPortIdentifier> btList=new JList<CommPortIdentifier>(BTManager.getPortIdentifiers());
            //this.add(btList,BorderLayout.EAST);
            this.add(new ChartPanel(chart), BorderLayout.CENTER);
            this.add(noticeLabel, BorderLayout.NORTH);
            JPanel btnPanel = new JPanel(new FlowLayout());
            btnPanel.add(run);
            btnPanel.add(addValue);
//          btnPanel.add(new JLabel("Baud Rate:"));
//          btnPanel.add(intervalTextField);
            this.add(btnPanel, BorderLayout.SOUTH);
            timer = new Timer(100, new ActionListener(){
            	@Override
            	public void actionPerformed(ActionEvent e){
            		//float[] newData = new float[1];
{'fraction_non_alphanumeric': 0.11675518245674148, 'fraction_numerical': 0.008223402432756552, 'mean_word_length': 2.124163767728124, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5279928', 'n_tokens_mistral': 3411, 'n_tokens_neox': 3220, 'n_words': 693}