<commit_before>var wardPaths = [];
var wardPolys = [];
var currWeekEnd = moment().day(-1).startOf('day');
var dateFormat = 'YYYY-MM-DD';
var numOfDays = 7;

var stIndex = 0;
var serviceTypesJSON = {
    "graffiti_removal": {
        "code": "4fd3b167e750846744000005",
        "name": "Graffiti Removal"
    },
    "restaurant_complaint": {
        "code": "4fd6e4ece750840569000019",
        "name": "Restaurant Complaint"
    },
    "rodent_baiting_rat_complaint": {
        "code": "4fd3b9bce750846c5300004a",
        "name": "Rodent Baiting / Rat Complaint"
    },
    "tree_debris": {
        "code": "4fd3bbf8e750846c53000069",
        "name": "Tree Debris"
    },
    "abandoned_vehicle": {
        "code": "4ffa4c69601827691b000018",
        "name": "Abandoned Vehicle"
    },
    "street_light_1_out": {
        "code": "4ffa9f2d6018277d400000c8",
        "name": "Street Light 1 / Out"
    },
    "pavement_cavein_survey": {
        "code": "4ffa971e6018277d4000000b",
        "name": "Pavement Cave-In Survey"
    },
    "alley_light_out": {
        "code": "4ffa9cad6018277d4000007b",
        "name": "Alley Light Out"
    },
    "building_violation": {
        "code": "4fd3bd72e750846c530000cd",
        "name": "Building Violation"
    },
    "traffic_signal_out": {
        "code": "4ffa9db16018277d400000a2",
        "name": "Traffic Signal Out"
    },
    "street_cut_complaint": {
        "code": "4ffa995a6018277d4000003c",
        "name": "Street Cut Complaints"
    },
    "sanitation_code_violation": {
        "code": "4fd3b750e750846c5300001d",
        "name": "Sanitation Code Violation"
    },
    "pothole_in_street": {
        "code": "4fd3b656e750846c53000004",
        "name": "Pothole in Street"
    },
    "street_lights_all_out": {
        "code": "4fd3bd3de750846c530000b9",
        "name": "Street Lights All / Out"
    }
};
var serviceTypes = _.pairs(serviceTypesJSON);

function calculateLayerSettings(wardNum, highest, lowest) {
    var fillOp = 0.1;
    var col = '#0873AD';

    if (wardNum == lowest[0]) {
        fillOp = 1;
    } else if (wardNum == highest[0]) {
        fillOp = 1;
        col = 'black';
    }

    var settings = {
        color: col,
        fillOpacity: fillOp
    };

    return settings;
}

function redrawChart(stCode, isRedraw) {
    var url = 'http://cwfy-api-staging.smartchicagoapps.org/requests/' + stCode + '/counts.json?end_date=' + currWeekEnd.format(dateFormat) + '&count=' + numOfDays + '&callback=?';
    $.getJSON(
        url,
        function(response) {
            var counts = _.pairs(response).slice(1,51);
            var sorted = _.sortBy(counts,function(pair) { return pair[1]; });

            var lowest = sorted[0];
            var highest = sorted[49];

            if (!isRedraw) {
                for (var path in wardPaths) {
                    var wardNum = parseInt(path, 10);
                    var poly = L.polygon(
                        wardPaths[path],
                        $.extend({
                            id: wardNum,
                            opacity: 1,
                            weight: 2
                        }, calculateLayerSettings(wardNum, highest, lowest))
                    );
                    poly.bindPopup('<a href="/wards/' + wardNum + '/">Ward ' + wardNum + '</a>');
                    allWards.addLayer(poly);
                }

                allWards.addTo(window.map);
            } else {
                allWards.eachLayer(function(layer) {
                    layer.setStyle(calculateLayerSettings(layer.options.id, highest, lowest));
                });
            }
        }
    );
}

$(function () {
    $('.prevST').click(function(evt) {
        evt.preventDefault();
        redrawChart(serviceTypes[--stIndex][1].code, true);
    });

    $('.nextST a').click(function(evt) {
        evt.preventDefault();
        redrawChart(serviceTypes[++stIndex][1].code, true);
    });

    for (var ward in WARDS) {<commit_msg>Made the info box on the hompage a little more dynamic.<commit_after>var wardPaths = [];
var wardPolys = [];
var currWeekEnd = moment().day(-1).startOf('day');
var dateFormat = 'YYYY-MM-DD';
var numOfDays = 7;

var stIndex = 0;
var serviceTypesJSON = {
    "graffiti_removal": {
        "code": "4fd3b167e750846744000005",
        "name": "Graffiti Removal"
    },
    "restaurant_complaint": {
        "code": "4fd6e4ece750840569000019",
        "name": "Restaurant Complaint"
    },
    "rodent_baiting_rat_complaint": {
        "code": "4fd3b9bce750846c5300004a",
        "name": "<NAME> / Rat Complaint"
    },
    "tree_debris": {
        "code": "4fd3bbf8e750846c53000069",
        "name": "Tree Debris"
    },
    "abandoned_vehicle": {
        "code": "4ffa4c69601827691b000018",
        "name": "Abandoned Vehicle"
    },
    "street_light_1_out": {
        "code": "4ffa9f2d6018277d400000c8",
        "name": "Street Light 1 / Out"
    },
    "pavement_cavein_survey": {
        "code": "4ffa971e6018277d4000000b",
        "name": "Pavement Cave-In Survey"
    },
    "alley_light_out": {
        "code": "4ffa9cad6018277d4000007b",
        "name": "Alley Light Out"
    },
    "building_violation": {
        "code": "4fd3bd72e750846c530000cd",
        "name": "Building Violation"
    },
    "traffic_signal_out": {
        "code": "4ffa9db16018277d400000a2",
        "name": "Traffic Signal Out"
    },
    "street_cut_complaint": {
        "code": "4ffa995a6018277d4000003c",
        "name": "Street Cut Complaints"
    },
    "sanitation_code_violation": {
        "code": "4fd3b750e750846c5300001d",
        "name": "Sanitation Code Violation"
    },
    "pothole_in_street": {
        "code": "4fd3b656e750846c53000004",
        "name": "Pothole in Street"
    },
    "street_lights_all_out": {
        "code": "4fd3bd3de750846c530000b9",
        "name": "Street Lights All / Out"
    }
};
var serviceTypes = _.pairs(serviceTypesJSON);

function calculateLayerSettings(wardNum, highest, lowest) {
    var fillOp = 0.1;
    var col = '#0873AD';

    if (wardNum == lowest[0]) {
        fillOp = 1;
    } else if (wardNum == highest[0]) {
        fillOp = 1;
        col = 'black';
    }

    var settings = {
        color: col,
        fillOpacity: fillOp
    };

    return settings;
}

function redrawChart(stCode, isRedraw) {
    var url = 'http://cwfy-api-staging.smartchicagoapps.org/requests/' + stCode + '/counts.json?end_date=' + currWeekEnd.format(dateFormat) + '&count=' + numOfDays + '&callback=?';
    $.getJSON(
        url,
        function(response) {
            var counts = _.pairs(response).slice(1,51);
            var sorted = _.sortBy(counts,function(pair) { return pair[1]; });

            var lowest = sorted[0];
            var highest = sorted[49];

            if (!isRedraw) {
                for (var path in wardPaths) {
                    var wardNum = parseInt(path, 10);
                    var poly = L.polygon(
                        wardPaths[path],
                        $.extend({
                            id: wardNum,
                            opacity: 1,
                            weight: 2
                        }, calculateLayerSettings(wardNum, highest, lowest))
                    );
                    poly.bindPopup('<a href="/wards/' + wardNum + '/">Ward ' + wardNum + '</a>');
                    allWards.addLayer(poly);
                }

                allWards.addTo(window.map);
            } else {
                allWards.eachLayer(function(layer) {
                    layer.setStyle(calculateLayerSettings(layer.options.id, highest, lowest));
                });
            }
        }
    );
}

function updateST(i) {
    var st = serviceTypes[i][1];
    $('.st-info h2').text(st.name);
    redrawChart(st.code, true);
}

$(function () {
    $('.prevST').click(function(evt) {
        evt.preventDefault();
        updateST(--stIndex);
    });

    $('.nextST a').click(function(evt) {
        evt.preventDefault();
        updateST(++stIndex);
    });

    for (var ward in WARDS) {
{'fraction_non_alphanumeric': 0.14376163873370576, 'fraction_numerical': 0.06778398510242085, 'mean_word_length': 1.9914593390271074, 'pattern_counts': {'":': 84, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4306366', 'n_tokens_mistral': 3054, 'n_tokens_neox': 2661, 'n_words': 476}