<commit_before>/**
 * Created by atomic on 2/16/17.
 */
var data = require('../data.json');
var hist = require('../history.json');
var destress = require('../destress.json');
var fs = require("fs");

exports.getJSON = function(req, res) {
    // get a random palette from the top ones
    // var randomPalette = palettes[Math.floor(palettes.length * Math.random())];
    // res.send('Your random palette is called: ' + randomPalette['title']);
    res.json(data.activities);
};

exports.removeActivity = function (req, res) {

    deleteActivity(req.body.id, true);
    res.json(data.activities);
};


exports.checkActivity = function (req, res) {

    let now = new Date();
    let deleted = false;
    for (let act_id in data.activities) {
        let x = new Date(data.activities[act_id].date_object);
        let diff = new Date(now - x);
        console.log('now: ' + now + ', x: ' + x);
        console.log('diff: ' + diff.getTime());
        console.log('minutes difference : ' + diff.getMinutes());
        if(diff.getTime() > 0) {
            deleteActivity(act_id, false);
            deleted = true;
        }
    }
    res.send(deleted);
};

exports.removeDestress = function (req, res) {
    console.log('message : ' + req.body.message);
    destress.custom = destress.custom.filter(function(e){
        return e.message != req.body.message;
    });
    fs.writeFile('destress.json', JSON.stringify(destress, null, '\t'), function (err) {
        if (err) throw err;
        console.log('destress activity: [' + req.body.message + ']  is saved!');
    });
    res.json(destress);
};

exports.doDestress = function (req, res) {
    let val = parseInt(req.body.value);
    data.total_stress = data.total_stress - val;
    fs.writeFile('data.json', JSON.stringify(data, null, '\t'), function (err) {
        if (err) throw err;
        console.log('Activity is saved!');<commit_msg>fixed value go below negative<commit_after>/**
 * Created by atomic on 2/16/17.
 */
var data = require('../data.json');
var hist = require('../history.json');
var destress = require('../destress.json');
var fs = require("fs");

exports.getJSON = function(req, res) {
    // get a random palette from the top ones
    // var randomPalette = palettes[Math.floor(palettes.length * Math.random())];
    // res.send('Your random palette is called: ' + randomPalette['title']);
    res.json(data.activities);
};

exports.removeActivity = function (req, res) {

    deleteActivity(req.body.id, true);
    res.json(data.activities);
};


exports.checkActivity = function (req, res) {

    let now = new Date();
    let deleted = false;
    for (let act_id in data.activities) {
        let x = new Date(data.activities[act_id].date_object);
        let diff = new Date(now - x);
        console.log('now: ' + now + ', x: ' + x);
        console.log('diff: ' + diff.getTime());
        console.log('minutes difference : ' + diff.getMinutes());
        if(diff.getTime() > 0) {
            deleteActivity(act_id, false);
            deleted = true;
        }
    }
    res.send(deleted);
};

exports.removeDestress = function (req, res) {
    console.log('message : ' + req.body.message);
    destress.custom = destress.custom.filter(function(e){
        return e.message != req.body.message;
    });
    fs.writeFile('destress.json', JSON.stringify(destress, null, '\t'), function (err) {
        if (err) throw err;
        console.log('destress activity: [' + req.body.message + ']  is saved!');
    });
    res.json(destress);
};

exports.doDestress = function (req, res) {
    let val = parseInt(req.body.value);
    data.total_stress = data.total_stress - val;
    if (data.total_stress < 0) {
        data.total_stress = 0;  // prevent negative stress value
    }

    fs.writeFile('data.json', JSON.stringify(data, null, '\t'), function (err) {
        if (err) throw err;
        console.log('Activity is saved!');
{'fraction_non_alphanumeric': 0.16670934699103712, 'fraction_numerical': 0.003585147247119078, 'mean_word_length': 2.833169774288518, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '2818846', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1236, 'n_words': 288}