/*
   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": 90.07444168734492, "KoPercent": 9.925558312655086};
    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.8205128205128205, 500, 1500, "Total"], "isController": false}, "titles": ["Apdex", "T (Toleration threshold)", "F (Frustration threshold)", "Label"], "items": [{"data": [0.8333333333333334, 500, 1500, "get /api/area-notification"], "isController": false}, {"data": [0.00641025641025641, 500, 1500, "get api/user-define/all"], "isController": false}, {"data": [1.0, 500, 1500, "delete /api/arrival-notification"], "isController": false}, {"data": [0.7152777777777778, 500, 1500, "get /api/ais/ship-track"], "isController": false}, {"data": [0.8666666666666667, 500, 1500, "get /api/port"], "isController": false}, {"data": [0.8424657534246576, 500, 1500, "get /apicall/track-ship"], "isController": false}, {"data": [0.9230769230769231, 500, 1500, "get /api/arrival-departure-schedule/all"], "isController": false}, {"data": [0.7833333333333333, 500, 1500, "post /oauth/login"], "isController": false}, {"data": [0.8666666666666667, 500, 1500, "get /api/port/suggestion"], "isController": false}, {"data": [0.8918918918918919, 500, 1500, "get /api/ais/suggestion"], "isController": false}, {"data": [0.9936974789915967, 500, 1500, "get /apicall/area-ship"], "isController": false}, {"data": [0.9680851063829787, 500, 1500, "get /apicall/single-ship"], "isController": false}, {"data": [1.0, 500, 1500, "post /api/area-notification"], "isController": false}, {"data": [0.8032786885245902, 500, 1500, "post /api/user-define"], "isController": false}, {"data": [0.8604651162790697, 500, 1500, "get /api/arrival-notification"], "isController": false}, {"data": [0.8, 500, 1500, "post /api/arrival-notification"], "isController": false}, {"data": [0.7789473684210526, 500, 1500, "get /api/user-define"], "isController": false}, {"data": [0.8787878787878788, 500, 1500, "get /api/ais/search"], "isController": false}, {"data": [0.6666666666666666, 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", 1209, 120, 9.925558312655086, 2118.35070306038, 0, 300005, 158.0, 446.0, 3767.5, 8192.800000000003, 3.73259895709518, 803.1077205212671, 2.9213962928330393], "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", 30, 5, 16.666666666666668, 105.16666666666663, 58, 175, 107.5, 153.3, 171.7, 175.0, 1.7101812792155968, 1.498078718219131, 1.3404770515049593], "isController": false}, {"data": ["get api/user-define/all", 78, 11, 14.102564102564102, 4129.128205128205, 24, 8197, 4143.5, 7509.000000000001, 7880.349999999999, 8197.0, 1.873918892946377, 5169.293997678623, 1.4551072172905053], "isController": false}, {"data": ["delete /api/arrival-notification", 4, 0, 0.0, 179.25, 147, 224, 173.0, 224.0, 224.0, 224.0, 0.8831971737690439, 0.33896141532347096, 0.7585663225877677], "isController": false}, {"data": ["get /api/ais/ship-track", 72, 4, 5.555555555555555, 28364.916666666664, 45, 300005, 219.0, 127249.20000000019, 300003.0, 300005.0, 0.2305158111435185, 77.53193954642812, 0.17904932938308205], "isController": false}, {"data": ["get /api/port", 15, 2, 13.333333333333334, 69.73333333333333, 0, 122, 84.0, 117.2, 122.0, 122.0, 0.9023641941887746, 0.9762687616555374, 0.6575626579137339], "isController": false}, {"data": ["get /apicall/track-ship", 73, 10, 13.698630136986301, 234.2876712328767, 39, 861, 229.0, 404.80000000000007, 484.4999999999997, 861.0, 1.9436604718036103, 155.4124152560706, 1.6185643288380638], "isController": false}, {"data": ["get /api/arrival-departure-schedule/all", 26, 2, 7.6923076923076925, 85.61538461538461, 0, 133, 91.0, 126.0, 130.54999999999998, 133.0, 0.797717301261007, 0.3466642568956524, 0.6414337434418432], "isController": false}, {"data": ["post /oauth/login", 150, 27, 18.0, 169.80666666666664, 26, 793, 132.0, 262.5000000000001, 779.45, 789.94, 8.06842020332419, 5.434942478887633, 4.2548309665967405], "isController": false}, {"data": ["get /api/port/suggestion", 15, 2, 13.333333333333334, 65.2, 18, 131, 66.0, 108.80000000000001, 131.0, 131.0, 0.8848513449740443, 0.3592980363673902, 0.7059224206583293], "isController": false}, {"data": ["get /api/ais/suggestion", 37, 4, 10.81081081081081, 140.0, 32, 201, 149.0, 193.8, 198.3, 201.0, 0.7727006933422437, 0.5565411006286024, 0.6265956530365049], "isController": false}, {"data": ["get /apicall/area-ship", 238, 0, 0.0, 233.72689075630257, 117, 765, 229.0, 305.1, 336.69999999999976, 556.869999999999, 4.9396040014943345, 269.6053100094434, 3.9090875482545346], "isController": false}, {"data": ["get /apicall/single-ship", 141, 4, 2.8368794326241136, 173.71631205673762, 0, 503, 176.0, 232.0, 258.8, 421.5200000000024, 3.2975513926892583, 2.7274502882434106, 2.611863328480554], "isController": false}, {"data": ["post /api/area-notification", 23, 0, 0.0, 155.82608695652178, 66, 225, 168.0, 202.60000000000002, 220.99999999999994, 225.0, 1.7558592258951065, 0.8299178372394839, 1.777479435453088], "isController": false}, {"data": ["post /api/user-define", 61, 12, 19.672131147540984, 125.6229508196721, 17, 258, 137.0, 196.00000000000006, 203.5, 258.0, 1.4151162251194729, 0.9892492489444624, 1.3827876702199229], "isController": false}, {"data": ["get /api/arrival-notification", 43, 6, 13.953488372093023, 157.51162790697674, 76, 256, 147.0, 226.8, 244.99999999999997, 256.0, 2.837534644318332, 7.221303987396067, 2.2235259667414544], "isController": false}, {"data": ["post /api/arrival-notification", 30, 6, 20.0, 122.63333333333334, 55, 234, 111.5, 188.20000000000002, 215.29999999999998, 234.0, 1.7025140457408772, 0.7199107244197265, 1.6000971851767778], "isController": false}, {"data": ["get /api/user-define", 95, 21, 22.105263157894736, 89.69473684210527, 20, 158, 89.0, 141.4, 149.59999999999997, 158.0, 1.9760379399284467, 5.472861328937515, 1.4986240860824527], "isController": false}, {"data": ["get /api/ais/search", 33, 4, 12.121212121212121, 195.72727272727272, 47, 283, 204.0, 267.0, 278.79999999999995, 283.0, 0.7795521118775395, 0.8863160552300859, 0.6368233915831994], "isController": false}, {"data": ["get /api/ais/around-ship-track", 15, 0, 0.0, 1480.8000000000002, 199, 5151, 406.0, 4605.6, 5151.0, 5151.0, 0.4675518982607069, 34.48393106921326, 0.6989231208309955], "isController": false}, {"data": ["get /api/ais/filter", 30, 0, 0.0, 61.733333333333334, 27, 126, 60.5, 97.00000000000003, 118.85, 126.0, 1.7228507436972376, 1.741357929420548, 1.3133932801642452], "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, 1.6666666666666667, 0.1654259718775848], "isController": false}, {"data": ["504/Gateway Time-out", 4, 3.3333333333333335, 0.3308519437551696], "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", 2, 1.6666666666666667, 0.1654259718775848], "isController": false}, {"data": ["401/Unauthorized", 81, 67.5, 6.699751861042183], "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}", 4, 3.3333333333333335, 0.3308519437551696], "isController": false}, {"data": ["429/Too Many Requests", 27, 22.5, 2.2332506203473947], "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", 1209, 120, "401/Unauthorized", 81, "429/Too Many Requests", 27, "504/Gateway Time-out", 4, "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}", 4, "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}, "titles": ["Sample", "#Samples", "#Errors", "Error", "#Errors", "Error", "#Errors", "Error", "#Errors", "Error", "#Errors", "Error", "#Errors"], "items": [{"data": ["get /api/area-notification", 30, 5, "401/Unauthorized", 5, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get api/user-define/all", 78, 11, "401/Unauthorized", 11, "", "", "", "", "", "", "", ""], "isController": false}, {"data": [], "isController": false}, {"data": ["get /api/ais/ship-track", 72, 4, "504/Gateway Time-out", 4, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/port", 15, 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", 73, 10, "401/Unauthorized", 10, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/arrival-departure-schedule/all", 26, 2, "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", 2, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["post /oauth/login", 150, 27, "429/Too Many Requests", 27, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/port/suggestion", 15, 2, "401/Unauthorized", 2, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/ais/suggestion", 37, 4, "401/Unauthorized", 4, "", "", "", "", "", "", "", ""], "isController": false}, {"data": [], "isController": false}, {"data": ["get /apicall/single-ship", 141, 4, "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}", 4, "", "", "", "", "", "", "", ""], "isController": false}, {"data": [], "isController": false}, {"data": ["post /api/user-define", 61, 12, "401/Unauthorized", 12, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/arrival-notification", 43, 6, "401/Unauthorized", 6, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["post /api/arrival-notification", 30, 6, "401/Unauthorized", 6, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/user-define", 95, 21, "401/Unauthorized", 21, "", "", "", "", "", "", "", ""], "isController": false}, {"data": ["get /api/ais/search", 33, 4, "401/Unauthorized", 4, "", "", "", "", "", "", "", ""], "isController": false}, {"data": [], "isController": false}, {"data": [], "isController": false}]}, function(index, item){
        return item;
    }, [[0, 0]], 0);

});
