<commit_before>function SocietiesCtrl($scope, $location, $timeout, $http, searchModelService, TreesFromSocieties, FindSocieties) {

    $scope.appendQueryString();
    
    var cookieValue = null;
    if (document.cookie && document.cookie !== '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = jQuery.trim(cookies[i]);
            if (    cookie.substring(0, 10) === ('csrftoken=')) {
                cookieValue = decodeURIComponent(cookie.substring(10));
                break;
             }
        }
    }
    $scope.cookieValue = cookieValue;
    $scope.searchModel = searchModelService.getModel();
    $scope.csvDownloadButton = {text: 'CSV', disabled: false};
    $scope.globalTree = false;
    $scope.variables = [];
   
    $scope.treeButtons = [
        {value: 'phylogeny', name:'Phylogenies', description:"Trees derived from discrete data using phylogenetic methods (branch lengths informative)"},
        {value:'glottolog', name:'Glottolog Trees', description:"Trees derived from Glottolog language family taxonomies (branch lengths uninformative)"},
        {value:'global',name:"Global Tree", description:"A global language supertree composed from language family taxonomies in Glottolog (branch lengths uninformative)"}
    ];


    $scope.setActive('societies');
    $scope.columnSort = { sortColumn: 'society.name', reverse: false };
    
    $scope.tabs = [
        { title: "Table", content: "table", active: true},
        { title: "Map", content: "map", active: false},
        { title: "Tree", content: "tree", active: false},
        { title: "Download", content: "download", active: false},
    ];
    
    var assignGradient = function() {
        if($scope.results.variable_descriptions) {
            $scope.results.variable_descriptions.forEach(function(v) { 
                if (v.variable.data_type.toLowerCase() == 'continuous') {
                        v.fill = "/"+window.location.href.split('/').pop()+"#grad1";
                }
            });
        }
        if($scope.results.environmental_variables) {
            $scope.results.environmental_variables.forEach(function(v) {
                if (v.variable.name.indexOf("precipitation") != -1) v.fill = "/"+window.location.href.split('/').pop()+"#blue";
                    else if (v.variable.name.indexOf("Net primary production") != -1 || v.variable. name.indexOf("NPP") != -1) v.fill = "/"+window.location.href.split('/').pop()+"#earthy";
                    else v.fill = "/"+window.location.href.split('/').pop()+"#temp";
            });
        }
    }
    
    var concatenateVariables = function() {
        if ($scope.results.variable_descriptions) $scope.variables = $scope.variables.concat($scope.results.variable_descriptions);
        if ($scope.results.environmental_variables) $scope.variables = $scope.variables.concat($scope.results.environmental_variables);
        $scope.results.chosenVariable = $scope.variables[0];
    }
    
    var searchCompletedCallback = function() {
        searchModelService.searchCompletedCallback();
        $scope.results = $scope.searchModel.results;
        $scope.query = searchModelService.getModel().getQuery();
        assignGradient();
        concatenateVariables();
    };

    if (!$scope.searchModel.results.searched && !$scope.searchModel.results.searchedByName) {
        var queryObject = $location.search();
        var by_name = false;
        for (var key in queryObject) {
            if (key == 'name') {
                 by_name = true;
            } else {
                queryObject[key] = JSON.parse(queryObject[key]);
            }
        }
        if (!by_name) {
            searchModelService.updateSearchQuery(queryObject);
            $scope.searchModel.results = FindSocieties.find(queryObject, searchCompletedCallback);
        } else {
            $scope.results = FindSocieties.find(queryObject);
            $scope.searchModel.results.searchedByName = true;
        }
    } else {
        $scope.results = searchModelService.getModel().getResults();
        $scope.query = searchModelService.getModel().getQuery();
        assignGradient();
        concatenateVariables();
    }
    
    var sortTrees = function() {
        $scope.results.language_trees.phylogeny = [];
        $scope.results.language_trees.glottolog = [];
        $scope.results.language_trees.forEach(function(tree) {
            if (tree.name.indexOf("global") != -1) $scope.results.language_trees.global = tree;
            else if (tree.name.indexOf("glotto") != -1) {
                $scope.results.language_trees.glottolog.push(tree);
            }
            else {
                $scope.results.language_trees.phylogeny.push(tree);
            }
        });
    }
    
    $scope.addTrees = function() {
        if ($scope.results.language_trees && $scope.results.language_trees.length > 0) return;
        if ($scope.tabs[2].active) {
            list = $scope.results.societies.map(function(s) { return s.society.id});
            society_ids = {'s': list};
            $scope.results.language_trees = TreesFromSocieties.find(society_ids, sortTrees);
        }
    }<commit_msg>Fixing page refresh<commit_after>function SocietiesCtrl($scope, $location, $timeout, $http, searchModelService, TreesFromSocieties, FindSocieties) {

    $scope.appendQueryString();
    
    var cookieValue = null;
    if (document.cookie && document.cookie !== '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = jQuery.trim(cookies[i]);
            if (    cookie.substring(0, 10) === ('csrftoken=')) {
                cookieValue = decodeURIComponent(cookie.substring(10));
                break;
             }
        }
    }
    $scope.cookieValue = cookieValue;
    $scope.searchModel = searchModelService.getModel();
    $scope.csvDownloadButton = {text: 'CSV', disabled: false};
    $scope.globalTree = false;
    $scope.variables = [];
   
    $scope.treeButtons = [
        {value: 'phylogeny', name:'Phylogenies', description:"Trees derived from discrete data using phylogenetic methods (branch lengths informative)"},
        {value:'glottolog', name:'Glottolog Trees', description:"Trees derived from Glottolog language family taxonomies (branch lengths uninformative)"},
        {value:'global',name:"Global Tree", description:"A global language supertree composed from language family taxonomies in Glottolog (branch lengths uninformative)"}
    ];


    $scope.setActive('societies');
    $scope.columnSort = { sortColumn: 'society.name', reverse: false };
    
    $scope.tabs = [
        { title: "Table", content: "table", active: true},
        { title: "Map", content: "map", active: false},
        { title: "Tree", content: "tree", active: false},
        { title: "Download", content: "download", active: false},
    ];
    
    var assignGradient = function() {
        if($scope.results.variable_descriptions) {
            $scope.results.variable_descriptions.forEach(function(v) { 
                if (v.variable.data_type.toLowerCase() == 'continuous') {
                        v.fill = "/"+window.location.href.split('/').pop()+"#grad1";
                }
            });
        }
        if($scope.results.environmental_variables) {
            $scope.results.environmental_variables.forEach(function(v) {
                if (v.variable.name.indexOf("precipitation") != -1) v.fill = "/"+window.location.href.split('/').pop()+"#blue";
                    else if (v.variable.name.indexOf("Net primary production") != -1 || v.variable. name.indexOf("NPP") != -1) v.fill = "/"+window.location.href.split('/').pop()+"#earthy";
                    else v.fill = "/"+window.location.href.split('/').pop()+"#temp";
            });
        }
    }
    
    var concatenateVariables = function() {
        if ($scope.results.variable_descriptions) $scope.variables = $scope.variables.concat($scope.results.variable_descriptions);
        if ($scope.results.environmental_variables) $scope.variables = $scope.variables.concat($scope.results.environmental_variables);
        $scope.results.chosenVariable = $scope.variables[0];
    }
    
    var searchCompletedCallback = function() {
        searchModelService.searchCompletedCallback();
        $scope.results = searchModelService.getModel().getResults();
        $scope.query = searchModelService.getModel().getQuery();
        concatenateVariables();
        assignGradient();
        $scope.addTrees();
    };
    
        
    $scope.addTrees = function() {
        if (!$scope.results) return;
        if ($scope.results.language_trees && $scope.results.language_trees.length > 0) return;
        if ($scope.tabs[2].active) {
            list = $scope.results.societies.map(function(s) { return s.society.id});
            society_ids = {'s': list};
            $scope.results.language_trees = TreesFromSocieties.find(society_ids, sortTrees);
        }
    }

    if (!$scope.searchModel.results.searched && !$scope.searchModel.results.searchedByName) {
        var queryObject = $location.search();
        var by_name = false;
        for (var key in queryObject) {
            if (key == 'name') {
                 by_name = true;
            } else {
                queryObject[key] = JSON.parse(queryObject[key]);
            }
        }
        if (!by_name) {
            searchModelService.updateSearchQuery(queryObject);
            $scope.searchModel.results = FindSocieties.find(queryObject, searchCompletedCallback);
        } else {
            $scope.results = FindSocieties.find(queryObject);
            $scope.searchModel.results.searchedByName = true;
        }
        $scope.results = searchModelService.getModel().getResults();
        $scope.query = searchModelService.getModel().getQuery();  
    } else {
        $scope.results = searchModelService.getModel().getResults();
        $scope.query = searchModelService.getModel().getQuery();
        concatenateVariables();
        assignGradient();
    }
        
    var sortTrees = function() {
        $scope.results.language_trees.phylogeny = [];
        $scope.results.language_trees.glottolog = [];
        $scope.results.language_trees.forEach(function(tree) {
            if (tree.name.indexOf("global") != -1) $scope.results.language_trees.global = tree;
            else if (tree.name.indexOf("glotto") != -1) {
                $scope.results.language_trees.glottolog.push(tree);
            }
            else {
                $scope.results.language_trees.phylogeny.push(tree);
            }
        });
    }
{'fraction_non_alphanumeric': 0.14420825920029964, 'fraction_numerical': 0.00280925180260324, 'mean_word_length': 2.5062376887721602, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3945208', 'n_tokens_mistral': 3034, 'n_tokens_neox': 2969, 'n_words': 516}