<commit_before>package com.brianledbetter.kwplogger.KWP2000;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by b3d on 12/6/15.
 */
public class MeasurementValue {
    public String stringValue;
    public String stringLabel;
    public static final Map<Byte, MeasurementValueParser> valueParsers = new HashMap<Byte, MeasurementValueParser>() {
        { // I WANT LAMBDAS
            put((byte)0x01, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int rpm = (bytes[0] * bytes[1]) / 5;
                    return new MeasurementValue(Integer.toString(rpm), "rpm");
                }
            });
            put((byte) 0x04, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    String unit;
                    if (bytes[1] > 127) {

                        unit = "deg ATDC";
                    }
                    else {
                        unit = "deg BTDC";
                    }
                    int output = (Math.abs(bytes[1] - 127) * bytes[0])/100;
                    return new MeasurementValue(Integer.toString(output), unit);
                }
            });
            put((byte) 0x06, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int output = (bytes[0]*bytes[1])/1000;
                    return new MeasurementValue(Integer.toString(output), "V");
                }
            });
            put((byte) 0x07, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int output = (bytes[0]*bytes[1])/100;
                    return new MeasurementValue(Integer.toString(output), "km/h");
                }
            });

            put((byte)0x1A, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int temperatureDegreesC = bytes[1] - bytes[0];
                    return new MeasurementValue(Integer.toString(temperatureDegreesC), "degC");
                }
            });

        }
    };

    public static MeasurementValue parseValue(byte[] byteValue) {
        MeasurementValueParser mvp = valueParsers.get(byteValue[0]);
        if (mvp != null) {
            return mvp.parseBytes(Arrays.copyOfRange(byteValue, 1, 3));
        } else {
            return new MeasurementValue("Error", "Error");
        }
    }

    public MeasurementValue(String value, String label) {
        this.stringValue = value;<commit_msg>more parse types, passthrough raw values to display<commit_after>package com.brianledbetter.kwplogger.KWP2000;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by b3d on 12/6/15.
 */
public class MeasurementValue {
    public String stringValue;
    public String stringLabel;
    public static final Map<Byte, MeasurementValueParser> valueParsers = new HashMap<Byte, MeasurementValueParser>() {
        { // I WANT LAMBDAS
            put((byte)0x01, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int rpm = (bytes[0] * bytes[1]) / 5;
                    return new MeasurementValue(Integer.toString(rpm), "rpm");
                }
            });
            put((byte)0x02, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int percent = (bytes[0] * bytes[1]) / 500;
                    return new MeasurementValue(Integer.toString(percent), "%");
                }
            });
            put((byte)0x03, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int deg = (bytes[0] * bytes[1]) / 500;
                    return new MeasurementValue(Integer.toString(deg), "deg");
                }
            });
            put((byte) 0x04, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    String unit;
                    if (bytes[1] > 127) {

                        unit = "deg ATDC";
                    }
                    else {
                        unit = "deg BTDC";
                    }
                    int output = (Math.abs(bytes[1] - 127) * bytes[0])/100;
                    return new MeasurementValue(Integer.toString(output), unit);
                }
            });
            put((byte) 0x05, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int output = ((bytes[0]*bytes[1])/10) - (bytes[0] * 10);
                    return new MeasurementValue(Integer.toString(output), "deg C");
                }
            });
            put((byte) 0x06, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int output = (bytes[0]*bytes[1])/1000;
                    return new MeasurementValue(Integer.toString(output), "V");
                }
            });
            put((byte) 0x07, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int output = (bytes[0]*bytes[1])/100;
                    return new MeasurementValue(Integer.toString(output), "km/h");
                }
            });
            put((byte) 0x08, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int output = (bytes[0]*bytes[1])/10;
                    return new MeasurementValue(Integer.toString(output), "-");
                }
            });
            put((byte) 0x09, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int output = ((bytes[1]-127)*bytes[0])/50;
                    return new MeasurementValue(Integer.toString(output), "deg");
                }
            });
            put((byte) 0x0A, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    String output;
                    if(bytes[1] == 0) {
                        output = "COLD";
                    } else {
                        output = "WARM";
                    }
                    return new MeasurementValue(output, "-");
                }
            });
            put((byte)0x1A, new MeasurementValueParser() {
                @Override
                public MeasurementValue parseBytes(byte[] bytes) {
                    int temperatureDegreesC = bytes[1] - bytes[0];
                    return new MeasurementValue(Integer.toString(temperatureDegreesC), "degC");
                }
            });

        }
    };

    public static MeasurementValue parseValue(byte[] byteValue) {
        MeasurementValueParser mvp = valueParsers.get(byteValue[0]);
        if (mvp != null) {
            return mvp.parseBytes(Arrays.copyOfRange(byteValue, 1, 3));
        } else {
            return new MeasurementValue(HexUtil.bytesToHexString(byteValue), "Raw");
        }
    }

    public MeasurementValue(String value, String label) {
        this.stringValue = value;
{'fraction_non_alphanumeric': 0.10529045643153527, 'fraction_numerical': 0.020357883817427386, 'mean_word_length': 1.4953089615011323, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7252305', 'n_tokens_mistral': 2141, 'n_tokens_neox': 1817, 'n_words': 422}