def handle(self, *args, **options):
        start_date = datetime.strptime(options["start_date"], "%Y-%m-%d")
        self.stdout.write("Evaluating bonus points for solutions after %s" %
                          start_date)

        users = User.objects.filter(is_staff=False)
        gradefunc = points_for_completed_tasks(options["category_name"],
                                               start_date, 10)
        grades = calculate_grades(users, gradefunc)

        if not options["zeroes"]:
            grades = filter_zeroes(grades)

        # we guessed some names and can't sort at the database layer
        grades = list(grades)
        grades.sort()

        with open(options["csv_file"], mode="w", newline="") as csv_file:
            writer = csv.writer(csv_file)
            for row in grades:
                writer.writerow(row)

        self.stdout.write(
            self.style.SUCCESS("Successfully created %s" %
                               options["csv_file"]))
 def test_no_points_for_completed_tasks(self):
     """
     Verify that the maximum bonus point
     amount is taken into account.
     """
     points_for_alice = points_for_completed_tasks(self.category.name,
                                                   datetime(1970, 1, 1),
                                                   0)(self.alice)
     self.assertEqual(points_for_alice, 0)
 def test_points_for_completed_tasks(self):
     """
     Verify that bonus points are awarded to
     legitimate solutions.
     """
     points_for_alice = points_for_completed_tasks(self.category.name,
                                                   datetime(1970, 1, 1),
                                                   10)(self.alice)
     self.assertEqual(points_for_alice, 1)
    def handle(self, *args, **options):
        start_date = datetime.strptime(options["start_date"], "%Y-%m-%d")
        self.stdout.write("Evaluating bonus points for solutions after %s" % start_date)

        users = User.objects.filter(is_staff=False)
        gradefunc = points_for_completed_tasks(options["category_name"], start_date, 10)
        grades = calculate_grades(users, gradefunc)

        if not options["zeroes"]:
            grades = filter_zeroes(grades)

        # we guessed some names and can't sort at the database layer
        grades = list(grades)
        grades.sort()

        with open(options["csv_file"], mode="w", newline="") as csv_file:
            writer = csv.writer(csv_file)
            for row in grades:
                writer.writerow(row)

        self.stdout.write(self.style.SUCCESS("Successfully created %s" % options["csv_file"]))