<commit_before>{% extends "base.html" %}

{% block content %}
    <div class="main">
        <div class="response-time" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
        <div class="response-time-avg" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
        <div class="uptime" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
    </div>
{% endblock %}

{% block scripts %}
    <script src="/static/js/highcharts/highcharts.js"></script>
    <script src="/static/js/highcharts/exporting.js"></script>

    <script>
    function getKeys(obj){
        var keys = [];
        for (key in obj) {
            if (obj.hasOwnProperty(key)) { keys[keys.length] = key; }
        }
        return keys;
    }
    </script>

    <script>
    var metrics = [];
    var metrics_up = [];
    var dt_name;
    var exec_time, resp_time;

    {% for test in tests %}
        dt_name = '{{test.datasource.name}}';
        if (metrics[dt_name] === undefined) {
            metrics[dt_name] = [];
            metrics_up[dt_name] = [];
        }

        exec_time = Date.UTC({{test.execution_time.year}}, {{test.execution_time.month}} - 1,  {{test.execution_time.day}});
        exec_time += {{test.execution_time.hour}}*3600*1000 + {{test.execution_time.minute}}*60*1000 + {{test.execution_time.second}}*1000;

        {% if test.up %}
            resp_time = {{test.response_time}}/1000.0;
            metrics_up[dt_name].push(1);
        {% else %}
            resp_time = null;
            metrics_up[dt_name].push(0);
        {% endif %}

        metrics[dt_name].push([exec_time, resp_time]);
    {% endfor %}

    //get all keys in the array
    var names = getKeys(metrics);

    //get datasource titles
    var titles = [];
    {% for datasource in datasources %}
        titles['{{datasource.name}}'] = '{{datasource.title}}';
    {% endfor %}

    //calculate data
    var series = [];
    var series_avg = [];
    var series_uptime = [];
    var colors = [];
    for (var i=0; i<names.length; i++) {
        series[i] = {name: titles[names[i]], data: []};
        colors[i] = "#"+((1<<24)*Math.random()|0).toString(16);
        var sum = 0, n_of_samples = 0, sum_up = 0;

        for (var j=0; j<metrics[names[i]].length; j++) {
            var v = metrics[names[i]][j];
            series[i].data.push(v);
            if (v[1] != null) {
                sum += v[1];
                n_of_samples++;
            }
            sum_up += metrics_up[names[i]][j];
        }

        //calculate the average response time of each endpoint
        series_avg[i] = {name : titles[names[i]]};
        if (n_of_samples > 0) {
            series_avg[i].data = [Math.round(sum/n_of_samples*100)/100.0];
        } else {
            series_avg[i].data = null;
        }

        //calculate the uptime of each endpoint
        series_uptime[i] = {name : titles[names[i]]};
        series_uptime[i].data = [Math.round((sum_up*100.0) /  metrics_up[names[i]].length *100)/100.0];
    }

    //show the graphs
    $(function () {
        //response time over time chart
        $('.response-time').highcharts({
            chart: {
                type: 'spline',
                zoomType: 'xy'
            },
            title: {
                text: 'Remote endpoint response times'
            },
            xAxis: {
                type: 'datetime',
                title: {
                    text: 'Date'
                }
            },
            yAxis: {
                title: {
                    text: 'Response time (sec)'
                },
                min: 0
            },
            tooltip: {
                headerFormat: '<b>{series.name}</b><br>',
                pointFormat: '{point.x:%e. %b}: {point.y:.2f} sec'
            },
            colors: colors,
            plotOptions: {
                spline: {
                    marker: {
                        enabled: false
                    }
                }
            },

            series: series
        });

        //average response time chart
        $('.response-time-avg').highcharts({
            chart: {
                type: 'bar'
            },
            title: {
                text: "Average response time"
            },
            xAxis: {
                title: {
                    text: "Endpoint"
                },
                labels: {
                    enabled:false,//default is true
                }
            },
            yAxis: {
                title: {
                    text: "Time (sec)"
                }
            },
            colors: colors,
            tooltip: {
                headerFormat: '',
                valueSuffix: ' sec'
            },
            series: series_avg
        });

        //uptime chart
        $('.uptime').highcharts({
            chart: {
                type: 'bar'
            },
            title: {
                text: "Up-time of remote endpoints"
            },
            xAxis: {
                title: {
                    text: "Endpoint"
                },
                labels: {
                    enabled:false,//default is true
                }
            },
            yAxis: {
                title: {
                    text: "Time responsive (%)"
                },
                min: 0,
                max: 100
            },
            plotOptions: {
                bar: {
                    minPointLength:5,
                }
            },
            colors: colors,
            tooltip: {
                headerFormat: '',
                valueSuffix: ' %'
            },
            series: series_uptime
        });
    });
    </script>
{% endblock %}<commit_msg>Automate color handling by highcharts<commit_after>{% extends "base.html" %}

{% block content %}
    <div class="main">
        <div class="response-time" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
        <div class="response-time-avg" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
        <div class="uptime" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
    </div>
{% endblock %}

{% block scripts %}
    <script src="/static/js/highcharts/highcharts.js"></script>
    <script src="/static/js/highcharts/exporting.js"></script>

    <script>
    function getKeys(obj){
        var keys = [];
        for (key in obj) {
            if (obj.hasOwnProperty(key)) { keys[keys.length] = key; }
        }
        return keys;
    }
    </script>

    <script>
    var metrics = [];
    var metrics_up = [];
    var dt_name;
    var exec_time, resp_time;

    {% for test in tests %}
        dt_name = '{{test.datasource.name}}';
        if (metrics[dt_name] === undefined) {
            metrics[dt_name] = [];
            metrics_up[dt_name] = [];
        }

        exec_time = Date.UTC({{test.execution_time.year}}, {{test.execution_time.month}} - 1,  {{test.execution_time.day}});
        exec_time += {{test.execution_time.hour}}*3600*1000 + {{test.execution_time.minute}}*60*1000 + {{test.execution_time.second}}*1000;

        {% if test.up %}
            resp_time = {{test.response_time}}/1000.0;
            metrics_up[dt_name].push(1);
        {% else %}
            resp_time = null;
            metrics_up[dt_name].push(0);
        {% endif %}

        metrics[dt_name].push([exec_time, resp_time]);
    {% endfor %}

    //get all keys in the array
    var names = getKeys(metrics);

    //get datasource titles
    var titles = [];
    {% for datasource in datasources %}
        titles['{{datasource.name}}'] = '{{datasource.title}}';
    {% endfor %}

    //calculate data
    var series = [];
    var series_avg = [];
    var series_uptime = [];
    for (var i=0; i<names.length; i++) {
        series[i] = {name: titles[names[i]], data: []};
        var sum = 0, n_of_samples = 0, sum_up = 0;

        for (var j=0; j<metrics[names[i]].length; j++) {
            var v = metrics[names[i]][j];
            series[i].data.push(v);
            if (v[1] != null) {
                sum += v[1];
                n_of_samples++;
            }
            sum_up += metrics_up[names[i]][j];
        }

        //calculate the average response time of each endpoint
        series_avg[i] = {name : titles[names[i]]};
        if (n_of_samples > 0) {
            series_avg[i].data = [Math.round(sum/n_of_samples*100)/100.0];
        } else {
            series_avg[i].data = null;
        }

        //calculate the uptime of each endpoint
        series_uptime[i] = {name : titles[names[i]]};
        series_uptime[i].data = [Math.round((sum_up*100.0) /  metrics_up[names[i]].length *100)/100.0];
    }

    //show the graphs
    $(function () {
        //response time over time chart
        $('.response-time').highcharts({
            chart: {
                type: 'spline',
                zoomType: 'xy'
            },
            title: {
                text: 'Remote endpoint response times'
            },
            xAxis: {
                type: 'datetime',
                title: {
                    text: 'Date'
                }
            },
            yAxis: {
                title: {
                    text: 'Response time (sec)'
                },
                min: 0
            },
            tooltip: {
                headerFormat: '<b>{series.name}</b><br>',
                pointFormat: '{point.x:%e. %b}: {point.y:.2f} sec'
            },
            plotOptions: {
                spline: {
                    marker: {
                        enabled: false
                    }
                }
            },

            series: series
        });

        //average response time chart
        $('.response-time-avg').highcharts({
            chart: {
                type: 'bar'
            },
            title: {
                text: "Average response time"
            },
            xAxis: {
                title: {
                    text: "Endpoint"
                },
                labels: {
                    enabled:false,//default is true
                }
            },
            yAxis: {
                title: {
                    text: "Time (sec)"
                }
            },
            tooltip: {
                headerFormat: '',
                valueSuffix: ' sec'
            },
            series: series_avg
        });

        //uptime chart
        $('.uptime').highcharts({
            chart: {
                type: 'bar'
            },
            title: {
                text: "Up-time of remote endpoints"
            },
            xAxis: {
                title: {
                    text: "Endpoint"
                },
                labels: {
                    enabled:false,//default is true
                }
            },
            yAxis: {
                title: {
                    text: "Time responsive (%)"
                },
                min: 0,
                max: 100
            },
            plotOptions: {
                bar: {
                    minPointLength:5,
                }
            },
            tooltip: {
                headerFormat: '',
                valueSuffix: ' %'
            },
            series: series_uptime
        });
    });
    </script>
{% endblock %}
{'fraction_non_alphanumeric': 0.14216163583252192, 'fraction_numerical': 0.01469416659290077, 'mean_word_length': 1.2240157480314962, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 43, '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': '4044190', 'n_tokens_mistral': 3481, 'n_tokens_neox': 3131, 'n_words': 646}