Пример #1
0
    def get(year, name=None):
        """Get rank for a specified organization

        :param name str Organization name, use all to get rank of all orgs
        :param year int Year of GCI
        :return:
        """

        if name is None:
            tasks = Task.objects(year=year)
        else:
            try:
                org = Organization.objects.get(
                    name=name, year=year
                )
                tasks = Task.objects(org=org)
            except me.DoesNotExist:
                return []

        tasks_students = [x.student for x in tasks]
        rank = []
        for student in set(tasks_students):
            rank.append({
                'student': student,
                'tasks': tasks_students.count(student)
            })

        return sorted(rank, key=itemgetter('tasks'), reverse=True)
Пример #2
0
    def get(self):
        """Get a list of all tasks

        :return list A list of all tasks
        """
        args = self.arg_parser.parse_args()
        org_name = args.get('org')
        student = args.get('student')
        year = args.get('year')
        limit = args.get('limit')
        offset = args.get('offset')

        query = Task.objects(year=year)
        if org_name:
            try:
                org = Organization.objects.get(name=org_name, year=year)
            except me.DoesNotExist:
                return []

            query = query.filter(org=org)

        if student:
            query = query.filter(student=student)

        if limit is not None:
            query = query.limit(limit)

        query = query.skip(offset)

        return queryset_to_dict(query)
Пример #3
0
    def get(year, name=None):
        """Get org stats"""
        args = dict(year=year)
        if name is not None:
            args['org_name'] = name

        categories = Task.count_categories(**args)

        return {
            'categories': categories
        }
Пример #4
0
    def get(name, year, org_name=None):
        """Get org stats"""
        tasks = Task.objects(student=name, year=year)
        if org_name is not None:
            try:
                org = Organization.objects.get(
                    name=org_name, year=year
                )
                tasks = tasks.filter(org=org)
            except me.DoesNotExist:
                return []

        categories = Task.count_categories(year=year, tasks=tasks)

        return {
            'student': name,
            'tasks': [task.to_dict() for task in tasks],
            'stats': {
                'categories': categories
            }
        }
Пример #5
0
    def __fetch_org_tasks_by_year(self, org, year):
        url = self.URLS['TASKS'].format(orgname=org.name, year=year)
        self.logger.info('Getting %d/%s', year, org.name)
        self.logger.debug('Fetching %s', url)

        r = requests.get(url)
        fetched_tasks = json.loads(r.text).get('data').get('')
        self.logger.info('Got %d tasks', len(fetched_tasks))
        for fetched_task in fetched_tasks:
            fetched_task = fetched_task.get('columns')
            task = Task.objects(key=fetched_task.get('key')).first()
            if not task:
                # New task
                Task(
                    key=fetched_task.get('key'),
                    year=year,
                    org=org,
                    student=fetched_task.get('student'),
                    title=fetched_task.get('title'),
                    categories=fetched_task.get('types').split(', ')
                ).save()