<commit_before>



$(document).ready(function() {

    var MeetingCode;
    var adminCode;
    var started;

    initTimer();

    initStartEndButton();

    if (typeof(Storage) != "undefined") {
        MeetingCode = localStorage.getItem("MeetingCode");
        adminCode = localStorage.getItem("meetingCodeControl");
    } else {
        MeetingCode = "dupa";
    }

    $("#code_1").val(MeetingCode.charAt(0));
    $("#code_2").val(MeetingCode.charAt(1));
    $("#code_3").val(MeetingCode.charAt(2));
    $("#code_4").val(MeetingCode.charAt(3));
    $("#code_5").val(MeetingCode.charAt(4));

    $("#adminCode_1").val(adminCode.charAt(0));
    $("#adminCode_2").val(adminCode.charAt(1));
    $("#adminCode_3").val(adminCode.charAt(2));
    $("#adminCode_4").val(adminCode.charAt(3));
    $("#adminCode_5").val(adminCode.charAt(4));

    getVotes(MeetingCode);

    setInterval(function(){getVotes(MeetingCode)}, 30000);

    $("#changeTime").click(function() {startAndStop(adminCode)});

    
});


function getVotes(MeetingCode) {
    $.ajax({
        type: "GET",
        url: "http://antivps.pl:3033/vote/average/" + MeetingCode,
        success: function(data) {
            refreshProgressBar(data.value);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            alert("Error, status: " + textStatus + ", errorThrown: " + errorThrown);
        }
    });

    $.ajax({
        type: "GET",
        url: "http://antivps.pl:3033/vote/" + MeetingCode,
        success: function(data) {
            drawHistogram(data);
        },
        error: function(jqXHRm, textStatus, errorThrown) {
            if (jqXHR.status === 0) {
                alert("Verify network.");
            } else if (jqXHR.status == 404) {
                alert("Requested page not found.");
            } else if (jqXHR.status == 500) {
                alert("Internal Server Error.");
            } else if (textStatus === "timeout") {
                alert("Time out error.");
            } else {
                alert("Uncaught Error.\n" + jqXHR.responseText);
            }
        }
    });
};


function refreshProgressBar(average) {
    var gradePercent = ((average + 2) / 4) * 100;
            
    $("#meetingGrade").attr('style', "width: " + gradePercent + "%");

    switch (true) {
        case (gradePercent <= 20):
            $('#meetingGrade').attr('class', "progress-bar progress-bar-danger");
            break;
        case (gradePercent < 40 && gradePercent > 20):
            $('#meetingGrade').attr('class', "progress-bar progress-bar-warning");
            break;
        case (gradePercent <= 60 && gradePercent >= 40):
            $('#meetingGrade').attr('class', "progress-bar progress-bar-info");
            break;
        case (gradePercent < 80 && gradePercent > 60):
            $('#meetingGrade').attr('class', "progress-bar progress-bar-success");
            break;
        case (gradePercent >= 80):
            $('#meetingGrade').attr('class', "progress-bar progress-bar-success");
            break;
        default:
            $('#meetingGrade').attr('class', "progress-bar");
    }
};

function drawHistogram(data) {

    //google charts..
    google.load("visualization", "1", {
        packages: ["corechart"]
    });
    google.setOnLoadCallback(drawHistogram);

    var data = google.visualization.arrayToDataTable(
        convertJsonToGoogleFormat(data));

    var options = {
        title: "Histogram",
        width: "100%",
        height: "100%",
        bar: {
            groupWidth: "85%"
        },
        // chartArea: {
        //     width: "80%",
        //     height: "70%"
        // },
        legend: {
            position: "none"
        },
        dataOpacity: 0.9,
    };

    var chartDiv = document.getElementById('hist_div');

    var chart = new google.visualization.ColumnChart(chartDiv);

    chart.draw(data, options);
}


/**
 * Function converting the JSON object returned by Focus Meter Server to an array
 * needed by Google Charts API.
 * @param votesData - object with number of votes
 * @return an array.
 */
function convertJsonToGoogleFormat(votesData) {
    var resultArray = [['Grade', 'Votes', {role: 'style'}]];

    resultArray.push(['Disaster', votesData.disaster, 'color: #E0553B']);
    resultArray.push(['Boring', votesData.boring, 'color: #E58955']);
    resultArray.push(['OK', votesData.ok, 'color: #27B0F4']);
    resultArray.push(['Great', votesData.great, 'color: #458BF6']);
    resultArray.push(['Awesome', votesData.awesome, 'color: #0FC085']);

    return resultArray;<commit_msg>Try to redraw histogram after resize<commit_after>



$(document).ready(function() {

    var MeetingCode;
    var adminCode;
    var started;

    initTimer();

    initStartEndButton();

    if (typeof(Storage) != "undefined") {
        MeetingCode = localStorage.getItem("MeetingCode");
        adminCode = localStorage.getItem("meetingCodeControl");
    } else {
        MeetingCode = "dupa";
    }

    $("#code_1").val(MeetingCode.charAt(0));
    $("#code_2").val(MeetingCode.charAt(1));
    $("#code_3").val(MeetingCode.charAt(2));
    $("#code_4").val(MeetingCode.charAt(3));
    $("#code_5").val(MeetingCode.charAt(4));

    $("#adminCode_1").val(adminCode.charAt(0));
    $("#adminCode_2").val(adminCode.charAt(1));
    $("#adminCode_3").val(adminCode.charAt(2));
    $("#adminCode_4").val(adminCode.charAt(3));
    $("#adminCode_5").val(adminCode.charAt(4));

    getVotes(MeetingCode);

    setInterval(function(){getVotes(MeetingCode)}, 30000);

    $("#changeTime").click(function() {startAndStop(adminCode)});

    $(window).resize(function() {
        getVotes(MeetingCode);
    })

    
});


function getVotes(MeetingCode) {
    $.ajax({
        type: "GET",
        url: "http://antivps.pl:3033/vote/average/" + MeetingCode,
        success: function(data) {
            refreshProgressBar(data.value);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            alert("Error, status: " + textStatus + ", errorThrown: " + errorThrown);
        }
    });

    $.ajax({
        type: "GET",
        url: "http://antivps.pl:3033/vote/" + MeetingCode,
        success: function(data) {
            drawHistogram(data);
        },
        error: function(jqXHRm, textStatus, errorThrown) {
            if (jqXHR.status === 0) {
                alert("Verify network.");
            } else if (jqXHR.status == 404) {
                alert("Requested page not found.");
            } else if (jqXHR.status == 500) {
                alert("Internal Server Error.");
            } else if (textStatus === "timeout") {
                alert("Time out error.");
            } else {
                alert("Uncaught Error.\n" + jqXHR.responseText);
            }
        }
    });
};


function refreshProgressBar(average) {
    var gradePercent = ((average + 2) / 4) * 100;
            
    $("#meetingGrade").attr('style', "width: " + gradePercent + "%");

    switch (true) {
        case (gradePercent <= 20):
            $('#meetingGrade').attr('class', "progress-bar progress-bar-danger");
            break;
        case (gradePercent < 40 && gradePercent > 20):
            $('#meetingGrade').attr('class', "progress-bar progress-bar-warning");
            break;
        case (gradePercent <= 60 && gradePercent >= 40):
            $('#meetingGrade').attr('class', "progress-bar progress-bar-info");
            break;
        case (gradePercent < 80 && gradePercent > 60):
            $('#meetingGrade').attr('class', "progress-bar progress-bar-success");
            break;
        case (gradePercent >= 80):
            $('#meetingGrade').attr('class', "progress-bar progress-bar-success");
            break;
        default:
            $('#meetingGrade').attr('class', "progress-bar");
    }
};

function drawHistogram(data) {

    //google charts..
    google.load("visualization", "1", {
        packages: ["corechart"]
    });
    google.setOnLoadCallback(drawHistogram);

    var data = google.visualization.arrayToDataTable(
        convertJsonToGoogleFormat(data));

    var options = {
        title: "Histogram",
        width: "100%",
        height: "100%",
        bar: {
            groupWidth: "85%"
        },
        chartArea: {
            width: "80%",
            height: "70%"
        },
        legend: {
            position: "none"
        },
        dataOpacity: 0.9,
    };

    var chartDiv = document.getElementById('hist_div');

    var chart = new google.visualization.ColumnChart(chartDiv);

    chart.draw(data, options);
}


/**
 * Function converting the JSON object returned by Focus Meter Server to an array
 * needed by Google Charts API.
 * @param votesData - object with number of votes
 * @return an array.
 */
function convertJsonToGoogleFormat(votesData) {
    var resultArray = [['Grade', 'Votes', {role: 'style'}]];

    resultArray.push(['Disaster', votesData.disaster, 'color: #E0553B']);
    resultArray.push(['Boring', votesData.boring, 'color: #E58955']);
    resultArray.push(['OK', votesData.ok, 'color: #27B0F4']);
    resultArray.push(['Great', votesData.great, 'color: #458BF6']);
    resultArray.push(['Awesome', votesData.awesome, 'color: #0FC085']);

    return resultArray;
{'fraction_non_alphanumeric': 0.16961779313323255, 'fraction_numerical': 0.020945800043187218, 'mean_word_length': 2.461509715994021, 'pattern_counts': {'":': 0, '<': 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': '7141599', 'n_tokens_mistral': 2951, 'n_tokens_neox': 2776, 'n_words': 520}