Exemplo n.º 1
0
    def recalculateGCIRanking(self, request, *args, **kwargs):
        """Recalculates student ranking for the entire program.

    Args in POST dict:
      cursor: Query cursor to figure out where we need to start processing
    """

        key_name = '%s/%s' % (kwargs['sponsor'], kwargs['program'])
        cursor = request.POST.get('cursor')

        program = GCIProgram.get_by_key_name(key_name)
        if not program:
            logging.warning(
                'Enqueued recalculate ranking task for non-existing program: %s',
                key_name)
            return responses.terminateTask()

        # Retrieve the students for the program
        q = GCIProfile.all()
        q.filter('program', program)
        q.filter('is_student', True)

        if cursor:
            q.with_cursor(cursor)

        students = q.fetch(25)

        for student in students:
            # get all the tasks that the student has completed
            task_q = GCITask.all()
            task_q.filter('student', student)
            task_q.filter('status', 'Closed')

            tasks = task_q.fetch(1000)

            # calculate score with all the tasks
            score_logic.calculateScore(student, tasks, program)

            # calculate org score with all the tasks
            db.run_in_transaction(org_score_logic.updateOrgScoresTxn(tasks))

        if students:
            # schedule task to do the rest of the students
            params = {
                'cursor': q.cursor(),
            }
            taskqueue.add(queue_name='gci-update',
                          url=request.path,
                          params=params)

        return responses.terminateTask()
Exemplo n.º 2
0
def calculateScore(profile):
  """Calculates the score for the student associated with a GCIProfile.

  Args:
    profile: A GCIProfile associated with some student.
  """
  # TODO(nathaniel): The string literals in this function should be constants
  # declared somewhere sensible.
  # Get all the tasks that the student has completed.
  query = task_model.GCITask.all()
  query.filter('student', profile)
  query.filter('status', 'Closed')

  tasks = query.fetch(1000)

  # Calculate org score with all the tasks.
  db.run_in_transaction(org_score_logic.updateOrgScoresTxn(tasks))
Exemplo n.º 3
0
    def recalculateGCIRanking(self, request, *args, **kwargs):
        """Recalculates student ranking for the entire program.

    Args in POST dict:
      cursor: Query cursor to figure out where we need to start processing
    """

        key_name = "%s/%s" % (kwargs["sponsor"], kwargs["program"])
        cursor = request.POST.get("cursor")

        program = GCIProgram.get_by_key_name(key_name)
        if not program:
            logging.warning("Enqueued recalculate ranking task for non-existing program: %s", key_name)
            return responses.terminateTask()

        # Retrieve the students for the program
        q = GCIProfile.all()
        q.filter("program", program)
        q.filter("is_student", True)

        if cursor:
            q.with_cursor(cursor)

        students = q.fetch(25)

        for student in students:
            # get all the tasks that the student has completed
            task_q = GCITask.all()
            task_q.filter("student", student)
            task_q.filter("status", "Closed")

            tasks = task_q.fetch(1000)

            # calculate score with all the tasks
            score_logic.calculateScore(student, tasks, program)

            # calculate org score with all the tasks
            db.run_in_transaction(org_score_logic.updateOrgScoresTxn(tasks))

        if students:
            # schedule task to do the rest of the students
            params = {"cursor": q.cursor()}
            taskqueue.add(queue_name="gci-update", url=request.path, params=params)

        return responses.terminateTask()