<commit_before>var _ = require('underscore')._;

module.exports = function(app, settings) {
    /**
     * Map loader, express route middleware.
     */
    function loadMap(req, res, next) {
        if (req.param('mapfile_64')) {
            var path = require('path');
            var Map = require('tilelive.js').Map;
            var map = new Map(req.param('mapfile_64'), path.join(__dirname, settings.mapfile_dir), true);
            map.localize(function(err) {
                if (err) {
                    next(new Error('Error loading map file'));
                    return;
                }
                res.map = map.mapnik_map();
                next();
            });
        }
        else {
            next(new Error('Map could not be loaded.'));
        }
    }

    /**
     * Layer loader, express route middleware.
     */
    function loadLayer(req, res, next) {
        res.layers = [];
        var layers = res.map.layers();
        var data = res.map.describe_data();
        for (var i = 0; i < layers.length; i++) {
            var id = layers[i].datasource.id;
            var layer = {
                id: id,
                fields: {},
                features: res.map.features(i)
            };

            for (var fieldId in data[id].fields) {
                layer.fields[fieldId] = {type: data[id].fields[fieldId]};
                var field = layer.fields[fieldId];
                var values = _.pluck(layer.features, fieldId);
                if (field.type == 'Number') {
                    field.min = Math.min.apply(Math, values);
                    field.max = Math.max.apply(Math, values);
                }<commit_msg>Making inspect functionality use new mapnik_map style<commit_after>var _ = require('underscore')._;

module.exports = function(app, settings) {
    /**
     * Map loader, express route middleware.
     */
    function loadMap(req, res, next) {
        if (req.param('mapfile_64')) {
            var path = require('path');
            var Map = require('tilelive.js').Map;
            var map = new Map(req.param('mapfile_64'), path.join(__dirname, settings.mapfile_dir), true);
            map.localize(function(err) {
                if (err) {
                    next(new Error('Error loading map file'));
                    return;
                }
                map.mapnik_map(function(err, map){
                    if (err) return next(new Error('Error rendering map'));
                    res.map = map;
                    next();
                });
            });
        }
        else {
            next(new Error('Map could not be loaded.'));
        }
    }

    /**
     * Layer loader, express route middleware.
     */
    function loadLayer(req, res, next) {
        res.layers = [];
        var layers = res.map.layers();
        var data = res.map.describe_data();
        for (var i = 0; i < layers.length; i++) {
            var id = layers[i].datasource.id;
            var layer = {
                id: id,
                fields: {},
                features: res.map.features(i)
            };

            for (var fieldId in data[id].fields) {
                layer.fields[fieldId] = {type: data[id].fields[fieldId]};
                var field = layer.fields[fieldId];
                var values = _.pluck(layer.features, fieldId);
                if (field.type == 'Number') {
                    field.min = Math.min.apply(Math, values);
                    field.max = Math.max.apply(Math, values);
                }
{'fraction_non_alphanumeric': 0.13180272108843538, 'fraction_numerical': 0.002834467120181406, 'mean_word_length': 1.4221002059025394, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2514851', 'n_tokens_mistral': 997, 'n_tokens_neox': 941, 'n_words': 225}