<commit_before>var rankingController = module.exports = {};

var _ = require('lodash');
var q = require('q');
var moment = require('moment');
var mongoose = require('mongoose');
var Ranking = require('./ranking').model;
var helper = require('../helper');
var mongoService = require('../mongoService');
var rankingService = require('./rankingService');
var expressService = require('../expressService');

expressService.addStandardMethods(rankingController, rankingService);

rankingController.getRankings = function(req, res) {
    var rankingSystemRef = req.param('rankingSystemRef');
    var periodStart = req.param('startDate');
    var periodEnd = req.param('endDate');
    var limit = 30;
    if (req.param('per_page') && req.param('per_page') > 0){
        limit = req.param('per_page');
    }

    if (limit > 100) limit = 100;

    var offset = 0;
    if (req.param('page') && req.param('page') > 0){
        offset = req.param('page')-1;
    }

    if (periodStart != null){
        periodStart = moment(periodStart).toDate();
    }

    if (periodEnd != null){
        periodEnd = moment(periodEnd).toDate();
    }

    rankingService.calculateRankings(periodStart, periodEnd, rankingSystemRef).then(function(rankingResults){
        res.set('total', rankingResults.length);
        res.jsonp(200, rankingResults.slice(limit*offset, limit));
    },function(error){
        helper.errorResponse(res, error);
    });
};<commit_msg>Fixed a bug in the ranking paging<commit_after>var rankingController = module.exports = {};

var _ = require('lodash');
var q = require('q');
var moment = require('moment');
var mongoose = require('mongoose');
var Ranking = require('./ranking').model;
var helper = require('../helper');
var mongoService = require('../mongoService');
var rankingService = require('./rankingService');
var expressService = require('../expressService');

expressService.addStandardMethods(rankingController, rankingService);

rankingController.getRankings = function(req, res) {
    var rankingSystemRef = req.param('rankingSystemRef');
    var periodStart = req.param('startDate');
    var periodEnd = req.param('endDate');
    var limit = 30;
    if (req.param('per_page') && req.param('per_page') > 0){
        limit = req.param('per_page');
    }

    if (limit > 100) limit = 100;

    var offset = 0;
    if (req.param('page') && req.param('page') > 0){
        offset = req.param('page')-1;
    }

    if (periodStart != null){
        periodStart = moment(periodStart).toDate();
    }

    if (periodEnd != null){
        periodEnd = moment(periodEnd).toDate();
    }

    rankingService.calculateRankings(periodStart, periodEnd, rankingSystemRef).then(function(rankingResults){
        res.set('total', rankingResults.length);
        res.jsonp(200, rankingResults.slice(limit*offset, (limit*offset)+limit));
    },function(error){
        helper.errorResponse(res, error);
    });
};
{'fraction_non_alphanumeric': 0.16340542396155167, 'fraction_numerical': 0.010298661174047374, 'mean_word_length': 3.930626057529611, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4489987', 'n_tokens_mistral': 889, 'n_tokens_neox': 842, 'n_words': 180}