<commit_before>'use strict';

const url = '/search';

postRequestShow('The Matrix');

$('#search-button').on('click', function () {
    let searchShow = document.getElementById('search-input').value;
    postRequestShow(searchShow);
});

function getTime() {
    let currentDate = new Date();
    let time = {
        'hour': currentDate.getHours() > 12 ? currentDate.getHours() - 12 : currentDate.getHours(),
        'minute': currentDate.getMinutes(),
        'meridiem': currentDate.getHours() < 12 ? 'AM' : 'PM'
    };
    // updates the time displayed on the page
    document.getElementById('time').innerHTML = time.hour + ':' + time.minute + ' ' + time.meridiem;

    return time;
}

function postRequestShow(show) {
    let time = getTime();
    let body = {
        'show': show
    };

    function postSuccess(data) {
        if (typeof data !== 'undefined' && data.length !== 0) {
            let showing = determineCurrentlyShowing(data, time);
            console.log(showing);
            let resultStr = '';
            // the array of currently showing instances of the show
            let showingCurrently = showing.current;
            // the array of later showing instances of the show
            let showingLater = showing.later;

            if (typeof showingCurrently !== 'undefined' && showingCurrently.length !== 0) {
                resultStr += '"' + show + '" is currently showing on the following channels:';
                for (let i = 0; i < showingCurrently.length; i++) {
                    resultStr += ' ' + showingCurrently[i].channel;
                }
            } else {
                resultStr += 'Well, technically "' + show + '" isn\'t currently on, but it will be showing later at the following times:';
                let timeStr = '';
                for (let i = 0; i < showingLater.length; i++) {
                    timeStr = showingLater[i].time.hour + ':' + showingLater[i].time.minute + showingLater[i].time.meridiem;
                    resultStr += '\n' + timeStr + ' on ' + showingLater[i].channel;
                }
            }

            document.getElementById('status').innerHTML = 'Yes.';
            document.getElementById('status-details').innerHTML = resultStr;
        } else {
            document.getElementById('status').innerHTML = 'No.';
        }

        document.getElementById('search-input').value = '';
    }

    $.ajax({
        url: url,
        type: 'POST',
        data: JSON.stringify(body),
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            postSuccess(data);
        }
    });
}

function determineCurrentlyShowing(showingResults, currentTime) {
    let results = {
        'current': [],
        'later': []
    };

    // iterates through each listing result
    for (let i = 0; i < showingResults.length; i++) {
        let time = showingResults[i].time;<commit_msg>Fix changing of status details on new searches<commit_after>'use strict';

const url = '/search';

postRequestShow('The Matrix');

$('#search-button').on('click', function () {
    let searchShow = document.getElementById('search-input').value;
    postRequestShow(searchShow);
});

function getTime() {
    let currentDate = new Date();
    let time = {
        'hour': currentDate.getHours() > 12 ? currentDate.getHours() - 12 : currentDate.getHours(),
        'minute': currentDate.getMinutes(),
        'meridiem': currentDate.getHours() < 12 ? 'AM' : 'PM'
    };
    // updates the time displayed on the page
    document.getElementById('time').innerHTML = time.hour + ':' + time.minute + ' ' + time.meridiem;

    return time;
}

function postRequestShow(show) {
    let time = getTime();
    let body = {
        'show': show
    };

    function postSuccess(data) {
        let statusElem = document.getElementById('status');
        let statusDetailsElem = document.getElementById('status-details');

        if (typeof data !== 'undefined' && data.length !== 0) {
            let showing = determineCurrentlyShowing(data, time);
            let resultStr = '';
            // the array of currently showing instances of the show
            let showingCurrently = showing.current;
            // the array of later showing instances of the show
            let showingLater = showing.later;

            if (typeof showingCurrently !== 'undefined' && showingCurrently.length !== 0) {
                resultStr += '"' + show + '" is currently showing on the following channels:';
                for (let i = 0; i < showingCurrently.length; i++) {
                    resultStr += ' ' + showingCurrently[i].channel;
                }
            } else {
                resultStr += 'Well, technically "' + show + '" isn\'t currently on, but it will be showing later at the following times:';
                let timeStr = '';
                for (let i = 0; i < showingLater.length; i++) {
                    timeStr = showingLater[i].time.hour + ':' + showingLater[i].time.minute + showingLater[i].time.meridiem;
                    resultStr += '\n' + timeStr + ' on ' + showingLater[i].channel;
                }
            }

            statusElem.innerHTML = 'Yes.';
            statusDetailsElem.innerHTML = resultStr;
        } else {
            statusElem.innerHTML = 'No.';
            statusDetailsElem.innerHTML = '"' + show + '" is not currently on, nor will it be within the next 3 hours :(';
        }

        document.getElementById('search-input').value = '';
    }

    $.ajax({
        url: url,
        type: 'POST',
        data: JSON.stringify(body),
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            postSuccess(data);
        }
    });
}

function determineCurrentlyShowing(showingResults, currentTime) {
    let results = {
        'current': [],
        'later': []
    };

    // iterates through each listing result
    for (let i = 0; i < showingResults.length; i++) {
        let time = showingResults[i].time;
{'fraction_non_alphanumeric': 0.13504132231404958, 'fraction_numerical': 0.0038016528925619835, 'mean_word_length': 2.1287487073422957, 'pattern_counts': {'":': 0, '<': 11, '<?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': '6286347', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1575, 'n_words': 426}