Ejemplo n.º 1
0
 def GET_AUTH(self, courseid, contestid):  # pylint: disable=arguments-differ
     """ GET request: simply display the form """
     course, _ = self.get_course_and_check_rights(courseid)
     contests_data = self.contest_manager.get_all_contest_data(course)
     course, start, end, blackout, tasks, results, activity, contestid, contest_name = self.contest_manager.get_data(
         courseid, contestid, False)
     for username, data in results.items():
         for d, value in data['tasks'].items():
             if value.get('time', '') != '':
                 value['time'] = value.get('time',
                                           '').strftime("%Y-%m-%d %H:%M:%S")
             else:
                 value['time'] = ''
     if "csv" in web.input():
         return make_csv(results)
     #return self.template_helper.get_custom_renderer('frontend/webapp_contest/plugins/contests').admin(course, contest_data, None, False)
     self.template_helper.add_javascript(
         web.ctx.homepath + '/static/webapp/js/Blob.min.js', "header")
     self.template_helper.add_javascript(
         web.ctx.homepath + '/static/webapp/js/xlsx.core.min.js', "header")
     self.template_helper.add_javascript(
         web.ctx.homepath + '/static/webapp/js/FileSaver.min.js', "header")
     self.template_helper.add_javascript(
         web.ctx.homepath + '/static/webapp/js/tableexport.min.js',
         "header")
     self.template_helper.add_css(web.ctx.homepath +
                                  '/static/webapp/css/tableexport.min.css')
     return self.template_helper.get_renderer().course_admin.contest_report(
         course, tasks, results, None, AccessibleTime)
Ejemplo n.º 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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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(), t[1].get_id())))

        # 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, tasks, errors)
Ejemplo n.º 5
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 users.items()])

        for username, data in 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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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 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 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, individual_data.values(), [my_aggregations, other_aggregations])
Ejemplo n.º 8
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)