<commit_before>/*
 * Captures metrics.
 *
 * Copyright 2017 Raising the Floor - International
 *
 * Licensed under the New BSD license. You may not use this file except in
 * compliance with this License.
 *
 * The R&D leading to these results received funding from the
 * Department of Education - Grant H421A150005 (GPII-APCP). However,
 * these results do not necessarily represent the policy of the
 * Department of Education, and you should not assume endorsement by the
 * Federal Government.
 *
 * You may obtain a copy of the License at
 * https://github.com/GPII/universal/blob/master/LICENSE.txt
 */

"use strict";

var fluid = require("infusion");

fluid.registerNamespace("gpii");
var windows = fluid.registerNamespace("gpii.windows");

require("../../WindowsUtilities/WindowsUtilities.js");
var ffi = require("ffi");

fluid.defaults("gpii.windowsMetrics", {
    gradeNames: ["fluid.modelComponent"],
    listeners: {
        "{eventLog}.events.onCreate": "{that}.events.onStartMetrics",
        "onDestroy.stopMetrics": "{that}.events.onStopMetrics",
        "onStartMetrics.application": "{that}.startApplicationMetrics",
        "onStopMetrics.application": "{that}.stopApplicationMetrics",
        "onStartMetrics.keyboard": "{that}.startKeyboardMetrics",
        "onStopMetrics.keyboard": "{that}.stopKeyboardMetrics"
    },
    events: {
        "onStartMetrics": null,
        "onStopMetrics": null
    },
    invokers: {
        logMetric: {
            func: "{eventLog}.logEvent",
            args: ["{eventLog}", "metrics", "{arguments}.0", "{arguments}.1"]
        },
        startApplicationMetrics: {
            funcName: "gpii.windows.startApplicationMetrics",
            args: ["{that}"]
        },
        stopApplicationMetrics: {
            funcName: "gpii.windows.stopApplicationMetrics",
            args: ["{that}"]
        },
        startKeyboardMetrics: {
            funcName: "gpii.windows.startKeyboardMetrics",
            args: ["{that}"]
        },
        stopKeyboardMetrics: {
            funcName: "gpii.windows.stopKeyboardMetrics",
            args: ["{that}"]
        }
    },
    model: {
        config: {
            application: {
                // Milliseconds to poll the active window.
                precision: 5000
            },
            keyboard: {
                // Number of records per log line (falsey for no limit).
                maxRecords: 500,
                // Minimum typing session time, in milliseconds.
                minSession: 30000,
                // The time a session will last with no activity, in milliseconds.
                sessionTimeout: 60000
            }
        },
        state: {
            application: {},
            keyboard: {
                keyboardHookHandle: null,
                lastKeyLogged: null,
                lastKeyTime: 0,
                times: []
            }
        }
    }
});

fluid.defaults("gpii.eventLog.windows", {
    components: {
        windowsMetrics: {
            type: "gpii.windowsMetrics"
        }
    }
});

fluid.defaults("gpii.installID.windows", {
    invokers: {
        getMachineID: "gpii.windows.getMachineID"
    }
});

/**
 * Gets the machine ID - something that uniquely identifies this machine.
 *
 * This relies on the MachineGUID, which is generated when Windows is installed or when a cloned image is deployed
 * in the recommended way using sysprep.
 *
 * @return {String} The machine ID.
 */
windows.getMachineID = function () {
    var machineID = windows.readRegistryKey(
        "HKEY_LOCAL_MACHINE", "64:SOFTWARE\\Microsoft\\Cryptography", "MachineGuid", "REG_SZ").value;<commit_msg>GPII-2582: Prevent the metrics capture starting if running tests<commit_after>/*
 * Captures metrics.
 *
 * Copyright 2017 Raising the Floor - International
 *
 * Licensed under the New BSD license. You may not use this file except in
 * compliance with this License.
 *
 * The R&D leading to these results received funding from the
 * Department of Education - Grant H421A150005 (GPII-APCP). However,
 * these results do not necessarily represent the policy of the
 * Department of Education, and you should not assume endorsement by the
 * Federal Government.
 *
 * You may obtain a copy of the License at
 * https://github.com/GPII/universal/blob/master/LICENSE.txt
 */

"use strict";

var fluid = require("infusion");

fluid.registerNamespace("gpii");
var windows = fluid.registerNamespace("gpii.windows");

require("../../WindowsUtilities/WindowsUtilities.js");
var ffi = require("ffi");

fluid.defaults("gpii.windowsMetrics", {
    gradeNames: ["fluid.modelComponent", "fluid.contextAware"],
    contextAwareness: {
        platform: {
            checks: {
                test: {
                    contextValue: "{gpii.contexts.test}",
                    gradeNames: "gpii.windowsMetrics.test"
                },
                windows: {
                    contextValue: "{gpii.contexts.windows}",
                    gradeNames: "gpii.windowsMetrics.windows"
                }
            }
        }
    },
    listeners: {
        //"{eventLog}.events.onCreate": "{that}.events.onStartMetrics",
        "onDestroy.stopMetrics": "{that}.events.onStopMetrics",
        "onStartMetrics.application": "{that}.startApplicationMetrics",
        "onStopMetrics.application": "{that}.stopApplicationMetrics",
        "onStartMetrics.keyboard": "{that}.startKeyboardMetrics",
        "onStopMetrics.keyboard": "{that}.stopKeyboardMetrics"
    },
    events: {
        "onStartMetrics": null,
        "onStopMetrics": null
    },
    invokers: {
        logMetric: {
            func: "{eventLog}.logEvent",
            args: ["{eventLog}", "metrics", "{arguments}.0", "{arguments}.1"]
        },
        startApplicationMetrics: {
            funcName: "gpii.windows.startApplicationMetrics",
            args: ["{that}"]
        },
        stopApplicationMetrics: {
            funcName: "gpii.windows.stopApplicationMetrics",
            args: ["{that}"]
        },
        startKeyboardMetrics: {
            funcName: "gpii.windows.startKeyboardMetrics",
            args: ["{that}"]
        },
        stopKeyboardMetrics: {
            funcName: "gpii.windows.stopKeyboardMetrics",
            args: ["{that}"]
        }
    },
    model: {
        config: {
            application: {
                // Milliseconds to poll the active window.
                precision: 5000
            },
            keyboard: {
                // Number of records per log line (falsey for no limit).
                maxRecords: 500,
                // Minimum typing session time, in milliseconds.
                minSession: 30000,
                // The time a session will last with no activity, in milliseconds.
                sessionTimeout: 60000
            }
        },
        state: {
            application: {},
            keyboard: {
                keyboardHookHandle: null,
                lastKeyLogged: null,
                lastKeyTime: 0,
                times: []
            }
        }
    }
});

fluid.defaults("gpii.windowsMetrics.windows", {
    listeners: {
        "{eventLog}.events.onCreate": "{that}.events.onStartMetrics"
    }
});

// Don't auto-start the metrics capture when testing.
fluid.defaults("gpii.windowsMetrics.test", {
});

fluid.defaults("gpii.eventLog.windows", {
    components: {
        windowsMetrics: {
            type: "gpii.windowsMetrics"
        }
    }
});

fluid.defaults("gpii.installID.windows", {
    invokers: {
        getMachineID: "gpii.windows.getMachineID"
    }
});

/**
 * Gets the machine ID - something that uniquely identifies this machine.
 *
 * This relies on the MachineGUID, which is generated when Windows is installed or when a cloned image is deployed
 * in the recommended way using sysprep.
 *
 * @return {String} The machine ID.
 */
windows.getMachineID = function () {
    var machineID = windows.readRegistryKey(
        "HKEY_LOCAL_MACHINE", "64:SOFTWARE\\Microsoft\\Cryptography", "MachineGuid", "REG_SZ").value;
{'fraction_non_alphanumeric': 0.11790989201936204, 'fraction_numerical': 0.009184560009929253, 'mean_word_length': 2.167452830188679, 'pattern_counts': {'":': 17, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4819392', 'n_tokens_mistral': 2244, 'n_tokens_neox': 2137, 'n_words': 539}