<commit_before>var db = require('./database');
var io;

var getUserId = function(callback) {
	db.getUID(callback);
};

// var saveIPN = function(body) {
// 	db.save()
// };

var saveEntry = function(body, callback) {
	if(typeof callback !== 'function') {
		callback = function(){};
	}

	if(!body) {
		return callback('Invalid Body Data');
	}

	var uid = +body.uid;
	if(isNaN(uid)) {
		callback('Invalid UID');
	}

	db.save(uid, 'guess', body, callback);

	getChartData(function(err) {
		io.emit('chartData', chartData);
	});
};

var saveIPN = function(ipn, callback) {
	if(typeof callback !== 'function') {
		callback = function(){};
	}

	if(!ipn) {
		return callback('Invalid IPN Data');
	}

	db.getIPNID(function(err, ipnid) {
		if(err) return callback('Unable to retrieve valid IPN ID');
		db.save(ipnid, 'ipn', ipn, callback);
	});
};

var getChartData = function(callback) {
	if(typeof callback !== 'function') {
		callback = function(){};
	}

	db.getAll('guess', function(err, guesses) {
		if(!guesses) return callback('No guesses.');
		parseChartData(guesses, function(err) {
			callback(err);
		});
	});
};

exports.loadSocketIO = function(socketio) {
	io = socketio;

	getChartData();

	io.on('connection', function(socket) {
		socket.emit('chartData', chartData);
	});
};

exports.getUserId = getUserId;
exports.saveEntry = saveEntry;
exports.getChartData = getChartData;

function getTimeNow() {
	var year = new Date().getUTCFullYear();<commit_msg>include saveIPN function<commit_after>var db = require('./database');
var io;

var getUserId = function(callback) {
	db.getUID(callback);
};

// var saveIPN = function(body) {
// 	db.save()
// };

var saveEntry = function(body, callback) {
	if(typeof callback !== 'function') {
		callback = function(){};
	}

	if(!body) {
		return callback('Invalid Body Data');
	}

	var uid = +body.uid;
	if(isNaN(uid)) {
		callback('Invalid UID');
	}

	db.save(uid, 'guess', body, callback);

	getChartData(function(err) {
		io.emit('chartData', chartData);
	});
};

var saveIPN = function(ipn, callback) {
	if(typeof callback !== 'function') {
		callback = function(){};
	}

	if(!ipn) {
		return callback('Invalid IPN Data');
	}

	db.getIPNID(function(err, ipnid) {
		if(err) return callback('Unable to retrieve valid IPN ID');
		db.save(ipnid, 'ipn', ipn, callback);
	});
};

var getChartData = function(callback) {
	if(typeof callback !== 'function') {
		callback = function(){};
	}

	db.getAll('guess', function(err, guesses) {
		if(!guesses) return callback('No guesses.');
		parseChartData(guesses, function(err) {
			callback(err);
		});
	});
};

exports.loadSocketIO = function(socketio) {
	io = socketio;

	getChartData();

	io.on('connection', function(socket) {
		socket.emit('chartData', chartData);
	});
};

exports.getUserId = getUserId;
exports.saveEntry = saveEntry;
exports.getChartData = getChartData;
exports.saveIPN = saveIPN;

function getTimeNow() {
	var year = new Date().getUTCFullYear();
{'fraction_non_alphanumeric': 0.18098782138024358, 'fraction_numerical': 0.0, 'mean_word_length': 4.611005692599621, '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': '4395845', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1045, 'n_words': 217}