<commit_before>var mongoose = require('mongoose');

var appSchema = mongoose.Schema({
    appId: String,
    title: String,
    developer: String,
    url: String,
    icon: String,
    installs: Number,
    score: Number,
    reviews: Number,
    description: String,
    impressions: {type: Number, default: 0},
    installs: {type: Number, default: 0},
    priority: {type: Number, index: true}
});

//TODO call this automatically on save
appSchema.methods.setPriority = function() {

    var installsScore = this.getInstallsScore();
    var ratingScore = this.getRatingScore();

    if (this.reviewsNonRepresentative()) {
        //consider only installs
        this.priority = 3 * installsScore;
    } else {

        if (this.highReviewRatio()) {
            //more weight to score than installs
            this.priority = 2 * ratingScore + 1 * installsScore;
        } else {
            //more weight to installs than score
            this.priority = 1 * ratingScore + 2 * installsScore;
        }
    }
};

/*
* Returns true if the amount of reviews is too low for the score to be
* considered representative of the app's quality.
*/
appSchema.methods.reviewsNonRepresentative = function() {
    return this.reviews < 100;
};

/*
* Returns true if the amount of reviews is considered high in relatino to the
* amount of installs.
*/
appSchema.methods.highReviewRatio = function() {
    if (!this.reviews) return false;

    //avg seems to be 15~20
    return (this.installs / this.reviews ) < 10;
};

/*
* Normalizes the app's installs to a 0-10 score, giving a better score to the
* less installed apps.
*/
appSchema.methods.getInstallsScore = function() {
    //this abuses the fact that the scraper only gets round estimates
    switch (this.installs) {
        case 0: return 10;
        case 100: return 9.5;
        case 500: return 9;
        case 1000: return 8;
        case 5000: return 5;
        case 10000: return 2;
        case 50000: return 1;
        default: throw new Error("unexpected number: " + this.installs);
    }
};

/*
* Normalizes the app's score to 0-10.
*/
appSchema.methods.getRatingScore = function() {
    return this.score * 2;
};

module.exports = mongoose.model('App', appSchema);<commit_msg>fix unexpected installs number<commit_after>var mongoose = require('mongoose');

var appSchema = mongoose.Schema({
    appId: String,
    title: String,
    developer: String,
    url: String,
    icon: String,
    installs: Number,
    score: Number,
    reviews: Number,
    description: String,
    impressions: {type: Number, default: 0},
    installs: {type: Number, default: 0},
    priority: {type: Number, index: true}
});

//TODO call this automatically on save
appSchema.methods.setPriority = function() {

    var installsScore = this.getInstallsScore();
    var ratingScore = this.getRatingScore();

    if (this.reviewsNonRepresentative()) {
        //consider only installs
        this.priority = 3 * installsScore;
    } else {

        if (this.highReviewRatio()) {
            //more weight to score than installs
            this.priority = 2 * ratingScore + 1 * installsScore;
        } else {
            //more weight to installs than score
            this.priority = 1 * ratingScore + 2 * installsScore;
        }
    }
};

/*
* Returns true if the amount of reviews is too low for the score to be
* considered representative of the app's quality.
*/
appSchema.methods.reviewsNonRepresentative = function() {
    return this.reviews < 100;
};

/*
* Returns true if the amount of reviews is considered high in relatino to the
* amount of installs.
*/
appSchema.methods.highReviewRatio = function() {
    if (!this.reviews) return false;

    //avg seems to be 15~20
    return (this.installs / this.reviews ) < 10;
};

/*
* Normalizes the app's installs to a 0-10 score, giving a better score to the
* less installed apps.
*/
appSchema.methods.getInstallsScore = function() {
    //this abuses the fact that the scraper only gets round estimates
    switch (this.installs) {
        case 0: return 10;
        case 50: return 9.5;
        case 100: return 9;
        case 500: return 8;
        case 1000: return 7.5;
        case 5000: return 5;
        case 10000: return 2;
        case 50000: return 1;
        default: throw new Error("unexpected number: " + this.installs);
    }
};

/*
* Normalizes the app's score to 0-10.
*/
appSchema.methods.getRatingScore = function() {
    return this.score * 2;
};

module.exports = mongoose.model('App', appSchema);
{'fraction_non_alphanumeric': 0.10671674768007071, 'fraction_numerical': 0.026071586389748123, 'mean_word_length': 2.6894865525672373, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4246020', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1318, 'n_words': 456}