<commit_before>'use strict';

var mongoose = require('mongoose'),
    _ = require('lodash'),
    crypto = require('crypto'),
    counter = require('../services/counter'),
    applications = require('../services/applications');

function tick(req, res){
    var ipAddr = req.headers["x-forwarded-for"],
        app = req.params.app,
        userId = req.params.user,
        user, list;

    if (userId){
        //TODO: check for that user in database, maybe cache that values on init
        user = userId;
    } else {
        if (ipAddr){
            list = ipAddr.split(",");
            ipAddr = list[list.length-1];
        } else {
            ipAddr = req.ip;
        }

        user = crypto.createHash('md5').update(ipAddr).digest('hex');
    }

    counter.count(app, user)
        .then(function(result){
            res.status(200).send(user);
        }, function(){
            res.status(400).send('ERROR');
        });
}

function recalculateApps(req, res){<commit_msg>notice about Heroku hosting added<commit_after>'use strict';

var mongoose = require('mongoose'),
    _ = require('lodash'),
    crypto = require('crypto'),
    counter = require('../services/counter'),
    applications = require('../services/applications');

function tick(req, res){
    //WARNING: this code should be used on Heroku alike hosting providers
    //if you use own hosting then it is very likely that you need to
    //rewrite the mechanic of ip acquirement
    var ipAddr = req.headers["x-forwarded-for"],
        app = req.params.app,
        userId = req.params.user,
        user, list;

    if (userId){
        //TODO: check is that user in database, maybe cache that values on init
        user = userId;
    } else {
        if (ipAddr){
            list = ipAddr.split(",");
            ipAddr = list[list.length-1];
        } else {
            ipAddr = req.ip;
        }

        user = crypto.createHash('md5').update(ipAddr).digest('hex');
    }

    counter.count(app, user)
        .then(function(result){
            res.status(200).send(user);
        }, function(){
            res.status(400).send('ERROR');
        });
}

function recalculateApps(req, res){
{'fraction_non_alphanumeric': 0.1456132292145154, 'fraction_numerical': 0.007349563619660083, 'mean_word_length': 2.2123893805309733, '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': '1189913', 'n_tokens_mistral': 643, 'n_tokens_neox': 635, 'n_words': 158}