<commit_before>var markers = [];
var map;
var filters = {
    dataTypes: {
        key: 'dataType',
        icon: 'cloud_queue',
        label: 'Data Types',
        values: {},
        inclusive: true, // For filter items that can take multiple values from a set of values
        has_search: false
    },
    organizations: {
        key: 'organization',
        label: 'Organizations',
        icon: 'business',   // From https://material.io/icons/
        values: {},
        has_search: true
    },
    siteTypes: {
        key: 'type',
        icon: 'layers',
        label: 'Site Types',
        values: {},
        has_search: true
    }
};

function CenterControl(controlDiv, map) {
    // Set CSS for the control border.
    var controlUI = document.createElement('div');
    controlUI.style.backgroundColor = '#fff';
    controlUI.style.border = '2px solid #fff';
    controlUI.style.borderRadius = '3px';
    controlUI.style.boxShadow = 'rgba(0, 0, 0, 0.3) 0px 1px 1px)';
    controlUI.style.cursor = 'pointer';
    controlUI.style.marginBottom = '1em';
    controlUI.style.marginTop = '1em';
    controlUI.style.textAlign = 'center';
    controlUI.title = 'Click to recenter the map';
    controlDiv.appendChild(controlUI);

    // Set CSS for the control interior.
    var controlText = document.createElement('div');
    controlText.style.padding = "1em";
    controlText.innerHTML = 'Showing <strong id="marker-count">0</strong> out of <strong id="marker-total-count">0</strong> results.';
    controlUI.appendChild(controlText);
}

function initMap() {
    const DEFAULT_ZOOM = 5;
    const DEFAULT_SPECIFIC_ZOOM = 12;
    const DEFAULT_LATITUDE = 40.0902;
    const DEFAULT_LONGITUDE = -95.7129;
    const DEFAULT_POSITION = { lat: DEFAULT_LATITUDE, lng: DEFAULT_LONGITUDE };
    var ZOOM_LEVEL = sessionStorage && parseInt(sessionStorage.getItem('CURRENT_ZOOM')) || DEFAULT_ZOOM;
    var temp = sessionStorage.getItem('CURRENT_CENTER');
    var MAP_CENTER = DEFAULT_POSITION;

    if(sessionStorage.getItem('CURRENT_CENTER')) {
        MAP_CENTER = getLatLngFromString(temp);
    } else if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function getLocation(locatedPosition) {
            map.setCenter({ lat: locatedPosition.coords.latitude, lng: locatedPosition.coords.longitude });
            map.setZoom(DEFAULT_SPECIFIC_ZOOM);
        }, undefined, { timeout: 5000 });
    }

    var markerData = JSON.parse(document.getElementById('sites-data').innerHTML);

    map = new google.maps.Map(document.getElementById('map'), {
        center: MAP_CENTER,
        zoom: ZOOM_LEVEL,
        gestureHandling: 'greedy',
        zoomControl: true,
        zoomControlOptions: {
            position: google.maps.ControlPosition.LEFT_BOTTOM
        },
        mapTypeId: google.maps.MapTypeId.TERRAIN,
        scaleControl: true
    });

    map.setOptions({minZoom: 1, maxZoom: 18});

    var infoWindow = new google.maps.InfoWindow({
        content: ''
    });

    map.addListener('zoom_changed', function(){
        var CURRENT_ZOOM = map.getZoom();
        sessionStorage.setItem('CURRENT_ZOOM', CURRENT_ZOOM);
    });

    map.addListener('center_changed', function(){
        var CURRENT_CENTER = map.getCenter();
        sessionStorage.setItem('CURRENT_CENTER', CURRENT_CENTER);
    });

    var icons = {
        followed: {
            url: "/static/dataloaderinterface/images/marker-blue-dotted.png",
            size: new google.maps.Size(36, 63),
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(18, 58),
            scaledSize: new google.maps.Size(36, 63)
        },
        owned: {
            url: "/static/dataloaderinterface/images/marker-red-dotted.png",
            size: new google.maps.Size(36, 62),
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(18, 58),
            scaledSize: new google.maps.Size(36, 62)
        },
        unfollowed: {
            url: "/static/dataloaderinterface/images/marker-blue.png",
            size: new google.maps.Size(36, 63),
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(18, 58),
            scaledSize: new google.maps.Size(36, 63)
        }
    };

    markerData.forEach(function(site) {
        var marker = new google.maps.Marker({
            position: {lat: site.latitude, lng: site.longitude},
            map: map,
            icon: icons[site.status]
        });

        for (var f in filters) {
            marker[filters[f].key] = site[filters[f].key];
        }

        marker.addListener('click', function() {
            var contentElement = $('<div></div>').append($('#site-marker-content').html());
            var fields = contentElement.find('.site-field');
            fields.each(function(index, element) {
                var field = $(element).data('field');
                $(element).find('.site-data').text(site[field]);
            });
            contentElement.find('.site-link a').attr('href', site.detail_link);

            var infoContent = $('<div></div>').append(contentElement.html()).html();
            infoWindow.setContent(infoContent);
            infoWindow.open(marker.get('map'), marker);
        });

        markers.push(marker);
    });

    var centerControlDiv = document.createElement('div');
    CenterControl(centerControlDiv, map);

    map.controls[google.maps.ControlPosition.TOP_CENTER].push(centerControlDiv);

    $("#marker-count").text(markers.length);
    $("#marker-total-count").text(markers.length);
}

$(document).ready(function () {
    $('nav .menu-browse-sites').addClass('active');
    resizeContent();

    var markerData = JSON.parse(document.getElementById('sites-data').innerHTML);

    markerData.forEach(function (site) {
        for (var f in filters) {
            var keys = [site[filters[f].key]];
            if (filters[f].inclusive) {
                keys = [];
                var includes = site[filters[f].key].split(",");
                for (var i = 0; i < includes.length; i++) {
                    if (includes[i].trim()) {
                        keys.push(includes[i].trim());
                    }
                }
            }
            for (var ckey in keys) {
                if (filters[f].values[keys[ckey]])
                    filters[f].values[keys[ckey]] += 1;
                else
                    filters[f].values[keys[ckey]] = 1;    // Initialize count
            }
        }
    });

    // Move the items to an array so we can sort them
    for (var f in filters) {
        filters[f].values_sortable = [];
        for (var val in filters[f].values) {
            filters[f].values_sortable.push([val, filters[f].values[val]]);
        }
    }

    // Sort the arrays
    for (var f in filters) {
        filters[f].values_sortable.sort(function (a, b) {
            return b[1] - a[1];
        });
    }

    // Append filter headers
    for (var f in filters) {
        $("#filters").append('<div class="filter-container"><div class="filter-header">\
                    <table class="mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp full-width">\
                        <tr>\
                            <td class="mdl-data-table__cell--non-numeric">\
                                <a data-toggle="collapse" href="#collapse-' + filters[f].key + '" role="button" aria-expanded="true"\
                                   aria-controls="collapse-' + f.key + '" style="text-decoration: none; color: #222;">\
                                    <h6><i class="material-icons mdl-shadow--2dp">' + filters[f].icon + '</i> ' + filters[f].label + '<i class="material-icons icon-arrow pull-right">keyboard_arrow_down</i></h6>\
                                </a>\
                            </td>\
                        </tr>\
                    </table>\
                </div>\
                <div id="collapse-' + filters[f].key + '" class="show filter-body" data-facet="' + filters[f].key + '">\
                    <table class="mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp full-width">\
                        <tbody>'+ (filters[f].has_search ?
                            '<tr class="td-filter">\
                                <td class="mdl-data-table__cell--non-numeric">\
                                    <div class="input-group">\
                                        <span class="input-group-addon" id="basic-addon1"><i class="material-icons">search</i></span>\
                                        <input type="text" class="form-control input-filter" placeholder="Search ' + filters[f].label + '...">\
                                    </div>\<commit_msg>Sorting arrays alphabetically<commit_after>var markers = [];
var map;
var filters = {
    dataTypes: {
        key: 'dataType',
        icon: 'cloud_queue',
        label: 'Data Types',
        values: {},
        inclusive: true, // For filter items that can take multiple values from a set of values
        has_search: false
    },
    organizations: {
        key: 'organization',
        label: 'Organizations',
        icon: 'business',   // From https://material.io/icons/
        values: {},
        has_search: true
    },
    siteTypes: {
        key: 'type',
        icon: 'layers',
        label: 'Site Types',
        values: {},
        has_search: true
    }
};

function CenterControl(controlDiv, map) {
    // Set CSS for the control border.
    var controlUI = document.createElement('div');
    controlUI.style.backgroundColor = '#fff';
    controlUI.style.border = '2px solid #fff';
    controlUI.style.borderRadius = '3px';
    controlUI.style.boxShadow = 'rgba(0, 0, 0, 0.3) 0px 1px 1px)';
    controlUI.style.cursor = 'pointer';
    controlUI.style.marginBottom = '1em';
    controlUI.style.marginTop = '1em';
    controlUI.style.textAlign = 'center';
    controlUI.title = 'Click to recenter the map';
    controlDiv.appendChild(controlUI);

    // Set CSS for the control interior.
    var controlText = document.createElement('div');
    controlText.style.padding = "1em";
    controlText.innerHTML = 'Showing <strong id="marker-count">0</strong> out of <strong id="marker-total-count">0</strong> results.';
    controlUI.appendChild(controlText);
}

function initMap() {
    const DEFAULT_ZOOM = 5;
    const DEFAULT_SPECIFIC_ZOOM = 12;
    const DEFAULT_LATITUDE = 40.0902;
    const DEFAULT_LONGITUDE = -95.7129;
    const DEFAULT_POSITION = { lat: DEFAULT_LATITUDE, lng: DEFAULT_LONGITUDE };
    var ZOOM_LEVEL = sessionStorage && parseInt(sessionStorage.getItem('CURRENT_ZOOM')) || DEFAULT_ZOOM;
    var temp = sessionStorage.getItem('CURRENT_CENTER');
    var MAP_CENTER = DEFAULT_POSITION;

    if(sessionStorage.getItem('CURRENT_CENTER')) {
        MAP_CENTER = getLatLngFromString(temp);
    } else if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function getLocation(locatedPosition) {
            map.setCenter({ lat: locatedPosition.coords.latitude, lng: locatedPosition.coords.longitude });
            map.setZoom(DEFAULT_SPECIFIC_ZOOM);
        }, undefined, { timeout: 5000 });
    }

    var markerData = JSON.parse(document.getElementById('sites-data').innerHTML);

    map = new google.maps.Map(document.getElementById('map'), {
        center: MAP_CENTER,
        zoom: ZOOM_LEVEL,
        gestureHandling: 'greedy',
        zoomControl: true,
        zoomControlOptions: {
            position: google.maps.ControlPosition.LEFT_BOTTOM
        },
        mapTypeId: google.maps.MapTypeId.TERRAIN,
        scaleControl: true
    });

    map.setOptions({minZoom: 1, maxZoom: 18});

    var infoWindow = new google.maps.InfoWindow({
        content: ''
    });

    map.addListener('zoom_changed', function(){
        var CURRENT_ZOOM = map.getZoom();
        sessionStorage.setItem('CURRENT_ZOOM', CURRENT_ZOOM);
    });

    map.addListener('center_changed', function(){
        var CURRENT_CENTER = map.getCenter();
        sessionStorage.setItem('CURRENT_CENTER', CURRENT_CENTER);
    });

    var icons = {
        followed: {
            url: "/static/dataloaderinterface/images/marker-blue-dotted.png",
            size: new google.maps.Size(36, 63),
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(18, 58),
            scaledSize: new google.maps.Size(36, 63)
        },
        owned: {
            url: "/static/dataloaderinterface/images/marker-red-dotted.png",
            size: new google.maps.Size(36, 62),
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(18, 58),
            scaledSize: new google.maps.Size(36, 62)
        },
        unfollowed: {
            url: "/static/dataloaderinterface/images/marker-blue.png",
            size: new google.maps.Size(36, 63),
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(18, 58),
            scaledSize: new google.maps.Size(36, 63)
        }
    };

    markerData.forEach(function(site) {
        var marker = new google.maps.Marker({
            position: {lat: site.latitude, lng: site.longitude},
            map: map,
            icon: icons[site.status]
        });

        for (var f in filters) {
            marker[filters[f].key] = site[filters[f].key];
        }

        marker.addListener('click', function() {
            var contentElement = $('<div></div>').append($('#site-marker-content').html());
            var fields = contentElement.find('.site-field');
            fields.each(function(index, element) {
                var field = $(element).data('field');
                $(element).find('.site-data').text(site[field]);
            });
            contentElement.find('.site-link a').attr('href', site.detail_link);

            var infoContent = $('<div></div>').append(contentElement.html()).html();
            infoWindow.setContent(infoContent);
            infoWindow.open(marker.get('map'), marker);
        });

        markers.push(marker);
    });

    var centerControlDiv = document.createElement('div');
    CenterControl(centerControlDiv, map);

    map.controls[google.maps.ControlPosition.TOP_CENTER].push(centerControlDiv);

    $("#marker-count").text(markers.length);
    $("#marker-total-count").text(markers.length);
}

$(document).ready(function () {
    $('nav .menu-browse-sites').addClass('active');
    resizeContent();

    var markerData = JSON.parse(document.getElementById('sites-data').innerHTML);

    markerData.forEach(function (site) {
        for (var f in filters) {
            var keys = [site[filters[f].key]];
            if (filters[f].inclusive) {
                keys = [];
                var includes = site[filters[f].key].split(",");
                for (var i = 0; i < includes.length; i++) {
                    if (includes[i].trim()) {
                        keys.push(includes[i].trim());
                    }
                }
            }
            for (var ckey in keys) {
                if (filters[f].values[keys[ckey]])
                    filters[f].values[keys[ckey]] += 1;
                else
                    filters[f].values[keys[ckey]] = 1;    // Initialize count
            }
        }
    });

    // Move the items to an array so we can sort them
    for (var f in filters) {
        filters[f].values_sortable = [];
        for (var val in filters[f].values) {
            filters[f].values_sortable.push([val, filters[f].values[val]]);
        }
    }

    // Sort the arrays alphabetically
    for (var f in filters) {
        filters[f].values_sortable.sort(function (a, b) {
            return b[0] > a[0] ? -1 : 1;
        });
    }

    // Append filter headers
    for (var f in filters) {
        $("#filters").append('<div class="filter-container"><div class="filter-header">\
                    <table class="mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp full-width">\
                        <tr>\
                            <td class="mdl-data-table__cell--non-numeric">\
                                <a data-toggle="collapse" href="#collapse-' + filters[f].key + '" role="button" aria-expanded="true"\
                                   aria-controls="collapse-' + f.key + '" style="text-decoration: none; color: #222;">\
                                    <h6><i class="material-icons mdl-shadow--2dp">' + filters[f].icon + '</i> ' + filters[f].label + '<i class="material-icons icon-arrow pull-right">keyboard_arrow_down</i></h6>\
                                </a>\
                            </td>\
                        </tr>\
                    </table>\
                </div>\
                <div id="collapse-' + filters[f].key + '" class="show filter-body" data-facet="' + filters[f].key + '">\
                    <table class="mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp full-width">\
                        <tbody>'+ (filters[f].has_search ?
                            '<tr class="td-filter">\
                                <td class="mdl-data-table__cell--non-numeric">\
                                    <div class="input-group">\
                                        <span class="input-group-addon" id="basic-addon1"><i class="material-icons">search</i></span>\
                                        <input type="text" class="form-control input-filter" placeholder="Search ' + filters[f].label + '...">\
                                    </div>\
{'fraction_non_alphanumeric': 0.14596097118221013, 'fraction_numerical': 0.010664851372815974, 'mean_word_length': 2.0135042735042736, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 78, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2405543', 'n_tokens_mistral': 5284, 'n_tokens_neox': 5018, 'n_words': 978}