<commit_before>'use strict';

const _ = require('lodash');
const CarPark = require('../models').CarPark;
const overAveragePercentage = 10;
const rankings = {
    GREEN: {value: 0, name: "Green"},
    ORANGE: {value: 1, name: "Orange"},
    RED: {value: 2, name: "Red"}
}

function computeGreenRankingLimit(average) {
    return average;
}

function computeOrangeRankingLimit(average) {
    return average + average * overAveragePercentage / 100;
}

function selectTag(greenRankingLimit, orangeRankingLimit, price) {
    if (price < greenRankingLimit)
	return rankings.GREEN;
    if (price < orangeRankingLimit)
	return rankings.ORANGE;
    return rankings.RED;
}

function updateRanking(carParks) {
    const averages = [];
    const prices = [];
    for (const carPark of carParks) {
	prices = prices.concat(carPark.prices);
    }
    // Sets price averages
    for (const duration in _.groupby(prices, duration)) {
	averages[duration] = _.sum(prices) / prices.length;
    }

    // Computes ranking
    for (const carPark of carParks) {
	_.map(carPark.prices, price => {
	    const greenRankingLimit = computeGreenRankingLimit(averages[price.duration]);
	    const orangeRankingLimit = computeOrangeRankingLimit(averages[price.duration]);
	    price.ranking = selectTag(greenRankingLimit, orangeRankingLimit, price.price).value;
	});
    }
}

module.exports = {
    updateRanking
};<commit_msg>A few fixes in ranking.js<commit_after>'use strict';

const _ = require('lodash');
const CarPark = require('../models').CarPark;
const overAveragePercentage = 10;
const rankings = {
    GREEN: {value: 0, name: "Green"},
    ORANGE: {value: 1, name: "Orange"},
    RED: {value: 2, name: "Red"}
}

function computeGreenRankingLimit(average) {
    return average;
}

function computeOrangeRankingLimit(average) {
    return average + average * overAveragePercentage / 100;
}

function selectTag(greenRankingLimit, orangeRankingLimit, price) {
    if (price < greenRankingLimit)
	return rankings.GREEN;
    if (price < orangeRankingLimit)
	return rankings.ORANGE;
    return rankings.RED;
}

function updateRanking(carParks) {
    const averages = [];
    const prices = [];
    for (const carPark of carParks) {
	prices = prices.concat(carPark.prices);
    }
    // Sets price averages
    _.groupby(prices, duration)).forEach(function(key, values) {
	averages[key] = _.sum(values) / values.length;
    });

    // Computes ranking
    for (const carPark of carParks) {
	_.map(carPark.prices, price => {
	    const greenRankingLimit = computeGreenRankingLimit(averages[price.duration]);
	    const orangeRankingLimit = computeOrangeRankingLimit(averages[price.duration]);
	    price.ranking = selectTag(greenRankingLimit, orangeRankingLimit, price.price).value;
	});
    }
}

module.exports = {
    updateRanking
};
{'fraction_non_alphanumeric': 0.12286324786324786, 'fraction_numerical': 0.005698005698005698, 'mean_word_length': 4.107272727272727, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2705533', 'n_tokens_mistral': 940, 'n_tokens_neox': 872, 'n_words': 201}