<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.team1504.robot2014;

import com.sun.squawk.microedition.io.FileConnection;
import edu.wpi.first.wpilibj.CANJaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.can.CANTimeoutException;
import edu.wpi.first.wpilibj.networktables2.util.List;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Calendar;
import javax.microedition.io.Connector;

/**
 *
 * @author Team 1504
 */
public class Logger 
{
    private static LoggingThread logger;
    private CANJaguar fl, bl, br, fr, pickup;
    private Shooter sh;
    private Joystick joy_left, joy_right, joy_op;
    private Mecanum mec;
    private HMC5883L_I2C comp;
    private boolean is_logging;
    private boolean write_freq;
    
    private long start_time;
    
    List frequent_queue;
    List sparse_queue;
    
    public Logger(CANJaguar fl, CANJaguar bl, CANJaguar br, CANJaguar fr, CANJaguar pickup, Shooter sh, Joystick l, Joystick r, Joystick o, Mecanum m, HMC5883L_I2C c)
    {
        start_time = System.currentTimeMillis();
        this.fl = fl;
        this.bl = bl;
        this.br = br;
        this.fr = fr;
        this.pickup = pickup;
        this.sh = sh;
        this.joy_left = l;
        this.joy_right = r;
        this.joy_op = o;
        this.mec = m;
        this.comp = c;
        frequent_queue = new List();
        sparse_queue = new List();
    }
    
    public void reset()
    {
        Calendar cal = Calendar.getInstance();
        String f_name;
        f_name = "log_" + cal.getTime().getTime();
        logger = new LoggingThread(f_name + ".log");
    }
    
    public void write_f(String line)
    {
        frequent_queue.add(line);
    }
    
    public void write_s(String line)
    {
        sparse_queue.add(line);
    }
    
    public void start()
    {
        enable();
        logger.start();
    }
    
    public void enable()
    {
        is_logging = true;
    }
    
    public void disable()
    {
        is_logging = false;
    }
    
    private class LoggingThread extends Thread
    {
        private PrintStream log_stream;
        
        public LoggingThread(String f_log_name)
        {
            FileConnection fc;
            try {
                fc = (FileConnection)Connector.open("file:///"+f_log_name, Connector.WRITE);
                fc.create();
                DataOutputStream f_log = fc.openDataOutputStream();
                log_stream = new PrintStream(f_log);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            log_stream.println("Timestamp Driver_Joy_Y Driver_Joy_X Driver_Joy_W FL_Out BL_Out BR_Out FR_Out FL_Jag_Speed FL_Bus_Voltage FL_Out_Voltage FL_Out_Current FL_Temp BL_Jag_Speed BL_Bus_Voltage BL_Out_Voltage BL_Out_Current BL_Temp BR_Jag_Speed BR_Bus_Voltage BR_Out_Voltage BR_Out_Current BR_Temp FR_Jag_Speed FR_Bus_Voltage FR_Out_Voltage FR_Out_Current FR_Temp");
        }
        
        public void run()
        {
//            System.out.println("Running Logging Thread");
            while(is_logging)
            {
                long loop_time = System.currentTimeMillis();
//                System.out.println("LOOOOP");
                if (frequent_queue.size() > 12)
                {
                    System.out.println("Flushing Frequent Queue");
                    while (frequent_queue.size() > 0)
                    {<commit_msg>DO THE THING GUUISE WOOO ALSO LOGGING HEADER IS A+<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.team1504.robot2014;

import com.sun.squawk.microedition.io.FileConnection;
import edu.wpi.first.wpilibj.CANJaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.can.CANTimeoutException;
import edu.wpi.first.wpilibj.networktables2.util.List;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Calendar;
import javax.microedition.io.Connector;

/**
 *
 * @author Team 1504
 */
public class Logger 
{
    private static LoggingThread logger;
    private CANJaguar fl, bl, br, fr, pickup;
    private Shooter sh;
    private Joystick joy_left, joy_right, joy_op;
    private Mecanum mec;
    private HMC5883L_I2C comp;
    private boolean is_logging;
    private boolean write_freq;
    
    private long start_time;
    
    List frequent_queue;
    List sparse_queue;
    
    public Logger(CANJaguar fl, CANJaguar bl, CANJaguar br, CANJaguar fr, CANJaguar pickup, Shooter sh, Joystick l, Joystick r, Joystick o, Mecanum m, HMC5883L_I2C c)
    {
        start_time = System.currentTimeMillis();
        this.fl = fl;
        this.bl = bl;
        this.br = br;
        this.fr = fr;
        this.pickup = pickup;
        this.sh = sh;
        this.joy_left = l;
        this.joy_right = r;
        this.joy_op = o;
        this.mec = m;
        this.comp = c;
        frequent_queue = new List();
        sparse_queue = new List();
    }
    
    public void reset()
    {
        Calendar cal = Calendar.getInstance();
        String f_name;
        f_name = "log_" + cal.getTime().getTime();
        logger = new LoggingThread(f_name + ".log");
    }
    
    public void write_f(String line)
    {
        frequent_queue.add(line);
    }
    
    public void write_s(String line)
    {
        sparse_queue.add(line);
    }
    
    public void start()
    {
        enable();
        logger.start();
    }
    
    public void enable()
    {
        is_logging = true;
    }
    
    public void disable()
    {
        is_logging = false;
    }
    
    private class LoggingThread extends Thread
    {
        private PrintStream log_stream;
        
        public LoggingThread(String f_log_name)
        {
            FileConnection fc;
            try {
                fc = (FileConnection)Connector.open("file:///"+f_log_name, Connector.WRITE);
                fc.create();
                DataOutputStream f_log = fc.openDataOutputStream();
                log_stream = new PrintStream(f_log);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            log_stream.println("Timestamp, Driver_Joy_Y, Driver_Joy_X, Driver_Joy_W, FL_Jag_Speed, FL_Bus_Voltage, FL_Out_Voltage, FL_Out_Current, FL_Temp, BL_Jag_Speed, BL_Bus_Voltage, BL_Out_Voltage, BL_Out_Current, BL_Temp, BR_Jag_Speed, BR_Bus_Voltage, BR_Out_Voltage, BR_Out_Current, BR_Temp, FR_Jag_Speed, FR_Bus_Voltage, FR_Out_Voltage, FR_Out_Current, FR_Temp, SH_Speed, SH_Angle");
        }
        
        public void run()
        {
//            System.out.println("Running Logging Thread");
            while(is_logging)
            {
                long loop_time = System.currentTimeMillis();
//                System.out.println("LOOOOP");
                if (frequent_queue.size() > 12)
                {
                    System.out.println("Flushing Frequent Queue");
                    while (frequent_queue.size() > 0)
                    {
{'fraction_non_alphanumeric': 0.09031556039173014, 'fraction_numerical': 0.007072905331882481, 'mean_word_length': 2.1530874785591765, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3615451', 'n_tokens_mistral': 2410, 'n_tokens_neox': 2318, 'n_words': 531}