<commit_before>
//BSD 2-Clause (c) 2014: A.Doherty (Oxford), D.Jackson, N.Hammerla (Newcastle)
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;


/**
 * Calculates epoch summaries from an AX3 .CWA file.
 */
public class ActigraphReader extends DeviceReader {

    private static final int INVALID_GT3_FILE = 0;
    private static final int VALID_GT3_V1_FILE = 1;
    private static final int VALID_GT3_V2_FILE = 2;
    private static final int GT3_HEADER_SIZE = 8;

    private static Logger logger;
    static {
        String path = ActigraphReader.class.getClassLoader()
                .getResource("logging.properties")
                .getFile();
        System.setProperty("java.util.logging.config.file", path);
        logger = Logger.getLogger(ActigraphReader.class.getName());
    }

    /**
     * Reads a .gt3x file
     * For v1, the .zip archive should contain least 3 files.
     * For v2, the .zip arhive should contain only 2 files.
     * This method first verifies if it is a valid v1/v2 file,
     * it will then parse the header and begin processing the activity.bin file for v1
     * and log.bin file for v2.
     */
    public static void readG3TXEpochs(
        String accFile,
        EpochWriter epochWriter,
        Boolean verbose) {

        ZipFile zip = null;
        // readers for the 'activity.bin' & 'info.txt' files inside the .zip
        BufferedReader infoReader = null;
        InputStream activityReader = null;

        try {
            zip = new ZipFile( new File(accFile), ZipFile.OPEN_READ);

            int gt3Version = getGT3XVersion(zip);
            if (gt3Version == INVALID_GT3_FILE) {
                System.err.println("file " + accFile + " is not a valid V1 or V2 g3tx file");
                System.exit(-2);
            }

            for (Enumeration<?> e = zip.entries(); e.hasMoreElements();) {
                ZipEntry entry = (ZipEntry) e.nextElement();
                if (entry.toString().equals("info.txt")) {
                    infoReader = new BufferedReader(new InputStreamReader(zip.getInputStream(entry)));
                } else if (entry.toString().equals("activity.bin") && gt3Version == VALID_GT3_V1_FILE) {
                    activityReader = zip.getInputStream(entry);
                } else if (entry.toString().equals("log.bin") && gt3Version == VALID_GT3_V2_FILE) {
                    activityReader = zip.getInputStream(entry);
                }
            }

            // underscored are unused for now
            double sampleFreq = -1, accelerationScale = -1, _AccelerationMin, _AccelerationMax;
            long _LastSampleTime, firstSampleTime=-1;
            String serialNumber = "";
            accelerationScale = setAccelerationScale(serialNumber);

            while (infoReader.ready()) {
                String line = infoReader.readLine();
                if (line!=null){
                    String[] tokens=line.split(":");
                    if ((tokens !=null)  && (tokens.length==2)){
                        if (tokens[0].trim().equals("Sample Rate")){
                            sampleFreq=Integer.parseInt(tokens[1].trim());
                        } else if (tokens[0].trim().equals("Last Sample Time"))
                            _LastSampleTime=GT3XfromTickToMillisecond(Long.parseLong(tokens[1].trim()));
                        else if (tokens[0].trim().equals("Acceleration Scale"))
                            accelerationScale=Double.parseDouble(tokens[1].trim());
                        else if (tokens[0].trim().equals("Acceleration Min"))
                            _AccelerationMin=Double.parseDouble(tokens[1].trim());
                        else if (tokens[0].trim().equals("Acceleration Max"))
                            _AccelerationMax=Double.parseDouble(tokens[1].trim());
                        else if (tokens[0].trim().equals("Start Date"))
                            firstSampleTime=GT3XfromTickToMillisecond(Long.parseLong(tokens[1].trim()));
                        else if (tokens[0].trim().equals("Serial Number"))
                            serialNumber=tokens[1].trim();
                    }
                }
            }

            if ((sampleFreq==-1 || accelerationScale==-1 || firstSampleTime==-1) && gt3Version != VALID_GT3_V2_FILE) {<commit_msg>fix acc scale setting for gt3x v1<commit_after>
//BSD 2-Clause (c) 2014: A.Doherty (Oxford), D.Jackson, N.Hammerla (Newcastle)
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;


/**
 * Calculates epoch summaries from an AX3 .CWA file.
 */
public class ActigraphReader extends DeviceReader {

    private static final int INVALID_GT3_FILE = 0;
    private static final int VALID_GT3_V1_FILE = 1;
    private static final int VALID_GT3_V2_FILE = 2;
    private static final int GT3_HEADER_SIZE = 8;

    private static Logger logger;
    static {
        String path = ActigraphReader.class.getClassLoader()
                .getResource("logging.properties")
                .getFile();
        System.setProperty("java.util.logging.config.file", path);
        logger = Logger.getLogger(ActigraphReader.class.getName());
    }

    /**
     * Reads a .gt3x file
     * For v1, the .zip archive should contain least 3 files.
     * For v2, the .zip arhive should contain only 2 files.
     * This method first verifies if it is a valid v1/v2 file,
     * it will then parse the header and begin processing the activity.bin file for v1
     * and log.bin file for v2.
     */
    public static void readG3TXEpochs(
        String accFile,
        EpochWriter epochWriter,
        Boolean verbose) {

        ZipFile zip = null;
        // readers for the 'activity.bin' & 'info.txt' files inside the .zip
        BufferedReader infoReader = null;
        InputStream activityReader = null;

        try {
            zip = new ZipFile( new File(accFile), ZipFile.OPEN_READ);

            int gt3Version = getGT3XVersion(zip);
            if (gt3Version == INVALID_GT3_FILE) {
                System.err.println("file " + accFile + " is not a valid V1 or V2 g3tx file");
                System.exit(-2);
            }

            for (Enumeration<?> e = zip.entries(); e.hasMoreElements();) {
                ZipEntry entry = (ZipEntry) e.nextElement();
                if (entry.toString().equals("info.txt")) {
                    infoReader = new BufferedReader(new InputStreamReader(zip.getInputStream(entry)));
                } else if (entry.toString().equals("activity.bin") && gt3Version == VALID_GT3_V1_FILE) {
                    activityReader = zip.getInputStream(entry);
                } else if (entry.toString().equals("log.bin") && gt3Version == VALID_GT3_V2_FILE) {
                    activityReader = zip.getInputStream(entry);
                }
            }

            // underscored are unused for now
            double sampleFreq = -1, accelerationScale = -1, _AccelerationMin, _AccelerationMax;
            long _LastSampleTime, firstSampleTime=-1;
            String serialNumber = "";

            while (infoReader.ready()) {
                String line = infoReader.readLine();
                if (line!=null){
                    String[] tokens=line.split(":");
                    if ((tokens !=null)  && (tokens.length==2)){
                        if (tokens[0].trim().equals("Sample Rate")){
                            sampleFreq=Integer.parseInt(tokens[1].trim());
                        } else if (tokens[0].trim().equals("Last Sample Time"))
                            _LastSampleTime=GT3XfromTickToMillisecond(Long.parseLong(tokens[1].trim()));
                        else if (tokens[0].trim().equals("Acceleration Scale"))
                            accelerationScale=Double.parseDouble(tokens[1].trim());
                        else if (tokens[0].trim().equals("Acceleration Min"))
                            _AccelerationMin=Double.parseDouble(tokens[1].trim());
                        else if (tokens[0].trim().equals("Acceleration Max"))
                            _AccelerationMax=Double.parseDouble(tokens[1].trim());
                        else if (tokens[0].trim().equals("Start Date"))
                            firstSampleTime=GT3XfromTickToMillisecond(Long.parseLong(tokens[1].trim()));
                        else if (tokens[0].trim().equals("Serial Number"))
                            serialNumber=tokens[1].trim();
                    }
                }
            }
            accelerationScale = setAccelerationScale(serialNumber);

            if ((sampleFreq==-1 || accelerationScale==-1 || firstSampleTime==-1) && gt3Version != VALID_GT3_V2_FILE) {
{'fraction_non_alphanumeric': 0.11377506538796861, 'fraction_numerical': 0.014603312990409765, 'mean_word_length': 2.0437810945273633, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '5292487', 'n_tokens_mistral': 2593, 'n_tokens_neox': 2446, 'n_words': 590}