<commit_before>// Strategies Retrieval

/**
 * Fetch url and retrieve a JSON object storing all strings representation of 
 * movement and awakeness strategies, and call update form to enable choosing 
 * strategies from a closed list.
 */
function retrieveStrategies() {
    fetch('/list-strategies')
    .then(response => response.json())
    .then(strategies => { 
        updateFormStrategiesList(strategies); 
    });
}

/**
 * Update form datalists to enable choosing strategies from a closed list.
 * @param {Array} strategies is a JSON object stirng lists of movement and awakeness strategies (as strings).
 */
function updateFormStrategiesList(strategies) {
    movementStrategies = strategies.movement;
    awakenessStrategies = strategies.awakeness;
    updateDatalistValuesFromArray('beaconMovementStrategy', movementStrategies);
    updateDatalistValuesFromArray('observerMovementStrategy', movementStrategies);
    updateDatalistValuesFromArray('observerAwakenessStrategy', awakenessStrategies);
}

/**
 * Add values stored in an array to a datalist corresponding the a given id.
 * @param {String} datalistId is the datalist id.
 * @param {Array} valuesArray is an array of values to be added to the datalist.
 */
function updateDatalistValuesFromArray(datalistId, valuesArray) {
    var valuesHtml = '';
    for (const value of valuesArray) {
        valuesHtml += '<option value="' + value + '" />';
    }

    document.getElementById(datalistId).innerHTML = valuesHtml;
}

// Inputs' Dynamic Upper Boundes

/**
 * Given two id's of HTML input tags, dynamically bound the value of the first input tag 
 * with the value of the second input tag.
 * @param {String} boundedInputId is the bounded element.
 * @param {String} boundingInputId is the bounding element.
 */
function setDynamicUpperBound(boundedInputId, boundingInputId) {
    var boundingValue = document.getElementById(boundingInputId).value;
    var boundedValue = document.getElementById(boundedInputId).value;

    document.getElementById(boundedInputId).setAttribute("max", boundingValue);

    if (boundedValue > boundingValue) {
        document.getElementById(boundedInputId).value = boundingValue;
    }
}

/**
 * Verify the following constrains are kept:
 * awakenessCycle <= roundsNum
 * awakenessDuration <= awakenessCycle
 */
function setAllDynamicUpperBounds() {
    setDynamicUpperBound('awakenessCycle', 'roundsNum');
    setDynamicUpperBound('awakenessDuration', 'awakenessCycle');
}<commit_msg>fix typo.<commit_after>// Strategies Retrieval

/**
 * Fetch url and retrieve a JSON object storing all strings representation of 
 * movement and awakeness strategies, and call update form to enable choosing 
 * strategies from a closed list.
 */
function retrieveStrategies() {
    fetch('/list-strategies')
    .then(response => response.json())
    .then(strategies => { 
        updateFormStrategiesList(strategies); 
    });
}

/**
 * Update form datalists to enable choosing strategies from a closed list.
 * @param {Array} strategies is a JSON object stirng lists of movement and awakeness strategies (as strings).
 */
function updateFormStrategiesList(strategies) {
    movementStrategies = strategies.movement;
    awakenessStrategies = strategies.awakeness;
    updateDatalistValuesFromArray('beaconMovementStrategy', movementStrategies);
    updateDatalistValuesFromArray('observerMovementStrategy', movementStrategies);
    updateDatalistValuesFromArray('observerAwakenessStrategy', awakenessStrategies);
}

/**
 * Add values stored in an array to a datalist corresponding to a given id.
 * @param {String} datalistId is the datalist id.
 * @param {Array} valuesArray is an array of values to be added to the datalist.
 */
function updateDatalistValuesFromArray(datalistId, valuesArray) {
    var valuesHtml = '';
    for (const value of valuesArray) {
        valuesHtml += '<option value="' + value + '" />';
    }

    document.getElementById(datalistId).innerHTML = valuesHtml;
}

// Inputs' Dynamic Upper Boundes

/**
 * Given two id's of HTML input tags, dynamically bound the value of the first input tag 
 * with the value of the second input tag.
 * @param {String} boundedInputId is the bounded element.
 * @param {String} boundingInputId is the bounding element.
 */
function setDynamicUpperBound(boundedInputId, boundingInputId) {
    var boundingValue = document.getElementById(boundingInputId).value;
    var boundedValue = document.getElementById(boundedInputId).value;

    document.getElementById(boundedInputId).setAttribute("max", boundingValue);

    if (boundedValue > boundingValue) {
        document.getElementById(boundedInputId).value = boundingValue;
    }
}

/**
 * Verify the following constrains are kept:
 * awakenessCycle <= roundsNum
 * awakenessDuration <= awakenessCycle
 */
function setAllDynamicUpperBounds() {
    setDynamicUpperBound('awakenessCycle', 'roundsNum');
    setDynamicUpperBound('awakenessDuration', 'awakenessCycle');
}
{'fraction_non_alphanumeric': 0.0931027548763322, 'fraction_numerical': 0.0, 'mean_word_length': 4.633069082672707, 'pattern_counts': {'":': 0, '<': 9, '<?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': '799736', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1323, 'n_words': 405}