<commit_before>var mongoose = require('mongoose');
var questionSchema = new mongoose.Schema({
    author: {
        type:mongoose.Schema.Types.ObjectId,
        ref:'User'
    },
    makeWith: String,
    language: String,
    question: [{
        type: {type: String},
        questionText: {type: String},
        image: {type: String},
        answers: [{
            text: String,
            url: String,
            attributesForTForMultiple: {
                isItRight: Boolean
            },
            attributesForSorting: {
                position: Number
            },
            attributesForLinking: {
                text1: String,
                text2: String,
                url1: String,
                url2: String
            },
            attributesForClickableArea: {
                x: Number,
                y: Number
            },
            attributesForEmptySpaces: {
                wordNumber: Number
            }
        }],
    }],
    keywords: [String],
    level: Number,
    totalAnswers: Number,
    correctAnswers: Number
});

questionSchema.statics.getQuestion=function(questionId,callback) {
    return this.findOne({'_id': {$in: questionId}}, callback);
}

questionSchema.statics.createQuestion=function(author,question, callback){
    question.author = author
    var new_question = new this(question);
    return new_question.save(callback);
};

questionSchema.statics.editQuestion=function(question,callback){
    return this.findOneAndUpdate(question._id, question, callback)
}

questionSchema.statics.updateLevel=function(questionId,userLevel,isCorrected,callback){
    this.findOne({_id:questionId}, function(err,question){
        if(err){
            return next(err);
        }
        var oldDifficult = question.level;
        var differentLevel = oldDifficult - userLevel;
        // caso in cui la domanda sia piÃ¹ difficile dell'abilitÃ  dell'utente:
        if(differentLevel <= 100 && differentLevel > 0){
            var scarto = oldDifficult - userLevel;
            if(isCorrected == true){
                if(scarto > 90){
                    question.level = oldDifficult + 11;
                }else if(scarto > 80){
                    question.level = oldDifficult + 10;
                }else if(scarto > 70){
                    question.level = oldDifficult + 9;
                }else if(scarto > 60){
                    question.level = oldDifficult + 8;
                }else if(scarto > 50){
                    question.level = oldDifficult + 7;
                }else if(scarto > 40){
                    question.level = oldDifficult + 6;
                }else if(scarto > 30){
                    question.level = oldDifficult + 5;
                }else if(scarto > 20){
                    question.level = oldDifficult + 4;
                }else if(scarto > 10){
                    question.level = oldDifficult + 3;
                }else if(scarto > 0){
                    question.level = oldDifficult + 2;
                }
            } else{
                if(scarto > 90){
                    question.level = oldDifficult - 2;
                }else if(scarto > 80){
                    question.level = oldDifficult - 3;
                }else if(scarto > 70){
                    question.level = oldDifficult - 4;
                }else if(scarto > 60){
                    question.level = oldDifficult - 5;
                }else if(scarto > 50){
                    question.level = oldDifficult - 6;
                }else if(scarto > 40){
                    question.level = oldDifficult - 7;
                }else if(scarto > 30){
                    question.level = oldDifficult - 8;
                }else if(scarto > 20){
                    question.level = oldDifficult - 9;
                }else if(scarto > 10){
                    question.level = oldDifficult - 10;
                }else if(scarto > 0){
                    question.level = oldDifficult - 11;
                }
            }
        }
        else{ // caso in cui la domanda sia piÃ¹ facile dell'abilitÃ  dell'utente
            var scarto = userLevel - oldDifficult;
            if(isCorrected == true){
                if(scarto > 90){
                    question.level = oldDifficult - 2;
                }else if(scarto > 80){
                    question.level = oldDifficult - 3;
                }else if(scarto > 70){
                    question.level = oldDifficult - 4;
                }else if(scarto > 60){
                    question.level = oldDifficult - 5;
                }else if(scarto > 50){
                    question.level = oldDifficult - 6;
                }else if(scarto > 40){
                    question.level = oldDifficult - 7;
                }else if(scarto > 30){
                    question.level = oldDifficult - 8;
                }else if(scarto > 20){
                    question.level = oldDifficult - 9;
                }else if(scarto > 10){
                    question.level = oldDifficult - 10;
                }else if(scarto > 0){
                    question.level = oldDifficult - 11;
                }else if(scarto == 0){
                    question.level = oldDifficult - 1;
                }
            } else{
                if(scarto > 90){
                    question.level = oldDifficult + 11;
                }else if(scarto > 80){
                    question.level = oldDifficult + 10;
                }else if(scarto > 70){
                    question.level = oldDifficult + 9;
                }else if(scarto > 60){
                    question.level = oldDifficult + 8;
                }else if(scarto > 50){
                    question.level = oldDifficult + 7;
                }else if(scarto > 40){
                    question.level = oldDifficult + 6;
                }else if(scarto > 30){
                    question.level = oldDifficult + 5;
                }else if(scarto > 20){
                    question.level = oldDifficult + 4;
                }else if(scarto > 10){
                    question.level = oldDifficult + 3;
                }else if(scarto > 0){
                    question.level = oldDifficult + 2;
                }else if(scarto == 0){
                    question.level = oldDifficult + 1;
                }
            }
        }
        // controllo che il livello non sia oltre i limiti
        if(question.level > 1000){
            question.level = 1000;
        }
        else if(question.level < 0){
            question.level = 0;
        }
        return question.save(callback);
    })

}

questionSchema.statics.addKeyword=function(questionId,keyword,callback){

}

questionSchema.statics.addCorrect=function(questionId){
    this.findOne({_id: questionId}, function(err, question){
        if (err) { return next(err); }
        question.correctAnswers += 1;
        return question.save()
    });
}

questionSchema.statics.addTotal=function(questionId){
    this.findOne({_id: questionId}, function(err, question){
        if (err) { return next(err); }
        question.totalAnswers += 1;
        return question.save()
    });
}

questionSchema.methods.getQuestion=function(questionId,callback){
    return Quiz.findOne({'_id':{$in:questionId}},callback);
};

module.exports = mongoose.model('Question', questionSchema);<commit_msg>Question controller e model updated<commit_after>var mongoose = require('mongoose');
var questionSchema = new mongoose.Schema({
    author: {
        type:mongoose.Schema.Types.ObjectId,
        ref:'User'
    },
    makeWith: String,
    language: String,
    question: [{
        type: {type: String},
        questionText: {type: String},
        image: {type: String},
        answers: [{
            text: String,
            url: String,
            attributesForTForMultiple: {
                isItRight: Boolean
            },
            attributesForSorting: {
                position: Number
            },
            attributesForLinking: {
                text1: String,
                text2: String,
                url1: String,
                url2: String
            },
            attributesForClickableArea: {
                x: Number,
                y: Number
            },
            attributesForEmptySpaces: {
                wordNumber: Number
            }
        }],
    }],
    keywords: [String],
    level: {type:Number, default: 500},
    totalAnswers: {type:Number, default: 0},
    correctAnswers: {type:Number, default: 0},
});

questionSchema.statics.getQuestion=function(questionId,callback) {
    return this.findOne({'_id': {$in: questionId}}, callback);
}

questionSchema.statics.createQuestion=function(author,question, callback){
    question.author = author
    var new_question = new this(question);
    return new_question.save(callback);
};

questionSchema.statics.editQuestion=function(question,callback){
    return this.findOneAndUpdate(question._id, question, callback)
}

questionSchema.statics.updateLevel=function(questionId,userLevel,isCorrected,callback){
    this.findOne({_id:questionId}, function(err,question){
        if(err){
            return next(err);
        }
        var oldDifficult = question.level;
        var differentLevel = oldDifficult - userLevel;
        // caso in cui la domanda sia piÃ¹ difficile dell'abilitÃ  dell'utente:
        if(differentLevel <= 100 && differentLevel > 0){
            var scarto = oldDifficult - userLevel;
            if(isCorrected == true){
                if(scarto > 90){
                    question.level = oldDifficult + 11;
                }else if(scarto > 80){
                    question.level = oldDifficult + 10;
                }else if(scarto > 70){
                    question.level = oldDifficult + 9;
                }else if(scarto > 60){
                    question.level = oldDifficult + 8;
                }else if(scarto > 50){
                    question.level = oldDifficult + 7;
                }else if(scarto > 40){
                    question.level = oldDifficult + 6;
                }else if(scarto > 30){
                    question.level = oldDifficult + 5;
                }else if(scarto > 20){
                    question.level = oldDifficult + 4;
                }else if(scarto > 10){
                    question.level = oldDifficult + 3;
                }else if(scarto > 0){
                    question.level = oldDifficult + 2;
                }
            } else{
                if(scarto > 90){
                    question.level = oldDifficult - 2;
                }else if(scarto > 80){
                    question.level = oldDifficult - 3;
                }else if(scarto > 70){
                    question.level = oldDifficult - 4;
                }else if(scarto > 60){
                    question.level = oldDifficult - 5;
                }else if(scarto > 50){
                    question.level = oldDifficult - 6;
                }else if(scarto > 40){
                    question.level = oldDifficult - 7;
                }else if(scarto > 30){
                    question.level = oldDifficult - 8;
                }else if(scarto > 20){
                    question.level = oldDifficult - 9;
                }else if(scarto > 10){
                    question.level = oldDifficult - 10;
                }else if(scarto > 0){
                    question.level = oldDifficult - 11;
                }
            }
        }
        else{ // caso in cui la domanda sia piÃ¹ facile dell'abilitÃ  dell'utente
            var scarto = userLevel - oldDifficult;
            if(isCorrected == true){
                if(scarto > 90){
                    question.level = oldDifficult - 2;
                }else if(scarto > 80){
                    question.level = oldDifficult - 3;
                }else if(scarto > 70){
                    question.level = oldDifficult - 4;
                }else if(scarto > 60){
                    question.level = oldDifficult - 5;
                }else if(scarto > 50){
                    question.level = oldDifficult - 6;
                }else if(scarto > 40){
                    question.level = oldDifficult - 7;
                }else if(scarto > 30){
                    question.level = oldDifficult - 8;
                }else if(scarto > 20){
                    question.level = oldDifficult - 9;
                }else if(scarto > 10){
                    question.level = oldDifficult - 10;
                }else if(scarto > 0){
                    question.level = oldDifficult - 11;
                }else if(scarto == 0){
                    question.level = oldDifficult - 1;
                }
            } else{
                if(scarto > 90){
                    question.level = oldDifficult + 11;
                }else if(scarto > 80){
                    question.level = oldDifficult + 10;
                }else if(scarto > 70){
                    question.level = oldDifficult + 9;
                }else if(scarto > 60){
                    question.level = oldDifficult + 8;
                }else if(scarto > 50){
                    question.level = oldDifficult + 7;
                }else if(scarto > 40){
                    question.level = oldDifficult + 6;
                }else if(scarto > 30){
                    question.level = oldDifficult + 5;
                }else if(scarto > 20){
                    question.level = oldDifficult + 4;
                }else if(scarto > 10){
                    question.level = oldDifficult + 3;
                }else if(scarto > 0){
                    question.level = oldDifficult + 2;
                }else if(scarto == 0){
                    question.level = oldDifficult + 1;
                }
            }
        }
        // controllo che il livello non sia oltre i limiti
        if(question.level > 1000){
            question.level = 1000;
        }
        else if(question.level < 0){
            question.level = 0;
        }
        return question.save(callback);
    })

}

questionSchema.statics.addKeyword=function(questionId,keyword,callback){

}

questionSchema.statics.addCorrect=function(questionId){
    this.findOne({_id: questionId}, function(err, question){
        if (err) { return next(err); }
        question.correctAnswers += 1;
        return question.save()
    });
}

questionSchema.statics.addTotal=function(questionId){
    this.findOne({_id: questionId}, function(err, question){
        if (err) { return next(err); }
        question.totalAnswers += 1;
        return question.save()
    });
}

questionSchema.methods.getQuestion=function(questionId,callback){
    return Quiz.findOne({'_id':{$in:questionId}},callback);
};

module.exports = mongoose.model('Question', questionSchema);
{'fraction_non_alphanumeric': 0.1027378693412849, 'fraction_numerical': 0.020398481973434534, 'mean_word_length': 1.403028822667318, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 87, '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': '910684', 'n_tokens_mistral': 4298, 'n_tokens_neox': 3892, 'n_words': 877}