<commit_before>/*****************************************************************************
 ***
 *** Create the admin object to act as a namespace for this file
 ***
 *****************************************************************************/

var admin = {};

admin.controller = function ($scope, $http) {
    $scope.getProjectList = function () {
        // FIXME:  GARY - Once the get-all-projects route is created, uncomment the block of code below
        // $http.get("get-all-projects").
        //     then (function(data) {
        //         return data;
        //     }, function(response) {
        //         console.log(response.status);
        //         return {};
        //     });
        return ceo_sample_data.project_list;
    };

    $scope.projectList = $scope.getProjectList();
    $scope.currentProjectId = "0";
    $scope.currentProject = null;
    $scope.projectName = "";
    $scope.projectDescription = "";
    $scope.numPlots = "";
    $scope.plotRadius = "";
    $scope.sampleType = "random";
    $scope.samplesPerPlot = "";
    $scope.sampleResolution = "";
    $scope.lonMin = "";
    $scope.latMin = "";
    $scope.lonMax = "";
    $scope.latMax = "";
    $scope.currentImagery = "DigitalGlobeRecentImagery+Streets";
    $scope.valueName = "";
    $scope.valueColor = "#000000";
    $scope.valueImage = "";
    $scope.sampleValues = [];

    // Initialize the base map and enable the dragbox interaction
    map_utils.digital_globe_base_map({div_name: "new-project-map",
                                      center_coords: [102.0, 17.0],
                                      zoom_level: 5});

    map_utils.enable_dragbox_draw();

    map_utils.set_bbox_coords = function () {
        var latmax = document.getElementById("lat-max");
        var lonmax = document.getElementById("lon-max");
        var latmin = document.getElementById("lat-min");
        var lonmin = document.getElementById("lon-min");
        latmax.value = map_utils.current_bbox.maxlat;
        lonmax.value = map_utils.current_bbox.maxlon;
        latmin.value = map_utils.current_bbox.minlat;
        lonmin.value = map_utils.current_bbox.minlon;
    };

    $scope.getProjectById = function (projectId) {
        $scope.projectList.find(
            function (project) {
                return project.id == projectId;
            }
        );
    };

    $scope.setCurrentProject = function() {
        var project = $scope.getProjectById($scope.currentProjectId);
        $scope.currentProject = project;

        if (project) {
            var plotData = $scope.projectList.plot_data[$scope.currentProjectId];
            $scope.projectName = project.name;
            $scope.projectDescription = project.description;
            $scope.numPlots = plotData.length;
            $scope.plotRadius = plotData[0].plot.radius;
            if (project.sample_resolution) {
                $scope.sampleType = "gridded";
                document.getElementById("gridded-sample-type").checked = true;
                utils.enable_element("samples-per-plot");
                utils.enable_element("sample-resolution");
            } else {
                $scope.sampleType = "random";
                document.getElementById("random-sample-type").checked = true;
                utils.enable_element("samples-per-plot");
                utils.disable_element("sample-resolution");
            }
            $scope.samplesPerPlot = plotData[0].samples.length;
            $scope.sampleResolution = project.sample_resolution || "";
            var boundaryExtent = map_utils.polygon_extent(project.boundary);
            $scope.lonMin = boundaryExtent[0];
            $scope.latMin = boundaryExtent[1];
            $scope.lonMax = boundaryExtent[2];
            $scope.latMax = boundaryExtent[3];
            $scope.currentImagery = project.imagery;
            map_utils.set_current_imagery($scope.currentImagery);
            map_utils.disable_dragbox_draw();
            map_utils.draw_polygon(project.boundary);
            $scope.sampleValues = project.sample_values;<commit_msg>Fixed bug in setCurrentProject by creating getPlotData function.<commit_after>/*****************************************************************************
 ***
 *** Create the admin object to act as a namespace for this file
 ***
 *****************************************************************************/

var admin = {};

admin.controller = function ($scope, $http) {
    $scope.getProjectList = function () {
        // FIXME:  GARY - Once the get-all-projects route is created, uncomment the block of code below
        // $http.get("get-all-projects").
        //     then (function(data) {
        //         return data;
        //     }, function(response) {
        //         console.log(response.status);
        //         return {};
        //     });
        return ceo_sample_data.project_list;
    };

    $scope.projectList = $scope.getProjectList();
    $scope.currentProjectId = "0";
    $scope.currentProject = null;
    $scope.projectName = "";
    $scope.projectDescription = "";
    $scope.numPlots = "";
    $scope.plotRadius = "";
    $scope.sampleType = "random";
    $scope.samplesPerPlot = "";
    $scope.sampleResolution = "";
    $scope.lonMin = "";
    $scope.latMin = "";
    $scope.lonMax = "";
    $scope.latMax = "";
    $scope.currentImagery = "DigitalGlobeRecentImagery+Streets";
    $scope.valueName = "";
    $scope.valueColor = "#000000";
    $scope.valueImage = "";
    $scope.sampleValues = [];

    // Initialize the base map and enable the dragbox interaction
    map_utils.digital_globe_base_map({div_name: "new-project-map",
                                      center_coords: [102.0, 17.0],
                                      zoom_level: 5});

    map_utils.enable_dragbox_draw();

    map_utils.set_bbox_coords = function () {
        var latmax = document.getElementById("lat-max");
        var lonmax = document.getElementById("lon-max");
        var latmin = document.getElementById("lat-min");
        var lonmin = document.getElementById("lon-min");
        latmax.value = map_utils.current_bbox.maxlat;
        lonmax.value = map_utils.current_bbox.maxlon;
        latmin.value = map_utils.current_bbox.minlat;
        lonmin.value = map_utils.current_bbox.minlon;
    };

    $scope.getProjectById = function (projectId) {
        $scope.projectList.find(
            function (project) {
                return project.id == projectId;
            }
        );
    };

    // FIXME: Replace with an AJAX request
    $scope.getPlotData = function (projectId) {
        return ceo_sample_data.plot_data[projectId];
    };

    $scope.setCurrentProject = function() {
        var project = $scope.getProjectById($scope.currentProjectId);
        $scope.currentProject = project;

        if (project) {
            var plotData = $scope.getPlotData(project.id);
            $scope.projectName = project.name;
            $scope.projectDescription = project.description;
            $scope.numPlots = plotData.length;
            $scope.plotRadius = plotData[0].plot.radius;
            if (project.sample_resolution) {
                $scope.sampleType = "gridded";
                document.getElementById("gridded-sample-type").checked = true;
                utils.enable_element("samples-per-plot");
                utils.enable_element("sample-resolution");
            } else {
                $scope.sampleType = "random";
                document.getElementById("random-sample-type").checked = true;
                utils.enable_element("samples-per-plot");
                utils.disable_element("sample-resolution");
            }
            $scope.samplesPerPlot = plotData[0].samples.length;
            $scope.sampleResolution = project.sample_resolution || "";
            var boundaryExtent = map_utils.polygon_extent(project.boundary);
            $scope.lonMin = boundaryExtent[0];
            $scope.latMin = boundaryExtent[1];
            $scope.lonMax = boundaryExtent[2];
            $scope.latMax = boundaryExtent[3];
            $scope.currentImagery = project.imagery;
            map_utils.set_current_imagery($scope.currentImagery);
            map_utils.disable_dragbox_draw();
            map_utils.draw_polygon(project.boundary);
            $scope.sampleValues = project.sample_values;
{'fraction_non_alphanumeric': 0.1588249343205159, 'fraction_numerical': 0.005015524241700501, 'mean_word_length': 2.2946498819826906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2476753', 'n_tokens_mistral': 2347, 'n_tokens_neox': 2248, 'n_words': 367}