<commit_before>var _ = require('underscore');
var models = require('../models');

var Record = models.Record;

var recordPage = function(req, res){
	Record.RecordModel.findByUser(req.session.account.username, function(err, docs){
		if(err){
			console.log(err);
			return res.status(400).json({error: "An error occurred"});
		}

		res.render('record', {records: docs});
	});
};

var addRecord = function(req, res){

	console.log('rarw');

	var recordData = {
		user: req.session.account.username,
		type: req.body.type,
		level: req.body.level,
		maxHp: req.body.maxHp,
		maxEnergy: req.body.maxEnergy,
		minDamage: req.body.minDamage,
		maxDamage: req.body.maxDamage,
		deaths: req.body.deaths,
		partySize: req.body.partySize,
		partyLevel: req.body.partyLevel,
		partyDeaths: req.body.partyDeaths,
		enemiesKilled: req.body.enemiesKilled,
		createdDate: req.body.date
	};

	var newRecord = new Record.RecordModel(recordData);

	newRecord.save(function(err){
		if(err){
			console.log(err);
			return res.status(400).json({error:'An error occurred'});
		}
		console.log('successfully recored data');
	});

	res.json({success: '/'});
};

var highScorePage = function(req, res){

	var callback = function(err, docs) {
        if(err) {
            return res.json({err:err}); //if error, return it 
        }

        //return success
        if(req.session.account){	
        	return res.render('highscore', {csrfToken: req.csrfToken(), user: req.session.account.username, records: docs}); 
        }
        else{
        	return res.render('highscore', {csrfToken: req.csrfToken(), records: docs});
        }
    };

    findAllRecords(req, res, callback);
};

var findAllRecords = function(req, res, callback) {
	Record.RecordModel.find(callback);
};

module.exports.recordPage = recordPage;
module.exports.addRecord = addRecord;
module.exports.highScorePage = highScorePage;<commit_msg>highscore sorts score by enemy kills<commit_after>var _ = require('underscore');
var models = require('../models');

var Record = models.Record;

var recordPage = function(req, res){
	Record.RecordModel.findByUser(req.session.account.username, function(err, docs){
		if(err){
			console.log(err);
			return res.status(400).json({error: "An error occurred"});
		}

		res.render('record', {records: docs});
	});
};

var addRecord = function(req, res){

	console.log('rarw');

	var recordData = {
		user: req.session.account.username,
		type: req.body.type,
		level: req.body.level,
		maxHp: req.body.maxHp,
		maxEnergy: req.body.maxEnergy,
		minDamage: req.body.minDamage,
		maxDamage: req.body.maxDamage,
		deaths: req.body.deaths,
		partySize: req.body.partySize,
		partyLevel: req.body.partyLevel,
		partyDeaths: req.body.partyDeaths,
		enemiesKilled: req.body.enemiesKilled,
		createdDate: req.body.date
	};

	var newRecord = new Record.RecordModel(recordData);

	newRecord.save(function(err){
		if(err){
			console.log(err);
			return res.status(400).json({error:'An error occurred'});
		}
		console.log('successfully recored data');
	});

	res.json({success: '/'});
};

var highScorePage = function(req, res){

	var callback = function(err, docs) {
        if(err) {
            return res.json({err:err}); //if error, return it 
        }

         docs.sort(function(a,b){
        	return  b.enemiesKilled - a.enemiesKilled;
        });

        //return success
        if(req.session.account){	
        	return res.render('highscore', {csrfToken: req.csrfToken(), user: req.session.account.username, records: docs}); 
        }
        else{
        	return res.render('highscore', {csrfToken: req.csrfToken(), records: docs});
        }
    };

    findAllRecords(req, res, callback);
};

var findAllRecords = function(req, res, callback) {
	Record.RecordModel.find(callback);
};

module.exports.recordPage = recordPage;
module.exports.addRecord = addRecord;
module.exports.highScorePage = highScorePage;
{'fraction_non_alphanumeric': 0.15343237704918034, 'fraction_numerical': 0.0030737704918032786, 'mean_word_length': 3.6710526315789473, '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': '891698', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1295, 'n_words': 250}