<commit_before>var indexStatsPrevs = {};
var indexStatsAggsPrevs = {};

var indexStatsLabels = {
    "pindexes": "index partition", "feeds": "datasource"
}

function IndexesCtrl($scope, $http, $routeParams, $log, $sce, $location) {

    $scope.indexNames = [];
    $scope.errorMessage = null;
    $scope.errorMessageFull = null;

    $scope.refreshIndexNames = function() {
        $http.get('/api/index').success(function(data) {
            var indexNames = [];
            for (var indexName in data.indexDefs.indexDefs) {
                indexNames.push(indexName)
            }
            $scope.indexNames = indexNames;
        }).
        error(function(data, code) {
            $scope.errorMessage = errorMessage(data, code);
            $scope.errorMessageFull = data;
        });
    };

    $scope.deleteIndex = function(name) {
        if (!confirm("Are you sure you want to permanenty delete the index '"
                     + name + "'?")) {
            return;
        }

        $scope.errorMessage = null;
        $scope.errorMessageFull = null;

        $http.delete('/api/index/' + name).success(function(data) {
            $scope.refreshIndexNames();
        }).
        error(function(data, code) {
            $scope.errorMessage = errorMessage(data, code);
            $scope.errorMessageFull = data;
        });
    };

    $scope.editIndex = function(name) {
        $location.path('/indexes/' + name + '/_edit');
    }

    $scope.cloneIndex = function(name) {
        $location.path('/indexes/' + name + '/_clone');
    }

    $scope.refreshIndexNames();
}

function IndexCtrl($scope, $http, $route, $routeParams, $log, $sce) {

    $scope.errorMessage = null;
    $scope.errorMessageFull = null;

    $scope.nodeDefsByUUID = null;
    $scope.nodeDefsByAddr = null;
    $scope.nodeAddrsArr = null;

    $scope.indexName = $routeParams.indexName;
    $scope.indexDocCount = 0;
    $scope.indexDefStr = "";
    $scope.indexParamsStr = "";
    $scope.indexStats = null;
    $scope.planPIndexes = null;
    $scope.planPIndexesStr = ""

    $scope.statsRefresh = null;
    $scope.warnings = null;

    $scope.tab = $routeParams.tabName;
    if ($scope.tab === undefined || $scope.tab === "") {
        $scope.tab = "summary";
    }
    $scope.tabPath = '/static/partials/index/tab-' + $scope.tab + '.html';

    $http.get('/api/cfg').success(function(data) {
        $scope.nodeDefsByUUID = {}
        $scope.nodeDefsByAddr = {}
        $scope.nodeAddrsArr = []
        for (var k in data.nodeDefsWanted.nodeDefs) {
            var nodeDef = data.nodeDefsWanted.nodeDefs[k]
            $scope.nodeDefsByUUID[nodeDef.uuid] = nodeDef
            $scope.nodeDefsByAddr[nodeDef.hostPort] = nodeDef
            $scope.nodeAddrsArr.push(nodeDef.hostPort);
        }
        $scope.nodeAddrsArr.sort();
        $scope.loadIndexDetails()
    }).
    error(function(data, code) {
        $scope.errorMessage = errorMessage(data, code);
        $scope.errorMessageFull = data;
    });

    $scope.loadIndexDetails = function() {
        $scope.errorMessage = null;
        $scope.errorMessageFull = null;

        $http.get('/api/index/' + $scope.indexName).
        success(function(data) {
            data.indexDef.params = JSON.parse(data.indexDef.params);
            data.indexDef.sourceParams = JSON.parse(data.indexDef.sourceParams);

            $scope.indexDef = data.indexDef
            $scope.indexDefStr = JSON.stringify(data.indexDef, undefined, 2);
            $scope.indexParamsStr = JSON.stringify(data.indexDef.params, undefined, 2);
            $scope.planPIndexesStr = JSON.stringify(data.planPIndexes, undefined, 2);
            $scope.planPIndexes = data.planPIndexes;
            if ($scope.planPIndexes) {
                $scope.planPIndexes.sort(
                    function(x, y) {
                        if (x.name > y.name) { return 1; }
                        if (y.name > x.name) { return -1; }
                        return 0;
                    }
                );
            }
            for (var k in $scope.planPIndexes) {
                var planPIndex = $scope.planPIndexes[k];
                planPIndex.sourcePartitionsArr =
                    planPIndex.sourcePartitions.split(",").sort(
                        function(x, y) { return parseInt(x) - parseInt(y); }
                    );
                planPIndex.sourcePartitionsStr =
                    collapseNeighbors(planPIndex.sourcePartitionsArr).join(", ");
            }
            $scope.warnings = data.warnings;

            $scope.indexCanWrite =
                !data.indexDef ||
                !data.indexDef.planParams ||
                !data.indexDef.planParams.nodePlanParams ||
                !data.indexDef.planParams.nodePlanParams[''] ||
                !data.indexDef.planParams.nodePlanParams[''][''] ||
                data.indexDef.planParams.nodePlanParams[''][''].canWrite;
            $scope.indexCanRead =
                !data.indexDef ||
                !data.indexDef.planParams ||
                !data.indexDef.planParams.nodePlanParams ||
                !data.indexDef.planParams.nodePlanParams[''] ||
                !data.indexDef.planParams.nodePlanParams[''][''] ||
                data.indexDef.planParams.nodePlanParams[''][''].canRead;
            $scope.indexPlanFrozen =
                data.indexDef &&
                data.indexDef.planParams &&
                data.indexDef.planParams.planFrozen;
        }).
        error(function(data, code) {
            $scope.errorMessage = errorMessage(data, code);
            $scope.errorMessageFull = data;
        });
    };

    $scope.loadIndexDocCount = function() {
        $scope.indexDocCount = "..."
        $scope.errorMessage = null;
        $scope.errorMessageFull = null;

        $http.get('/api/index/' + $scope.indexName + '/count').
        success(function(data) {
            $scope.indexDocCount = data.count;
        }).
        error(function(data, code) {
            $scope.indexDocCount = "error"
            $scope.errorMessage = errorMessage(data, code);
            $scope.errorMessageFull = data;
        });
    };

    $scope.loadIndexStats = function() {
        $scope.statsRefresh = "refreshing...";
        $scope.errorMessage = null;
        $scope.errorMessageFull = null;

        $http.get('/api/stats/index/' + $scope.indexName).
        success(function(data) {
            $scope.statsRefresh = null;
            $scope.indexStats = data;

            var indexStatsPrev = indexStatsPrevs[$scope.indexName];
            var indexStatsAggsPrev = indexStatsAggsPrevs[$scope.indexName];

            var errors = [];
            var stats = [];
            var aggs = {};

            var kinds = ["pindexes", "feeds"];
            for (var a in kinds) {
                var aa = kinds[a];

                // The k is pindexName / feedName.
                for (var k in data[aa]) {
                    var kk = data[aa][k];
                    // The j is category of stats, like
                    // bleveKVStoreStats, pindexStoreStats,
                    // bucketDataSourceStats, destStats.
                    for (var j in kk) {
                        var jj = data[aa][k][j];
                        errors = errors.concat(jj.Errors || []);

                        for (var s in jj) {
                            var ss = jj[s];
                            if (ss instanceof Array) {
                                continue;
                            }
                            if (typeof(ss) == "number") {
                                ss = jj[s] = {
                                    count: ss,
                                    advanced: j != "basic"
                                };
                            }
                            ss.prev = ss;
                            if (indexStatsPrev) {
                                ss.prev =
                                    ((indexStatsPrev[aa][k] || {})[j] || {})[s];
                            }
                            ss.sourceName = k;
                            ss.statKind = indexStatsLabels[aa];
                            ss.statName = s;
                            ss.label = s.replace(/^Timer/, "");

                            stats.push(ss);

                            var agg = aggs[s] = aggs[s] || {
                                advanced: ss.advanced,
                                count: 0,
                                label: ss.label
                            };
                            agg.count = agg.count + (ss.count || 0);
                            if (indexStatsAggsPrev) {
                                agg.prev = indexStatsAggsPrev[s];
                            }
                        }
                    }
                }
            }

            indexStatsPrevs[$scope.indexName] = data;
            indexStatsAggsPrevs[$scope.indexName] = aggs;

            stats.sort(function(a, b) {
                if (a.statKind < b.statKind) {
                    return 1;
                }
                if (a.statKind > b.statKind) {
                    return -1;
                }
                if (a.statName < b.statName) {
                    return -1;
                }
                if (a.statName > b.statName) {<commit_msg>don't sort by stat kind/category, favoring name<commit_after>var indexStatsPrevs = {};
var indexStatsAggsPrevs = {};

var indexStatsLabels = {
    "pindexes": "index partition", "feeds": "datasource"
}

function IndexesCtrl($scope, $http, $routeParams, $log, $sce, $location) {

    $scope.indexNames = [];
    $scope.errorMessage = null;
    $scope.errorMessageFull = null;

    $scope.refreshIndexNames = function() {
        $http.get('/api/index').success(function(data) {
            var indexNames = [];
            for (var indexName in data.indexDefs.indexDefs) {
                indexNames.push(indexName)
            }
            $scope.indexNames = indexNames;
        }).
        error(function(data, code) {
            $scope.errorMessage = errorMessage(data, code);
            $scope.errorMessageFull = data;
        });
    };

    $scope.deleteIndex = function(name) {
        if (!confirm("Are you sure you want to permanenty delete the index '"
                     + name + "'?")) {
            return;
        }

        $scope.errorMessage = null;
        $scope.errorMessageFull = null;

        $http.delete('/api/index/' + name).success(function(data) {
            $scope.refreshIndexNames();
        }).
        error(function(data, code) {
            $scope.errorMessage = errorMessage(data, code);
            $scope.errorMessageFull = data;
        });
    };

    $scope.editIndex = function(name) {
        $location.path('/indexes/' + name + '/_edit');
    }

    $scope.cloneIndex = function(name) {
        $location.path('/indexes/' + name + '/_clone');
    }

    $scope.refreshIndexNames();
}

function IndexCtrl($scope, $http, $route, $routeParams, $log, $sce) {

    $scope.errorMessage = null;
    $scope.errorMessageFull = null;

    $scope.nodeDefsByUUID = null;
    $scope.nodeDefsByAddr = null;
    $scope.nodeAddrsArr = null;

    $scope.indexName = $routeParams.indexName;
    $scope.indexDocCount = 0;
    $scope.indexDefStr = "";
    $scope.indexParamsStr = "";
    $scope.indexStats = null;
    $scope.planPIndexes = null;
    $scope.planPIndexesStr = ""

    $scope.statsRefresh = null;
    $scope.warnings = null;

    $scope.tab = $routeParams.tabName;
    if ($scope.tab === undefined || $scope.tab === "") {
        $scope.tab = "summary";
    }
    $scope.tabPath = '/static/partials/index/tab-' + $scope.tab + '.html';

    $http.get('/api/cfg').success(function(data) {
        $scope.nodeDefsByUUID = {}
        $scope.nodeDefsByAddr = {}
        $scope.nodeAddrsArr = []
        for (var k in data.nodeDefsWanted.nodeDefs) {
            var nodeDef = data.nodeDefsWanted.nodeDefs[k]
            $scope.nodeDefsByUUID[nodeDef.uuid] = nodeDef
            $scope.nodeDefsByAddr[nodeDef.hostPort] = nodeDef
            $scope.nodeAddrsArr.push(nodeDef.hostPort);
        }
        $scope.nodeAddrsArr.sort();
        $scope.loadIndexDetails()
    }).
    error(function(data, code) {
        $scope.errorMessage = errorMessage(data, code);
        $scope.errorMessageFull = data;
    });

    $scope.loadIndexDetails = function() {
        $scope.errorMessage = null;
        $scope.errorMessageFull = null;

        $http.get('/api/index/' + $scope.indexName).
        success(function(data) {
            data.indexDef.params = JSON.parse(data.indexDef.params);
            data.indexDef.sourceParams = JSON.parse(data.indexDef.sourceParams);

            $scope.indexDef = data.indexDef
            $scope.indexDefStr = JSON.stringify(data.indexDef, undefined, 2);
            $scope.indexParamsStr = JSON.stringify(data.indexDef.params, undefined, 2);
            $scope.planPIndexesStr = JSON.stringify(data.planPIndexes, undefined, 2);
            $scope.planPIndexes = data.planPIndexes;
            if ($scope.planPIndexes) {
                $scope.planPIndexes.sort(
                    function(x, y) {
                        if (x.name > y.name) { return 1; }
                        if (y.name > x.name) { return -1; }
                        return 0;
                    }
                );
            }
            for (var k in $scope.planPIndexes) {
                var planPIndex = $scope.planPIndexes[k];
                planPIndex.sourcePartitionsArr =
                    planPIndex.sourcePartitions.split(",").sort(
                        function(x, y) { return parseInt(x) - parseInt(y); }
                    );
                planPIndex.sourcePartitionsStr =
                    collapseNeighbors(planPIndex.sourcePartitionsArr).join(", ");
            }
            $scope.warnings = data.warnings;

            $scope.indexCanWrite =
                !data.indexDef ||
                !data.indexDef.planParams ||
                !data.indexDef.planParams.nodePlanParams ||
                !data.indexDef.planParams.nodePlanParams[''] ||
                !data.indexDef.planParams.nodePlanParams[''][''] ||
                data.indexDef.planParams.nodePlanParams[''][''].canWrite;
            $scope.indexCanRead =
                !data.indexDef ||
                !data.indexDef.planParams ||
                !data.indexDef.planParams.nodePlanParams ||
                !data.indexDef.planParams.nodePlanParams[''] ||
                !data.indexDef.planParams.nodePlanParams[''][''] ||
                data.indexDef.planParams.nodePlanParams[''][''].canRead;
            $scope.indexPlanFrozen =
                data.indexDef &&
                data.indexDef.planParams &&
                data.indexDef.planParams.planFrozen;
        }).
        error(function(data, code) {
            $scope.errorMessage = errorMessage(data, code);
            $scope.errorMessageFull = data;
        });
    };

    $scope.loadIndexDocCount = function() {
        $scope.indexDocCount = "..."
        $scope.errorMessage = null;
        $scope.errorMessageFull = null;

        $http.get('/api/index/' + $scope.indexName + '/count').
        success(function(data) {
            $scope.indexDocCount = data.count;
        }).
        error(function(data, code) {
            $scope.indexDocCount = "error"
            $scope.errorMessage = errorMessage(data, code);
            $scope.errorMessageFull = data;
        });
    };

    $scope.loadIndexStats = function() {
        $scope.statsRefresh = "refreshing...";
        $scope.errorMessage = null;
        $scope.errorMessageFull = null;

        $http.get('/api/stats/index/' + $scope.indexName).
        success(function(data) {
            $scope.statsRefresh = null;
            $scope.indexStats = data;

            var indexStatsPrev = indexStatsPrevs[$scope.indexName];
            var indexStatsAggsPrev = indexStatsAggsPrevs[$scope.indexName];

            var errors = [];
            var stats = [];
            var aggs = {};

            var kinds = ["pindexes", "feeds"];
            for (var a in kinds) {
                var aa = kinds[a];

                // The k is pindexName / feedName.
                for (var k in data[aa]) {
                    var kk = data[aa][k];
                    // The j is category of stats, like
                    // bleveKVStoreStats, pindexStoreStats,
                    // bucketDataSourceStats, destStats.
                    for (var j in kk) {
                        var jj = data[aa][k][j];
                        errors = errors.concat(jj.Errors || []);

                        for (var s in jj) {
                            var ss = jj[s];
                            if (ss instanceof Array) {
                                continue;
                            }
                            if (typeof(ss) == "number") {
                                ss = jj[s] = {
                                    count: ss,
                                    advanced: j != "basic"
                                };
                            }
                            ss.prev = ss;
                            if (indexStatsPrev) {
                                ss.prev =
                                    ((indexStatsPrev[aa][k] || {})[j] || {})[s];
                            }
                            ss.sourceName = k;
                            ss.statKind = indexStatsLabels[aa];
                            ss.statName = s;
                            ss.label = s.replace(/^Timer/, "");

                            stats.push(ss);

                            var agg = aggs[s] = aggs[s] || {
                                advanced: ss.advanced,
                                count: 0,
                                label: ss.label
                            };
                            agg.count = agg.count + (ss.count || 0);
                            if (indexStatsAggsPrev) {
                                agg.prev = indexStatsAggsPrev[s];
                            }
                        }
                    }
                }
            }

            indexStatsPrevs[$scope.indexName] = data;
            indexStatsAggsPrevs[$scope.indexName] = aggs;

            stats.sort(function(a, b) {
                if (a.statName < b.statName) {
                    return -1;
                }
                if (a.statName > b.statName) {
{'fraction_non_alphanumeric': 0.12582960125182108, 'fraction_numerical': 0.0011870717099228404, 'mean_word_length': 1.3880943177425589, 'pattern_counts': {'":': 4, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7086416', 'n_tokens_mistral': 5227, 'n_tokens_neox': 5009, 'n_words': 836}