<commit_before>var express = require('express');
var models = require('../model/models');
var moment = require('moment')
var router = express.Router();

function doList(callback, filter) {
    filter = filter || {};
    filter['$or'] = [
        {isDuplicate: false},
        {isDuplicate: null}
    ]
    // list non-duplicates
    models.Apartment.find(filter)
        .sort({createdAt: -1})
        .exec(function (errors, l) {
            if (errors) return console.error("LIST error", errors);
            for (var i = 0; i < l.length; i++) {
                l[i].createdAtStr = moment(new Date(l[i].createdAt)).format("DD MMMM YY");
                for (var j = 0; l[i].duplicates && j < l[i].duplicates.length; j++) {
                    l[i].duplicates[j].createdAtStr = moment(new Date(l[i].duplicates[j].createdAt)).format("DD MMMM YY");
                }
            }
            callback(l);
        });
}

router.get('/star', function (req, res) {
    models.Apartment.findOne({
        id: req.query.id
    })
        .exec(function (errors, a) {
            if (errors) {
                res.status(500).send("ERROR" + errors);
                return console.error("STAR error", errors);
            }
            if (!a) {
                res.status(500).send("NOT FOUND " + req.query.id);
                return console.error("STAR error", "NOT FOUND " + req.query.id);
            }
            var starred = a.starred ? false : true;
            models.Apartment.update({id: a.id}, {starred: starred}, function (e, n, r) {
                if (e) console.error("STAR error", a.id, e, n, r);
                models.Apartment.findOne({
                    id: req.query.id
                })
                    .exec(function (errors, a) {
                        if (errors) {
                            res.status(500).send("ERROR" + errors);
                            return console.error("STAR error", errors);
                        }
                        res.json(a);
                    });
            });
        });
});

router.get('/json', function (req, res) {
    doList(function (l) {
        res.json(l);
    });
});

router.get('/', function (req, res) {
    doList(function (l) {
        res.render('list', {
            apartments: l
        });
    });
});

router.get('/starred', function (req, res) {
    doList(function (l) {
        res.render('list', {
            apartments: l
        });
    }, {starred: true});
});


router.get('/stats', function (req, res) {
    res.render('stats');
});

router.get('/stats/json', function (req, res) {
    models.Stat.find({}, function (e, l) {
        if (e) return res.status(500).send("ERROR " + e);
        res.json(l);
    })
});

router.get('/update', function (req, res) {
    models.Apartment.findOne({id: req.query.id}, function (e, a) {
        var ids = a.duplicates.map(function (x) {
            return x.id
        });
        ids.push(req.query.id);
//        models.Apartment.find({id: {'$in' : ids}}, function(e, l) {
//            console.log(l);
//        });
        models.Apartment.update({id: {'$in': ids}}, {address: req.query.address, area: req.query.area}, { multi: true }, function (e, n, r) {
            if (e) console.error("UPDATE error", ids, e, n, r);
            console.log("UPDATE made " + n + "pcs", r);
            res.redirect('/list#' + req.query.id);
        });

    });
});

module.exports = router;<commit_msg>clean up<commit_after>var express = require('express');
var models = require('../model/models');
var moment = require('moment')
var router = express.Router();

function doList(callback, filter) {
    filter = filter || {};
    filter['$or'] = [
        {isDuplicate: false},
        {isDuplicate: null}
    ]
    // list non-duplicates
    models.Apartment.find(filter)
        .sort({createdAt: -1})
        .exec(function (errors, l) {
            if (errors) return console.error("LIST error", errors);
            for (var i = 0; i < l.length; i++) {
                l[i].createdAtStr = moment(new Date(l[i].createdAt)).format("DD MMMM YY");
                for (var j = 0; l[i].duplicates && j < l[i].duplicates.length; j++) {
                    l[i].duplicates[j].createdAtStr = moment(new Date(l[i].duplicates[j].createdAt)).format("DD MMMM YY");
                }
            }
            callback(l);
        });
}

router.get('/star', function (req, res) {
    models.Apartment.findOne({
        id: req.query.id
    })
        .exec(function (errors, a) {
            if (errors) {
                res.status(500).send("ERROR" + errors);
                return console.error("STAR error", errors);
            }
            if (!a) {
                res.status(500).send("NOT FOUND " + req.query.id);
                return console.error("STAR error", "NOT FOUND " + req.query.id);
            }
            var starred = a.starred ? false : true;
            models.Apartment.update({id: a.id}, {starred: starred}, function (e, n, r) {
                if (e) console.error("STAR error", a.id, e, n, r);
                models.Apartment.findOne({
                    id: req.query.id
                })
                    .exec(function (errors, a) {
                        if (errors) {
                            res.status(500).send("ERROR" + errors);
                            return console.error("STAR error", errors);
                        }
                        res.json(a);
                    });
            });
        });
});

router.get('/json', function (req, res) {
    doList(function (l) {
        res.json(l);
    });
});

router.get('/', function (req, res) {
    doList(function (l) {
        res.render('list', {
            apartments: l
        });
    });
});

router.get('/starred', function (req, res) {
    doList(function (l) {
        res.render('list', {
            apartments: l
        });
    }, {starred: true});
});


router.get('/stats', function (req, res) {
    res.render('stats');
});

router.get('/stats/json', function (req, res) {
    models.Stat.find({}, function (e, l) {
        if (e) return res.status(500).send("ERROR " + e);
        res.json(l);
    })
});

router.get('/update', function (req, res) {
    models.Apartment.findOne({id: req.query.id}, function (e, a) {
        var ids = a.duplicates.map(function (x) {
            return x.id
        });
        ids.push(req.query.id);
        models.Apartment.update({id: {'$in': ids}}, {address: req.query.address, area: req.query.area}, { multi: true }, function (e, n, r) {
            if (e) console.error("UPDATE error", ids, e, n, r);
            console.log("UPDATE made " + n + "pcs", r);
            res.redirect('/list#' + req.query.id);
        });

    });
});

module.exports = router;
{'fraction_non_alphanumeric': 0.17846062933963658, 'fraction_numerical': 0.004431969271679716, 'mean_word_length': 1.7058353317346122, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2304022', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2071, 'n_words': 444}