/*
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
var showControllersOnly = false;
var seriesFilter = "";
var filtersOnlySampleSeries = true;

/*
 * Add header in statistics table to group metrics by category
 * format
 *
 */
function summaryTableHeader(header) {
    var newRow = header.insertRow(-1);
    newRow.className = "tablesorter-no-sort";
    var cell = document.createElement('th');
    cell.setAttribute("data-sorter", false);
    cell.colSpan = 1;
    cell.innerHTML = "Requests";
    newRow.appendChild(cell);

    cell = document.createElement('th');
    cell.setAttribute("data-sorter", false);
    cell.colSpan = 3;
    cell.innerHTML = "Executions";
    newRow.appendChild(cell);

    cell = document.createElement('th');
    cell.setAttribute("data-sorter", false);
    cell.colSpan = 7;
    cell.innerHTML = "Response Times (ms)";
    newRow.appendChild(cell);

    cell = document.createElement('th');
    cell.setAttribute("data-sorter", false);
    cell.colSpan = 1;
    cell.innerHTML = "Throughput";
    newRow.appendChild(cell);

    cell = document.createElement('th');
    cell.setAttribute("data-sorter", false);
    cell.colSpan = 2;
    cell.innerHTML = "Network (KB/sec)";
    newRow.appendChild(cell);
}

/*
 * Populates the table identified by id parameter with the specified data and
 * format
 *
 */
function createTable(table, info, formatter, defaultSorts, seriesIndex, headerCreator) {
    var tableRef = table[0];

    // Create header and populate it with data.titles array
    var header = tableRef.createTHead();

    // Call callback is available
    if(headerCreator) {
        headerCreator(header);
    }

    var newRow = header.insertRow(-1);
    for (var index = 0; index < info.titles.length; index++) {
        var cell = document.createElement('th');
        cell.innerHTML = info.titles[index];
        newRow.appendChild(cell);
    }

    var tBody;

    // Create overall body if defined
    if(info.overall){
        tBody = document.createElement('tbody');
        tBody.className = "tablesorter-no-sort";
        tableRef.appendChild(tBody);
        var newRow = tBody.insertRow(-1);
        var data = info.overall.data;
        for(var index=0;index < data.length; index++){
            var cell = newRow.insertCell(-1);
            cell.innerHTML = formatter ? formatter(index, data[index]): data[index];
        }
    }

    // Create regular body
    tBody = document.createElement('tbody');
    tableRef.appendChild(tBody);

    var regexp;
    if(seriesFilter) {
        regexp = new RegExp(seriesFilter, 'i');
    }
    // Populate body with data.items array
    for(var index=0; index < info.items.length; index++){
        var item = info.items[index];
        if((!regexp || filtersOnlySampleSeries && !info.supportsControllersDiscrimination || regexp.test(item.data[seriesIndex]))
                &&
                (!showControllersOnly || !info.supportsControllersDiscrimination || item.isController)){
            if(item.data.length > 0) {
                var newRow = tBody.insertRow(-1);
                for(var col=0; col < item.data.length; col++){
                    var cell = newRow.insertCell(-1);
                    cell.innerHTML = formatter ? formatter(col, item.data[col]) : item.data[col];
                }
            }
        }
    }

    // Add support of columns sort
    table.tablesorter({sortList : defaultSorts});
}

$(document).ready(function() {

    // Customize table sorter default options
    $.extend( $.tablesorter.defaults, {
        theme: 'blue',
        cssInfoBlock: "tablesorter-no-sort",
        widthFixed: true,
        widgets: ['zebra']
    });

    var data = {"OkPercent": 88.0817167554528, "KoPercent": 11.91828324454719};
    var dataset = [
        {
            "label" : "FAIL",
            "data" : data.KoPercent,
            "color" : "#FF6347"
        },
        {
            "label" : "PASS",
            "data" : data.OkPercent,
            "color" : "#9ACD32"
        }];
    $.plot($("#flot-requests-summary"), dataset, {
        series : {
            pie : {
                show : true,
                radius : 1,
                label : {
                    show : true,
                    radius : 3 / 4,
                    formatter : function(label, series) {
                        return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'
                            + label
                            + '<br/>'
                            + Math.round10(series.percent, -2)
                            + '%</div>';
                    },
                    background : {
                        opacity : 0.5,
                        color : '#000'
                    }
                }
            }
        },
        legend : {
            show : true
        }
    });

    // Creates APDEX table
    createTable($("#apdexTable"), {"supportsControllersDiscrimination": true, "overall": {"data": [0.8058975776459946, 500, 1500, "Total"], "isController": false}, "titles": ["Apdex", "T (Toleration threshold)", "F (Frustration threshold)", "Label"], "items": [{"data": [0.7560669456066945, 500, 1500, "get /api/area-notification"], "isController": false}, {"data": [0.0534167468719923, 500, 1500, "get api/user-define/all"], "isController": false}, {"data": [1.0, 500, 1500, "delete /api/arrival-notification"], "isController": false}, {"data": [0.8184180138568129, 500, 1500, "get /api/ais/ship-track"], "isController": false}, {"data": [0.978494623655914, 500, 1500, "get /api/port"], "isController": false}, {"data": [0.8155354008191925, 500, 1500, "get /apicall/track-ship"], "isController": false}, {"data": [0.7962962962962963, 500, 1500, "get /api/arrival-departure-schedule/all"], "isController": false}, {"data": [0.78, 500, 1500, "post /oauth/login"], "isController": false}, {"data": [0.978494623655914, 500, 1500, "get /api/port/suggestion"], "isController": false}, {"data": [0.7963386727688787, 500, 1500, "get /api/ais/suggestion"], "isController": false}, {"data": [0.9887488748874887, 500, 1500, "get /apicall/area-ship"], "isController": false}, {"data": [0.9468251214434421, 500, 1500, "get /apicall/single-ship"], "isController": false}, {"data": [0.9994407158836689, 500, 1500, "post /api/area-notification"], "isController": false}, {"data": [0.7695749440715883, 500, 1500, "post /api/user-define"], "isController": false}, {"data": [0.7422907488986784, 500, 1500, "get /api/arrival-notification"], "isController": false}, {"data": [0.7862001943634597, 500, 1500, "post /api/arrival-notification"], "isController": false}, {"data": [0.8698727015558698, 500, 1500, "delete /api/user-define"], "isController": false}, {"data": [0.7648766328011611, 500, 1500, "get /api/user-define"], "isController": false}, {"data": [0.7977011494252874, 500, 1500, "get /api/ais/search"], "isController": false}, {"data": [0.49312714776632305, 500, 1500, "get /api/ais/around-ship-track"], "isController": false}, {"data": [1.0, 500, 1500, "get /api/ais/filter"], "isController": false}]}, function(index, item){
        switch(index){
            case 0:
                item = item.toFixed(3);
                break;
            case 1:
            case 2:
                item = formatDuration(item);
                break;
        }
        return item;
    }, [[0, 0]], 3);

    // Create statistics table
    createTable($("#statisticsTable"), {"supportsControllersDiscrimination": true, "overall": {"data": ["Total", 39796, 4743, 11.91828324454719, 1433.4531108654242, 0, 300056, 128.0, 322.90000000000146, 2202.650000000005, 5978.960000000006, 19.2729680109218, 5167.796867686403, 15.193835894855635], "isController": false}, "titles": ["Label", "#Samples", "FAIL", "Error %", "Average", "Min", "Max", "Median", "90th pct", "95th pct", "99th pct", "Transactions/s", "Received", "Sent"], "items": [{"data": ["get /api/area-notification", 1195, 291, 24.351464435146443, 81.98744769874477, 14, 503, 77.0, 135.4000000000001, 156.4000000000001, 223.15999999999985, 0.6743160629421849, 0.5612327830744975, 0.5099013765146719], "isController": false}, {"data": ["get api/user-define/all", 3117, 510, 16.361886429258902, 3793.05710619185, 13, 23456, 2659.0, 8767.60000000001, 11295.3, 18015.300000000017, 1.7541756640626978, 5360.171315604137, 1.3478424829956952], "isController": false}, {"data": ["delete /api/arrival-notification", 711, 0, 0.0, 138.55414908579468, 34, 361, 143.0, 206.80000000000007, 231.79999999999995, 288.76, 0.4085507194744808, 0.14272037120223088, 0.35116336756693395], "isController": false}, {"data": ["get /api/ais/ship-track", 1732, 102, 5.8891454965357966, 22646.584872979198, 16, 300056, 92.0, 12346.90000000001, 300001.0, 300003.0, 0.8435177221514961, 226.01398671216077, 0.5624466104905942], "isController": false}, {"data": ["get /api/port", 93, 2, 2.150537634408602, 95.51612903225812, 0, 235, 92.0, 164.00000000000009, 186.09999999999997, 235.0, 0.0584475574577198, 0.06275723013568632, 0.04808580812389625], "isController": false}, {"data": ["get /apicall/track-ship", 3418, 575, 16.82270333528379, 192.88063194850776, 16, 5171, 148.0, 362.0, 438.0, 727.2099999999978, 1.923545536760936, 112.88708559865572, 1.579997399478144], "isController": false}, {"data": ["get /api/arrival-departure-schedule/all", 1296, 264, 20.37037037037037, 63.02700617283954, 0, 308, 58.0, 126.0, 147.14999999999986, 220.02999999999997, 0.7334701798530004, 0.39665965455591945, 0.5086656463309795], "isController": false}, {"data": ["post /oauth/login", 150, 26, 17.333333333333332, 185.1266666666667, 22, 916, 136.0, 395.70000000000005, 763.9999999999995, 906.3100000000002, 8.187772925764191, 5.530478131823144, 4.31777087882096], "isController": false}, {"data": ["get /api/port/suggestion", 93, 2, 2.150537634408602, 86.94623655913975, 30, 286, 72.0, 136.60000000000002, 178.89999999999998, 286.0, 0.058433125173178814, 0.02421153274328443, 0.04897713462332311], "isController": false}, {"data": ["get /api/ais/suggestion", 1311, 267, 20.366132723112127, 128.58657513348592, 17, 436, 130.0, 189.0, 214.0, 281.5199999999995, 0.7334101614509326, 0.5032623395840093, 0.5694775317964913], "isController": false}, {"data": ["get /apicall/area-ship", 7777, 0, 0.0, 231.632120354893, 63, 5307, 204.0, 327.0, 391.09999999999945, 617.4400000000005, 4.349798282788904, 246.1311454988509, 3.3108922906858833], "isController": false}, {"data": ["get /apicall/single-ship", 5764, 264, 4.580152671755725, 169.97970159611384, 0, 5151, 150.0, 252.5, 305.0, 538.4500000000025, 3.233613422749514, 2.6843594032779885, 2.483873635468711], "isController": false}, {"data": ["post /api/area-notification", 894, 0, 0.0, 127.5917225950782, 34, 664, 125.5, 192.5, 216.0, 296.39999999999964, 0.5108965548770905, 0.24159062359810612, 0.5172279584782254], "isController": false}, {"data": ["post /api/user-define", 2235, 515, 23.042505592841163, 114.24250559284101, 13, 384, 122.0, 187.4000000000001, 208.0, 273.27999999999975, 1.2536114948601929, 0.8606999509633178, 1.2096958733605594], "isController": false}, {"data": ["get /api/arrival-notification", 2043, 520, 25.45276554087127, 118.11894273127763, 0, 3643, 107.0, 210.0, 249.0, 415.0, 1.166314907308507, 2.368414283953722, 0.8268984881079267], "isController": false}, {"data": ["post /api/arrival-notification", 1029, 219, 21.282798833819243, 123.92711370262384, 14, 1283, 130.0, 204.0, 226.0, 310.4000000000001, 0.585718042506395, 0.21066752058978222, 0.5477960321942854], "isController": false}, {"data": ["delete /api/user-define", 707, 92, 13.012729844413013, 108.60961810466772, 24, 313, 109.0, 173.0, 191.0, 236.83999999999992, 0.41010517718631884, 0.14068192330192092, 0.3488954069742823], "isController": false}, {"data": ["get /api/user-define", 3445, 810, 23.51233671988389, 86.48359941944872, 13, 367, 84.0, 142.0, 164.0, 209.53999999999996, 1.926817836572289, 5.254146381245938, 1.4515170229741565], "isController": false}, {"data": ["get /api/ais/search", 1305, 264, 20.229885057471265, 187.49961685823754, 14, 418, 205.0, 274.4000000000001, 294.70000000000005, 350.7000000000003, 0.7324066658547522, 0.7830687397329774, 0.5769253552382791], "isController": false}, {"data": ["get /api/ais/around-ship-track", 291, 20, 6.8728522336769755, 2229.8281786941575, 16, 16125, 518.0, 6614.600000000001, 8155.399999999993, 12022.199999999933, 0.1663528257685672, 8.559670849711368, 0.2470243218478426], "isController": false}, {"data": ["get /api/ais/filter", 1190, 0, 0.0, 50.76638655462174, 14, 256, 44.0, 96.0, 117.0, 169.4499999999996, 0.6733301835814942, 0.680563222662936, 0.49464483247375285], "isController": false}]}, function(index, item){
        switch(index){
            // Errors pct
            case 3:
                item = item.toFixed(2) + '%';
                break;
            // Mean
            case 4:
            // Mean
            case 7:
            // Median
            case 8:
            // Percentile 1
            case 9:
            // Percentile 2
            case 10:
            // Percentile 3
            case 11:
            // Throughput
            case 12:
            // Kbytes/s
            case 13:
            // Sent Kbytes/s
                item = item.toFixed(2);
                break;
        }
        return item;
    }, [[0, 0]], 0, summaryTableHeader);

    // Create error table
    createTable($("#errorsTable"), {"supportsControllersDiscrimination": false, "titles": ["Type of error", "Number of errors", "% in errors", "% in all samples"], "items": [{"data": ["Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in path at index 45: https://api-gateway.marine-vue.com/api/port/${ediCode}", 2, 0.0421674045962471, 0.00502563071665494], "isController": false}, {"data": ["400/Bad Request", 20, 0.421674045962471, 0.0502563071665494], "isController": false}, {"data": ["Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in path at index 61: https://api-gateway.marine-vue.com/api/arrival-notification/${ARRIVAL_ID}", 215, 4.532995994096563, 0.5402553020404061], "isController": false}, {"data": ["504/Gateway Time-out", 101, 2.1294539321104784, 0.25379435119107446], "isController": false}, {"data": ["502/Bad Gateway", 1, 0.02108370229812355, 0.00251281535832747], "isController": false}, {"data": ["Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in query at index 76: https://api-gateway.marine-vue.com/api/arrival-departure-schedule/all?mmsi=${shipMmsi}&amp;page=1&amp;limit=5", 264, 5.566097406704618, 0.6633832545984522], "isController": false}, {"data": ["500/Internal Server Error", 92, 1.9397006114273667, 0.23117901296612725], "isController": false}, {"data": ["401/Unauthorized", 3668, 77.33502002951718, 9.21700673434516], "isController": false}, {"data": ["Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in query at index 77: https://api-gateway.marine-vue.com/apicall/single-ship?isSearch=true&amp;shipId=${shipMmsi}", 264, 5.566097406704618, 0.6633832545984522], "isController": false}, {"data": ["404/Not Found", 90, 1.8975332068311195, 0.22615338224947232], "isController": false}, {"data": ["429/Too Many Requests", 26, 0.5481762597512123, 0.06533319931651423], "isController": false}]}, function(index, item){
        switch(index){
            case 2:
            case 3:
                item = item.toFixed(2) + '%';
                break;
        }
        return item;
    }, [[1, 1]]);

        // Create top5 errors by sampler
    createTable($("#top5ErrorsBySamplerTable"), {"supportsControllersDiscrimination": false, "overall": {"data": ["Total", 39796, 4743, "401/Unauthorized", 3668, "Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in query at index 76: https://api-gateway.marine-vue.com/api/arrival-departure-schedule/all?mmsi=${shipMmsi}&amp;page=1&amp;limit=5", 264, "Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in query at index 77: https://api-gateway.marine-vue.com/apicall/single-ship?isSearch=true&amp;shipId=${shipMmsi}", 264, "Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in path at index 61: https://api-gateway.marine-vue.com/api/arrival-notification/${ARRIVAL_ID}", 215, "504/Gateway Time-out", 101], "isController": false}, "titles": ["Sample", "#Samples", "#Errors", "Error", "#Errors", "Error", "#Errors", "Error", "#Errors", "Error", "#Errors", "Error", "#Errors"], "items": [{"data": ["get /api/area-notification", 1195, 291, "401/Unauthorized", 291, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get api/user-define/all", 3117, 510, "401/Unauthorized", 510, "", "", "", "", "", "", "", ""], "isController": false}, {"data": [], "isController": false}, {"data": ["get /api/ais/ship-track", 1732, 102, "504/Gateway Time-out", 101, "502/Bad Gateway", 1, "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/port", 93, 2, "Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in path at index 45: https://api-gateway.marine-vue.com/api/port/${ediCode}", 2, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /apicall/track-ship", 3418, 575, "401/Unauthorized", 575, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/arrival-departure-schedule/all", 1296, 264, "Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in query at index 76: https://api-gateway.marine-vue.com/api/arrival-departure-schedule/all?mmsi=${shipMmsi}&amp;page=1&amp;limit=5", 264, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["post /oauth/login", 150, 26, "429/Too Many Requests", 26, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/port/suggestion", 93, 2, "401/Unauthorized", 2, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/ais/suggestion", 1311, 267, "401/Unauthorized", 267, "", "", "", "", "", "", "", ""], "isController": false}, {"data": [], "isController": false}, {"data": ["get /apicall/single-ship", 5764, 264, "Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in query at index 77: https://api-gateway.marine-vue.com/apicall/single-ship?isSearch=true&amp;shipId=${shipMmsi}", 264, "", "", "", "", "", "", "", ""], "isController": false}, {"data": [], "isController": false}, {"data": ["post /api/user-define", 2235, 515, "401/Unauthorized", 515, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/arrival-notification", 2043, 520, "Non HTTP response code: java.net.URISyntaxException/Non HTTP response message: Illegal character in path at index 61: https://api-gateway.marine-vue.com/api/arrival-notification/${ARRIVAL_ID}", 215, "401/Unauthorized", 215, "404/Not Found", 90, "", "", "", ""], "isController": false}, {"data": ["post /api/arrival-notification", 1029, 219, "401/Unauthorized", 219, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["delete /api/user-define", 707, 92, "500/Internal Server Error", 92, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/user-define", 3445, 810, "401/Unauthorized", 810, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/ais/search", 1305, 264, "401/Unauthorized", 264, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/ais/around-ship-track", 291, 20, "400/Bad Request", 20, "", "", "", "", "", "", "", ""], "isController": false}, {"data": [], "isController": false}]}, function(index, item){
        return item;
    }, [[0, 0]], 0);

});
