<commit_before>/*jslint vars: false, browser: true, nomen: true */
/*global MOOC:true, _, jQuery, Backbone */

// Copyright 2012 Rooter Analysis S.L.
// Copyright (c) 2013 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

if (_.isUndefined(window.MOOC)) {
    window.MOOC = {};
}

(function ($, Backbone, _) {
    "use strict";

    var errorHandler = function () {
            MOOC.ajax.showAlert("generic");
            MOOC.ajax.hideLoading();
        },
        loadKQs = function (callback) {
            var promises = [];
            MOOC.models.course.each(function (unit) {
                unit.set("knowledgeQuantumList", new MOOC.models.KnowledgeQuantumList());
                promises.push($.ajax(MOOC.ajax.host + "privkq/?format=json&unit=" + unit.get("id"), {
                    success: function (data, textStatus, jqXHR) {
                        unit.get("knowledgeQuantumList").reset(_.map(data.objects, function (kq) {
                            var data = _.pick(kq, "id", "title", "videoID",
                                "teacher_comments", "supplementary_material",
                                "question", "order", "correct", "completed",
                                "normalized_weight", "peer_review_assignment");
                            data.id = parseInt(data.id, 10);
                            return data;
                        }));
                    }
                }));
            });
            $.when.apply(null, promises).done(callback).fail(errorHandler);
        },
        loadKQDetails = function (kq, callback) {
            var promises = [],
                questionUrl;

            if (kq.has("question") && !kq.has("questionInstance")) {
                questionUrl = kq.get("question").replace("question", "privquestion");
                promises.push($.ajax(questionUrl, {
                    success: function (data, textStatus, jqXHR) {
                        var question = new MOOC.models.Question({
                            id: parseInt(data.id, 10),
                            lastFrame: data.last_frame,
                            solutionVideo: data.solutionID,
                            solutionText: data.solution_text,
                            use_last_frame: data.use_last_frame
                        });
                        kq.set("questionInstance", question);
                    }
                }));
            }

            if (kq.has("peer_review_assignment") && !kq.has("peerReviewAssignmentInstance")) {
                promises.push($.ajax(kq.get("peer_review_assignment").replace("peer_review_assignment", "privpeer_review_assignment"), {
                    success: function (data, textStatus, jqXHR) {
                        var peer_review_assignment = new MOOC.models.PeerReviewAssignment({
                            id: parseInt(data.id, 10),
                            description: data.description,
                            minimum_reviewers: data.minimum_reviewers,
                            knowledgeQuantum: data.kq
                        });
                        kq.set("peerReviewAssignmentInstance", peer_review_assignment);
                    }
                }));
            }

            if (!kq.has("attachmentList")) {
                promises.push($.ajax(MOOC.ajax.host + "attachment/?format=json&kq=" + kq.get("id"), {
                    success: function (data, textStatus, jqXHR) {
                        var attachmentList = new MOOC.models.AttachmentList(
                            _.map(data.objects, function (attachment) {
                                return {
                                    id: parseInt(attachment.id, 10),
                                    url: attachment.attachment
                                };
                            })
                        );
                        kq.set("attachmentList", attachmentList);
                    }
                }));
            }
<commit_msg>Fetching peer review evaluation criterions<commit_after>/*jslint vars: false, browser: true, nomen: true */
/*global MOOC:true, _, jQuery, Backbone */

// Copyright 2012 Rooter Analysis S.L.
// Copyright (c) 2013 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

if (_.isUndefined(window.MOOC)) {
    window.MOOC = {};
}

(function ($, Backbone, _) {
    "use strict";

    var errorHandler = function () {
            MOOC.ajax.showAlert("generic");
            MOOC.ajax.hideLoading();
        },
        loadKQs = function (callback) {
            var promises = [];
            MOOC.models.course.each(function (unit) {
                unit.set("knowledgeQuantumList", new MOOC.models.KnowledgeQuantumList());
                promises.push($.ajax(MOOC.ajax.host + "privkq/?format=json&unit=" + unit.get("id"), {
                    success: function (data, textStatus, jqXHR) {
                        unit.get("knowledgeQuantumList").reset(_.map(data.objects, function (kq) {
                            var data = _.pick(kq, "id", "title", "videoID",
                                "teacher_comments", "supplementary_material",
                                "question", "order", "correct", "completed",
                                "normalized_weight", "peer_review_assignment");
                            data.id = parseInt(data.id, 10);
                            return data;
                        }));
                    }
                }));
            });
            $.when.apply(null, promises).done(callback).fail(errorHandler);
        },
        loadKQDetails = function (kq, callback) {
            var promises = [],
                questionUrl;

            if (kq.has("question") && !kq.has("questionInstance")) {
                questionUrl = kq.get("question").replace("question", "privquestion");
                promises.push($.ajax(questionUrl, {
                    success: function (data, textStatus, jqXHR) {
                        var question = new MOOC.models.Question({
                            id: parseInt(data.id, 10),
                            lastFrame: data.last_frame,
                            solutionVideo: data.solutionID,
                            solutionText: data.solution_text,
                            use_last_frame: data.use_last_frame
                        });
                        kq.set("questionInstance", question);
                    }
                }));
            }

            if (kq.has("peer_review_assignment") && !kq.has("peerReviewAssignmentInstance")) {
                var peer_review_assignment = new MOOC.models.PeerReviewAssignment();
                var criterionList = peer_review_assignment.get("_criterionList");
                var assignmentUrl = kq.get("peer_review_assignment").split("/");

                var assignmentId = parseInt(assignmentUrl.pop());
                while (isNaN(assignmentId))
                    assignmentId = parseInt(assignmentUrl.pop());
                criterionList.assignment = assignmentId;

                promises.push($.ajax(kq.get("peer_review_assignment").replace("peer_review_assignment", "privpeer_review_assignment"), {
                    success: function (data, textStatus, jqXHR) {
                        peer_review_assignment.set("id", parseInt(data.id, 10));
                        peer_review_assignment.set("description", data.description);
                        peer_review_assignment.set("minimum_reviewers", data.minimum_reviewers);
                        peer_review_assignment.set("knowledgeQuantum", data.kq);
                        kq.set("peerReviewAssignmentInstance", peer_review_assignment);
                }}));

                promises.push($.ajax(criterionList.url().replace("peer_review_assignment", "privpeer_review_assignment"), {
                    success: function (data, textStatus, jqXHR) {
                        var elements = _.map(data.objects, function (attachment) {
                            return {
                                assignment: attachment.assignment,
                                id: parseInt(attachment.id, 10),
                                order: parseInt(attachment.order, 10),
                                description: attachment.description
                            };
                        })
                        criterionList.add(elements);
                }}));
            }

            if (!kq.has("attachmentList")) {
                promises.push($.ajax(MOOC.ajax.host + "attachment/?format=json&kq=" + kq.get("id"), {
                    success: function (data, textStatus, jqXHR) {
                        var attachmentList = new MOOC.models.AttachmentList(
                            _.map(data.objects, function (attachment) {
                                return {
                                    id: parseInt(attachment.id, 10),
                                    url: attachment.attachment
                                };
                            })
                        );
                        kq.set("attachmentList", attachmentList);
                    }
                }));
            }

{'fraction_non_alphanumeric': 0.11148151779586234, 'fraction_numerical': 0.0043141484459260715, 'mean_word_length': 1.45074483421432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5619752', 'n_tokens_mistral': 2568, 'n_tokens_neox': 2430, 'n_words': 519}