<commit_before>// For OpenNorth Represent API calls

module.exports = function (app) {
    var represent = require('represent');

    app.get('/represent', function (req, res) {
        res.render('index.html');
    });

    app.get('/represent/postcode/:code', function (req, res) {

        //retrieve the datacache first
        var cacheKey = req.params.code;

        app.locals.datacache.get(cacheKey, function (err, data) {
            if (!err) {
                //in the cache
                console.log("cache retrieved");
                res.send(data);
            }
            else{

                represent.postalCode(req.params.code, function (err, data) {
                if (err) {
                    console.log("represent error" + JSON.stringify(err));
                    res.send(null);
                }
                else {
                    //store in the cache
                    app.locals.datacache.put(cacheKey, data, function (err, body) {
                        if (err) {
                            console.log("cache error" + JSON.stringify(err));
                        }
                        else {
                              console.log("cache stored: " + JSON.stringify(body));
                        }
                    });
                    res.send(data);
                }
                });<commit_msg>stored the required fields in datacache only<commit_after>// For OpenNorth Represent API calls

module.exports = function (app) {
    var represent = require('represent');

    app.get('/represent', function (req, res) {
        res.render('index.html');
    });

    app.get('/represent/postcode/:code', function (req, res) {

        //retrieve the datacache first
        var cacheKey = req.params.code;

        app.locals.datacache.get(cacheKey, function (err, data) {
            if (!err) {
                //in the cache
                console.log("cache retrieved");
                res.send(data);
            }
            else{

                represent.postalCode(req.params.code, function (err, data) {
                if (err) {
                    console.log("represent error" + JSON.stringify(err));
                    res.send(null);
                }
                else {
                    //store the candidate information in the cache only
                    var candidates=[];

                    data["candidates_centroid"].forEach(function(candidate){
                        var storedCandidate = {
                            name: null,
                            party_name:null,
                            personal_url: null,
                            photo_url: null
                        };

                        for (var key in storedCandidate){
                                storedCandidate[key] = candidate[key];
                        }
                        candidates.push(storedCandidate);
                    });

                    var usedInfo = {candidates_centroid:candidates};

                    app.locals.datacache.put(cacheKey,usedInfo , function (err, body) {
                        if (err) {
                            console.log("cache error" + JSON.stringify(err));
                        }
                        else {
                              console.log("cache stored: " + JSON.stringify(body));
                        }
                    });
                    res.send(usedInfo);
                }
                });
{'fraction_non_alphanumeric': 0.10505166475315729, 'fraction_numerical': 0.0, 'mean_word_length': 1.0805970149253732, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5141528', 'n_tokens_mistral': 868, 'n_tokens_neox': 794, 'n_words': 174}