<commit_before>var basal = require('oref0/lib/profile/basal');
var get_iob = require('oref0/lib/iob');

function detectSensitivityandCarbAbsorption(inputs) {

    glucose_data = inputs.glucose_data;
    iob_inputs = inputs.iob_inputs;
    basalprofile = inputs.basalprofile;
    profile = inputs.iob_inputs.profile;
    mealTime = new Date(inputs.mealTime);

    //console.log(mealTime);

    var avgDeltas = [];
    var bgis = [];
    var deviations = [];
    var deviationSum = 0;
    var carbsAbsorbed = 0;
    for (var i=0; i < glucose_data.length-3; ++i) {
        //console.log(glucose_data[i]);
        var bgTime;
        if (glucose_data[i].display_time) {
            bgTime = new Date(glucose_data[i].display_time.replace('T', ' '));
        } else if (glucose_data[i].dateString) {
            bgTime = new Date(glucose_data[i].dateString);
        } else { console.error("Could not determine last BG time"); }
        //console.log(bgTime);
        var bg = glucose_data[i].glucose;
        if ( bg < 40 || glucose_data[i+3].glucose < 40) {
            process.stderr.write("!");
            continue;
        }
        var avgDelta = (bg - glucose_data[i+3].glucose)/3;
        avgDelta = avgDelta.toFixed(2);
        var delta = (bg - glucose_data[i+1].glucose);
        iob_inputs.clock=bgTime;
        iob_inputs.profile.current_basal = basal.basalLookup(basalprofile, bgTime);
        //console.log(JSON.stringify(iob_inputs.profile));
        var iob = get_iob(iob_inputs)[0];
        //console.log(JSON.stringify(iob));

        //var bgi = -iob.activity*profile.sens;
        var bgi = Math.round(( -iob.activity * profile.sens * 5 )*100)/100;
        bgi = bgi.toFixed(2);
        deviation = delta-bgi;
        deviation = deviation.toFixed(2);
        //if (deviation < 0 && deviation > -2) { console.error("BG: "+bg+", avgDelta: "+avgDelta+", BGI: "+bgi+", deviation: "+deviation); }
        process.stderr.write(".");

        avgDeltas.push(avgDelta);
        bgis.push(bgi);
        deviations.push(deviation);
        deviationSum += parseFloat(deviation);

        // if bgTime is more recent than mealTime
        if(bgTime > mealTime) {
            //console.log(bgTime, deviation)
            // and deviation is positive
            if (deviation > 0) {
                // figure out how many carbs that represents
                //console.log(delta)
                absorbed = deviation * profile.carb_ratio / profile.sens;
                //console.log(absorbed);
                // and add that to the running total carbsAbsorbed
                carbsAbsorbed += absorbed;
                console.error(carbsAbsorbed);
            }
        }
    }
    console.error("");
    //console.log(JSON.stringify(avgDeltas));
    //console.log(JSON.stringify(bgis));
    avgDeltas.sort(function(a, b){return a-b});
    bgis.sort(function(a, b){return a-b});
    deviations.sort(function(a, b){return a-b});
    for (var i=0.51; i > 0.29; i = i - 0.01) {
        //console.error("p="+i.toFixed(2)+": "+percentile(avgDeltas, i).toFixed(2)+", "+percentile(bgis, i).toFixed(2)+", "+percentile(deviations, i).toFixed(2));
    }
    p50 = percentile(deviations, 0.5);
    p45 = percentile(deviations, 0.45);
    //p30 = percentile(deviations, 0.3);

    average = deviationSum / deviations.length;
<commit_msg>debugging off<commit_after>var basal = require('oref0/lib/profile/basal');
var get_iob = require('oref0/lib/iob');

function detectSensitivityandCarbAbsorption(inputs) {

    glucose_data = inputs.glucose_data;
    iob_inputs = inputs.iob_inputs;
    basalprofile = inputs.basalprofile;
    profile = inputs.iob_inputs.profile;
    mealTime = new Date(inputs.mealTime);

    //console.log(mealTime);

    var avgDeltas = [];
    var bgis = [];
    var deviations = [];
    var deviationSum = 0;
    var carbsAbsorbed = 0;
    for (var i=0; i < glucose_data.length-3; ++i) {
        //console.log(glucose_data[i]);
        var bgTime;
        if (glucose_data[i].display_time) {
            bgTime = new Date(glucose_data[i].display_time.replace('T', ' '));
        } else if (glucose_data[i].dateString) {
            bgTime = new Date(glucose_data[i].dateString);
        } else { console.error("Could not determine last BG time"); }
        //console.log(bgTime);
        var bg = glucose_data[i].glucose;
        if ( bg < 40 || glucose_data[i+3].glucose < 40) {
            process.stderr.write("!");
            continue;
        }
        var avgDelta = (bg - glucose_data[i+3].glucose)/3;
        avgDelta = avgDelta.toFixed(2);
        var delta = (bg - glucose_data[i+1].glucose);
        iob_inputs.clock=bgTime;
        iob_inputs.profile.current_basal = basal.basalLookup(basalprofile, bgTime);
        //console.log(JSON.stringify(iob_inputs.profile));
        var iob = get_iob(iob_inputs)[0];
        //console.log(JSON.stringify(iob));

        //var bgi = -iob.activity*profile.sens;
        var bgi = Math.round(( -iob.activity * profile.sens * 5 )*100)/100;
        bgi = bgi.toFixed(2);
        deviation = delta-bgi;
        deviation = deviation.toFixed(2);
        //if (deviation < 0 && deviation > -2) { console.error("BG: "+bg+", avgDelta: "+avgDelta+", BGI: "+bgi+", deviation: "+deviation); }
        process.stderr.write(".");

        avgDeltas.push(avgDelta);
        bgis.push(bgi);
        deviations.push(deviation);
        deviationSum += parseFloat(deviation);

        // if bgTime is more recent than mealTime
        if(bgTime > mealTime) {
            //console.log(bgTime, deviation)
            // and deviation is positive
            if (deviation > 0) {
                // figure out how many carbs that represents
                //console.log(delta)
                absorbed = deviation * profile.carb_ratio / profile.sens;
                //console.log(absorbed);
                // and add that to the running total carbsAbsorbed
                carbsAbsorbed += absorbed;
                //console.error(carbsAbsorbed);
            }
        }
    }
    console.error("");
    //console.log(JSON.stringify(avgDeltas));
    //console.log(JSON.stringify(bgis));
    avgDeltas.sort(function(a, b){return a-b});
    bgis.sort(function(a, b){return a-b});
    deviations.sort(function(a, b){return a-b});
    for (var i=0.51; i > 0.29; i = i - 0.01) {
        //console.error("p="+i.toFixed(2)+": "+percentile(avgDeltas, i).toFixed(2)+", "+percentile(bgis, i).toFixed(2)+", "+percentile(deviations, i).toFixed(2));
    }
    p50 = percentile(deviations, 0.5);
    p45 = percentile(deviations, 0.45);
    //p30 = percentile(deviations, 0.3);

    average = deviationSum / deviations.length;

{'fraction_non_alphanumeric': 0.15082458770614693, 'fraction_numerical': 0.016191904047976012, 'mean_word_length': 2.379432624113475, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, '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': '6797031', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2155, 'n_words': 411}