예제 #1
0
    def page(self, course, aggregationid, task):
        """ Get all data and display the page """
        aggregation = self.database.aggregations.find_one(
            {"_id": ObjectId(aggregationid)})

        data = list(
            self.database.submissions.find(
                {
                    "username": {
                        "$in": aggregation["students"]
                    },
                    "courseid": course.get_id(),
                    "taskid": task.get_id()
                }, {
                    "text": False,
                    "response_type": False,
                    "archive": False,
                    "input": False
                }).sort([("submitted_on", pymongo.DESCENDING)]))
        data = [
            dict(
                list(f.items()) +
                [("url", self.submission_url_generator(str(f["_id"])))])
            for f in data
        ]
        if "csv" in web.input():
            return make_csv(data)

        return self.template_helper.get_renderer(
        ).course_admin.aggregation_task(course, aggregation, task, data)
예제 #2
0
    def page(self, course, username, task):
        """ Get all data and display the page """
        data = list(
            self.database.submissions.find({
                "username": username,
                "courseid": course.get_id(),
                "taskid": task.get_id()
            }).sort([("submitted_on", pymongo.DESCENDING)]))
        data = [
            dict(
                list(f.items()) +
                [("url", self.submission_url_generator(str(f["_id"])))])
            for f in data
        ]
        if "csv" in web.input():
            return make_csv(data)

        user_task = self.database.user_tasks.find_one({
            "username":
            username,
            "courseid":
            course.get_id(),
            "taskid":
            task.get_id()
        })
        submissionid = None if not user_task else user_task.get(
            "submissionid", None)

        return self.template_helper.get_renderer().course_admin.student_task(
            course, username, task, data, submissionid)
예제 #3
0
    def page(self, course, msg="", error=False):
        """ Get all data and display the page """
        aggregations = OrderedDict()

        for aggregation in self.user_manager.get_course_aggregations(course):
            aggregations[aggregation['_id']] = dict(
                list(aggregation.items()) +
                [("tried", 0), ("done", 0),
                 ("url", self.submission_url_generator(aggregation['_id']))])

            data = list(
                self.database.submissions.aggregate([
                    {
                        "$match": {
                            "courseid": course.get_id(),
                            "taskid": {
                                "$in": list(course.get_tasks().keys())
                            },
                            "username": {
                                "$in": aggregation["students"]
                            }
                        }
                    },
                    {
                        "$group": {
                            "_id": "$taskid",
                            "tried": {
                                "$sum": 1
                            },
                            "done": {
                                "$sum": {
                                    "$cond": [{
                                        "$eq": ["$result", "success"]
                                    }, 1, 0]
                                }
                            }
                        }
                    },
                ]))

            for c in data:
                aggregations[
                    aggregation['_id']]["tried"] += 1 if c["tried"] else 0
                aggregations[
                    aggregation['_id']]["done"] += 1 if c["done"] else 0

        my_aggregations, other_aggregations = [], []
        for aggregation in aggregations.values():
            if self.user_manager.session_username() in aggregation["tutors"]:
                my_aggregations.append(aggregation)
            else:
                other_aggregations.append(aggregation)

        if "csv" in web.input():
            return make_csv(data)

        return self.template_helper.get_renderer(
        ).course_admin.aggregation_list(course,
                                        [my_aggregations, other_aggregations],
                                        msg, error)
예제 #4
0
 def page(self, course, username, task):
     """ Get all data and display the page """
     data = list(self.database.submissions.find({"username": username, "courseid": course.get_id(), "taskid": task.get_id()}).sort(
         [("submitted_on", pymongo.DESCENDING)]))
     data = [dict(f.items() + [("url", self.submission_url_generator(course, str(f["_id"])))]) for f in data]
     if "csv" in web.input():
         return make_csv(data)
     return self.template_helper.get_renderer().course_admin.student_task(course, username, task, data)
예제 #5
0
    def page(self, course, classroomid, task):
        """ Get all data and display the page """
        classroom = self.database.classrooms.find_one({"_id": ObjectId(classroomid)})

        data = list(
            self.database.submissions.find({"username": {"$in": classroom["students"]}, "courseid": course.get_id(), "taskid": task.get_id()}).sort(
                [("submitted_on", pymongo.DESCENDING)]))
        data = [dict(f.items() + [("url", self.submission_url_generator(course, str(f["_id"])))]) for f in data]
        if "csv" in web.input():
            return make_csv(data)

        return self.template_helper.get_renderer().course_admin.classroom_task(course, classroom, task, data)
예제 #6
0
    def page(self, course, error="", post=False):
        """ Get all data and display the page """
        users = sorted(list(
            self.user_manager.get_users_info(
                self.user_manager.get_course_registered_users(course,
                                                              False)).items()),
                       key=lambda k: k[1][0] if k[1] is not None else "")

        users = OrderedDict(
            sorted(list(
                self.user_manager.get_users_info(course.get_staff()).items()),
                   key=lambda k: k[1][0] if k[1] is not None else "") + users)

        user_data = OrderedDict([(username, {
            "username":
            username,
            "realname":
            user[0] if user is not None else "",
            "email":
            user[1] if user is not None else "",
            "total_tasks":
            0,
            "task_grades": {
                "answer": 0,
                "match": 0
            },
            "task_succeeded":
            0,
            "task_tried":
            0,
            "total_tries":
            0,
            "grade":
            0,
            "url":
            self.submission_url_generator(username)
        }) for username, user in list(users.items())])

        for username, data in list(
                self.user_manager.get_course_caches(list(users.keys()),
                                                    course).items()):
            user_data[username].update(data if data is not None else {})

        if "csv" in web.input():
            return make_csv(user_data)

        return self.template_helper.get_renderer().course_admin.student_list(
            course, list(user_data.values()), error, post)
예제 #7
0
    def page(self, course):
        """ Get all data and display the page """
        data = list(self.database.user_tasks.aggregate(
            [
                {
                    "$match":
                        {
                            "courseid": course.get_id(),
                            "username": {"$in": self.user_manager.get_course_registered_users(course, False)}
                        }
                },
                {
                    "$group":
                        {
                            "_id": "$taskid",
                            "viewed": {"$sum": 1},
                            "attempted": {"$sum": {"$cond": [{"$ne": ["$tried", 0]}, 1, 0]}},
                            "attempts": {"$sum": "$tried"},
                            "succeeded": {"$sum": {"$cond": ["$succeeded", 1, 0]}}
                        }
                }
            ]))

        # Load tasks and verify exceptions
        files = self.task_factory.get_readable_tasks(course)
        output = {}
        errors = []
        for task in files:
            try:
                output[task] = course.get_task(task)
            except Exception as inst:
                errors.append({"taskid": task, "error": str(inst)})
        tasks = OrderedDict(sorted(output.items(), key=lambda t: t[1].get_order()))

        # Now load additionnal informations
        result = OrderedDict()
        for taskid in tasks:
            result[taskid] = {"name": tasks[taskid].get_name(), "viewed": 0, "attempted": 0, "attempts": 0, "succeeded": 0,
                              "url": self.submission_url_generator(course, taskid)}
        for entry in data:
            if entry["_id"] in result:
                result[entry["_id"]]["viewed"] = entry["viewed"]
                result[entry["_id"]]["attempted"] = entry["attempted"]
                result[entry["_id"]]["attempts"] = entry["attempts"]
                result[entry["_id"]]["succeeded"] = entry["succeeded"]
        if "csv" in web.input():
            return make_csv(result)
        return self.template_helper.get_renderer().course_admin.task_list(course, result, errors)
예제 #8
0
    def page(self, course):
        """ Get all data and display the page """
        data = list(self.database.user_tasks.aggregate(
            [
                {
                    "$match":
                        {
                            "courseid": course.get_id(),
                            "username": {"$in": self.user_manager.get_course_registered_users(course, False)}
                        }
                },
                {
                    "$group":
                        {
                            "_id": "$taskid",
                            "viewed": {"$sum": 1},
                            "attempted": {"$sum": {"$cond": [{"$ne": ["$tried", 0]}, 1, 0]}},
                            "attempts": {"$sum": "$tried"},
                            "succeeded": {"$sum": {"$cond": ["$succeeded", 1, 0]}}
                        }
                }
            ]))

        # Load tasks and verify exceptions
        files = self.task_factory.get_readable_tasks(course)
        output = {}
        errors = []
        for task in files:
            try:
                output[task] = course.get_task(task)
            except Exception as inst:
                errors.append({"taskid": task, "error": str(inst)})
        tasks = OrderedDict(sorted(list(output.items()), key=lambda t: t[1].get_order()))

        # Now load additional informations
        result = OrderedDict()
        for taskid in tasks:
            result[taskid] = {"name": tasks[taskid].get_name(), "viewed": 0, "attempted": 0, "attempts": 0, "succeeded": 0,
                              "url": self.submission_url_generator(taskid)}
        for entry in data:
            if entry["_id"] in result:
                result[entry["_id"]]["viewed"] = entry["viewed"]
                result[entry["_id"]]["attempted"] = entry["attempted"]
                result[entry["_id"]]["attempts"] = entry["attempts"]
                result[entry["_id"]]["succeeded"] = entry["succeeded"]
        if "csv" in web.input():
            return make_csv(result)
        return self.template_helper.get_renderer().course_admin.task_list(course, result, errors)
예제 #9
0
    def page(self, course, msg="", error=False):
        """ Get all data and display the page """
        classrooms = OrderedDict()

        for classroom in self.user_manager.get_course_classrooms(course):
            classrooms[classroom['_id']] = dict(classroom.items() +
                                                [("tried", 0),
                                                 ("done", 0),
                                                 ("url", self.submission_url_generator(course, classroom['_id']))
                                                 ])

            data = list(self.database.submissions.aggregate(
                [
                    {
                        "$match":
                            {
                                "courseid": course.get_id(),
                                "taskid": {"$in": course.get_tasks().keys()},
                                "username": {"$in": classroom["students"]}
                            }
                    },
                    {
                        "$group":
                            {
                                "_id": "$taskid",
                                "tried": {"$sum": 1},
                                "done": {"$sum": {"$cond": [{"$eq": ["$result", "success"]}, 1, 0]}}
                            }
                    },

                ]))

            for c in data:
                classrooms[classroom['_id']]["tried"] += 1 if c["tried"] else 0
                classrooms[classroom['_id']]["done"] += 1 if c["done"] else 0

        my_classrooms, other_classrooms = [], []
        for classroom in classrooms.values():
            if self.user_manager.session_username() in classroom["tutors"]:
                my_classrooms.append(classroom)
            else:
                other_classrooms.append(classroom)

        if "csv" in web.input():
            return make_csv(data)

        return self.template_helper.get_renderer().course_admin.classroom_list(course, [my_classrooms, other_classrooms], msg, error)
예제 #10
0
    def page(self, course, classroomid):
        """ Get all data and display the page """
        classroom = self.database.classrooms.find_one({"_id": ObjectId(classroomid)})

        data = list(self.database.submissions.aggregate(
            [
                {
                    "$match":
                        {
                            "courseid": course.get_id(),
                            "username": {"$in": classroom["students"]}
                        }
                },
                {
                    "$group":
                        {
                            "_id": "$taskid",
                            "tried": {"$sum": 1},
                            "succeeded": {"$sum": {"$cond": [{"$eq": ["$result", "success"]}, 1, 0]}},
                            "grade": {"$max": "$grade"}
                        }
                }
            ]))

        tasks = course.get_tasks()
        result = dict([(taskid, {"taskid": taskid, "name": tasks[taskid].get_name(), "tried": 0, "status": "notviewed",
                                 "grade": 0, "url": self.submission_url_generator(course, classroomid, taskid)}) for taskid in tasks])

        for taskdata in data:
            if taskdata["_id"] in result:
                result[taskdata["_id"]]["tried"] = taskdata["tried"]
                if taskdata["tried"] == 0:
                    result[taskdata["_id"]]["status"] = "notattempted"
                elif taskdata["succeeded"]:
                    result[taskdata["_id"]]["status"] = "succeeded"
                else:
                    result[taskdata["_id"]]["status"] = "failed"
                result[taskdata["_id"]]["grade"] = taskdata["grade"]

        if "csv" in web.input():
            return make_csv(result)

        return self.template_helper.get_renderer().course_admin.classroom(course, classroom, result.values())
예제 #11
0
    def page(self, course, error="", post=False):
        """ Get all data and display the page """
        users = sorted(self.user_manager.get_users_info(self.user_manager.get_course_registered_users(course, False)).items(),
                       key=lambda k: k[1][0] if k[1] is not None else "")

        users = OrderedDict(sorted(self.user_manager.get_users_info(course.get_staff()).items(),
                                   key=lambda k: k[1][0] if k[1] is not None else "") + users)

        user_data = OrderedDict([(username, {
            "username": username, "realname": user[0] if user is not None else "",
            "email": user[1] if user is not None else "", "total_tasks": 0,
            "task_grades": {"answer": 0, "match": 0}, "task_succeeded": 0, "task_tried": 0, "total_tries": 0,
            "grade": 0, "url": self.submission_url_generator(course, username)}) for username, user in users.iteritems()])

        for username, data in self.user_manager.get_course_caches(users.keys(), course).iteritems():
            user_data[username].update(data if data is not None else {})

        if "csv" in web.input():
            return make_csv(user_data)

        return self.template_helper.get_renderer().course_admin.student_list(course, user_data.values(), error, post)
예제 #12
0
    def page(self, course, username):
        """ Get all data and display the page """
        data = list(
            self.database.user_tasks.find({
                "username": username,
                "courseid": course.get_id()
            }))

        tasks = course.get_tasks()
        result = dict([(taskid, {
            "taskid": taskid,
            "name": tasks[taskid].get_name(),
            "tried": 0,
            "status": "notviewed",
            "grade": 0,
            "url": self.submission_url_generator(username, taskid)
        }) for taskid in tasks])

        for taskdata in data:
            if taskdata["taskid"] in result:
                result[taskdata["taskid"]]["tried"] = taskdata["tried"]
                if taskdata["tried"] == 0:
                    result[taskdata["taskid"]]["status"] = "notattempted"
                elif taskdata["succeeded"]:
                    result[taskdata["taskid"]]["status"] = "succeeded"
                else:
                    result[taskdata["taskid"]]["status"] = "failed"
                result[taskdata["taskid"]]["grade"] = taskdata["grade"]
                result[taskdata["taskid"]]["submissionid"] = str(
                    taskdata["submissionid"])

        if "csv" in web.input():
            return make_csv(result)

        results = sorted(
            list(result.values()),
            key=lambda result:
            (tasks[result["taskid"]].get_order(), result["taskid"]))
        return self.template_helper.get_renderer().course_admin.student_info(
            course, username, results)
예제 #13
0
    def page(self, course, username):
        """ Get all data and display the page """
        data = list(self.database.user_tasks.find({"username": username, "courseid": course.get_id()}))

        tasks = course.get_tasks()
        result = dict([(taskid, {"taskid": taskid, "name": tasks[taskid].get_name(),
                                 "tried": 0, "status": "notviewed", "grade": 0,
                                 "url": self.submission_url_generator(course, username, taskid)}) for taskid in tasks])

        for taskdata in data:
            if taskdata["taskid"] in result:
                result[taskdata["taskid"]]["tried"] = taskdata["tried"]
                if taskdata["tried"] == 0:
                    result[taskdata["taskid"]]["status"] = "notattempted"
                elif taskdata["succeeded"]:
                    result[taskdata["taskid"]]["status"] = "succeeded"
                else:
                    result[taskdata["taskid"]]["status"] = "failed"
                result[taskdata["taskid"]]["grade"] = taskdata["grade"]

        if "csv" in web.input():
            return make_csv(result)
        return self.template_helper.get_renderer().course_admin.student(course, username, result.values())
예제 #14
0
    def page(self, course, aggregationid):
        """ Get all data and display the page """
        aggregation = self.database.aggregations.find_one(
            {"_id": ObjectId(aggregationid)})

        data = list(
            self.database.submissions.aggregate([{
                "$match": {
                    "courseid": course.get_id(),
                    "username": {
                        "$in": aggregation["students"]
                    }
                }
            }, {
                "$group": {
                    "_id": "$taskid",
                    "tried": {
                        "$sum": 1
                    },
                    "succeeded": {
                        "$sum": {
                            "$cond": [{
                                "$eq": ["$result", "success"]
                            }, 1, 0]
                        }
                    },
                    "grade": {
                        "$max": "$grade"
                    }
                }
            }]))

        tasks = course.get_tasks()
        result = dict([(taskid, {
            "taskid":
            taskid,
            "name":
            tasks[taskid].get_name(),
            "tried":
            0,
            "status":
            "notviewed",
            "grade":
            0,
            "url":
            self.submission_url_generator(aggregationid, taskid)
        }) for taskid in tasks])

        for taskdata in data:
            if taskdata["_id"] in result:
                result[taskdata["_id"]]["tried"] = taskdata["tried"]
                if taskdata["tried"] == 0:
                    result[taskdata["_id"]]["status"] = "notattempted"
                elif taskdata["succeeded"]:
                    result[taskdata["_id"]]["status"] = "succeeded"
                else:
                    result[taskdata["_id"]]["status"] = "failed"
                result[taskdata["_id"]]["grade"] = taskdata["grade"]

        if "csv" in web.input():
            return make_csv(result)

        results = sorted(
            list(result.values()),
            key=lambda result:
            (tasks[result["taskid"]].get_order(), result["taskid"]))
        return self.template_helper.get_renderer(
        ).course_admin.aggregation_info(course, aggregation, results)
예제 #15
0
    def page(self, course, task):
        """ Get all data and display the page """
        user_list = self.user_manager.get_course_registered_users(
            course, False)
        users = OrderedDict(
            sorted(list(self.user_manager.get_users_info(user_list).items()),
                   key=lambda k: k[1][0] if k[1] is not None else ""))

        individual_results = list(
            self.database.user_tasks.find({
                "courseid": course.get_id(),
                "taskid": task.get_id(),
                "username": {
                    "$in": user_list
                }
            }))

        individual_data = OrderedDict([(username, {
            "username":
            username,
            "realname":
            user[0] if user is not None else "",
            "email":
            user[1] if user is not None else "",
            "url":
            self.individual_submission_url_generator(task, username),
            "tried":
            0,
            "grade":
            0,
            "status":
            "notviewed"
        }) for username, user in list(users.items())])

        for user in individual_results:
            individual_data[user["username"]]["tried"] = user["tried"]
            if user["tried"] == 0:
                individual_data[user["username"]]["status"] = "notattempted"
            elif user["succeeded"]:
                individual_data[user["username"]]["status"] = "succeeded"
            else:
                individual_data[user["username"]]["status"] = "failed"
            individual_data[user["username"]]["grade"] = user["grade"]

        aggregation_data = OrderedDict()
        for aggregation in self.user_manager.get_course_aggregations(course):
            aggregation_data[aggregation['_id']] = {
                "_id": aggregation['_id'],
                "description": aggregation['description'],
                "url":
                self.aggregation_submission_url_generator(task, aggregation),
                "tried": 0,
                "grade": 0,
                "status": "notviewed",
                "tutors": aggregation["tutors"],
                "groups": aggregation["groups"]
            }

            aggregation_results = list(
                self.database.submissions.aggregate([{
                    "$match": {
                        "courseid": course.get_id(),
                        "taskid": task.get_id(),
                        "username": {
                            "$in": aggregation["students"]
                        }
                    }
                }, {
                    "$group": {
                        "_id": "$taskid",
                        "tried": {
                            "$sum": 1
                        },
                        "succeeded": {
                            "$sum": {
                                "$cond": [{
                                    "$eq": ["$result", "success"]
                                }, 1, 0]
                            }
                        },
                        "grade": {
                            "$max": "$grade"
                        }
                    }
                }]))

            for g in aggregation_results:
                aggregation_data[aggregation['_id']]["tried"] = g["tried"]
                if g["tried"] == 0:
                    aggregation_data[
                        aggregation['_id']]["status"] = "notattempted"
                elif g["succeeded"]:
                    aggregation_data[
                        aggregation['_id']]["status"] = "succeeded"
                else:
                    aggregation_data[aggregation['_id']]["status"] = "failed"
                aggregation_data[aggregation['_id']]["grade"] = g["grade"]

        my_aggregations, other_aggregations = [], []
        for aggregation in list(aggregation_data.values()):
            if self.user_manager.session_username() in aggregation["tutors"]:
                my_aggregations.append(aggregation)
            else:
                other_aggregations.append(aggregation)

        if "csv" in web.input() and web.input()["csv"] == "students":
            return make_csv(list(individual_data.values()))
        elif "csv" in web.input() and web.input()["csv"] == "aggregations":
            return make_csv(list(aggregation_data.values()))

        return self.template_helper.get_renderer().course_admin.task_info(
            course, task, list(individual_data.values()),
            [my_aggregations, other_aggregations])
예제 #16
0
    def page(self, course, task):
        """ Get all data and display the page """
        user_list = self.user_manager.get_course_registered_users(course, False)
        users = OrderedDict(sorted(self.user_manager.get_users_info(user_list).items(),
                                   key=lambda k: k[1][0] if k[1] is not None else ""))

        individual_results = list(self.database.user_tasks.find({"courseid": course.get_id(), "taskid": task.get_id(),
                                                                 "username": {"$in": user_list}}))

        individual_data = OrderedDict([(username, {"username": username, "realname": user[0] if user is not None else "",
                                                   "email": user[1] if user is not None else "",
                                                   "url": self.individual_submission_url_generator(course, task, username),
                                                   "tried": 0, "grade": 0, "status": "notviewed"})
                                       for username, user in users.iteritems()])

        for user in individual_results:
            individual_data[user["username"]]["tried"] = user["tried"]
            if user["tried"] == 0:
                individual_data[user["username"]]["status"] = "notattempted"
            elif user["succeeded"]:
                individual_data[user["username"]]["status"] = "succeeded"
            else:
                individual_data[user["username"]]["status"] = "failed"
            individual_data[user["username"]]["grade"] = user["grade"]

        classroom_data = OrderedDict()
        for classroom in self.user_manager.get_course_classrooms(course):
            classroom_data[classroom['_id']] = {"_id": classroom['_id'], "description": classroom['description'],
                                                "url": self.classroom_submission_url_generator(course, task, classroom),
                                                "tried": 0, "grade": 0, "status": "notviewed",
                                                "tutors": classroom["tutors"]}

            classroom_results = list(self.database.submissions.aggregate(
                [
                    {
                        "$match":
                            {
                                "courseid": course.get_id(),
                                "taskid": task.get_id(),
                                "username": {"$in": classroom["students"]}
                            }
                    },
                    {
                        "$group":
                            {
                                "_id": "$taskid",
                                "tried": {"$sum": 1},
                                "succeeded": {"$sum": {"$cond": [{"$eq": ["$result", "success"]}, 1, 0]}},
                                "grade": {"$max": "$grade"}
                            }
                    }
                ]))

            for g in classroom_results:
                classroom_data[classroom['_id']]["tried"] = g["tried"]
                if g["tried"] == 0:
                    classroom_data[classroom['_id']]["status"] = "notattempted"
                elif g["succeeded"]:
                    classroom_data[classroom['_id']]["status"] = "succeeded"
                else:
                    classroom_data[classroom['_id']]["status"] = "failed"
                classroom_data[classroom['_id']]["grade"] = g["grade"]

        my_classrooms, other_classrooms = [], []
        for classroom in classroom_data.values():
            if self.user_manager.session_username() in classroom["tutors"]:
                my_classrooms.append(classroom)
            else:
                other_classrooms.append(classroom)

        if "csv" in web.input() and web.input()["csv"] == "students":
            return make_csv(individual_data.values())
        elif "csv" in web.input() and web.input()["csv"] == "classrooms":
            return make_csv(classroom_data.values())

        return self.template_helper.get_renderer().course_admin.task_info(course, task, individual_data.values(), [my_classrooms, other_classrooms])