예제 #1
0
 def __update_predictions_correctness(match: Match) -> None:
     for prediction in match.prediction_set.all():
         prediction.is_correct = Prediction.calculate_whether_correct(
             match, prediction.predicted_winner
         )
         prediction.clean()
         prediction.save()
def main():
    for prediction in Prediction.objects.select_related(
        "match", "predicted_winner"
    ).all():
        prediction.is_correct = Prediction.calculate_whether_correct(
            prediction.match, prediction.predicted_winner
        )
        prediction.save()
예제 #3
0
    def test_calculate_whether_correct(self):
        with self.subTest("when higher-scoring team is predicted winner"):
            prediction = Prediction(
                match=self.match,
                ml_model=self.ml_model,
                predicted_winner=self.home_team,
                predicted_margin=50,
            )
            self.assertTrue(
                Prediction.calculate_whether_correct(
                    self.match, prediction.predicted_winner
                )
            )

        with self.subTest("when lower-scoring team is predicted winner"):
            prediction = Prediction(
                match=self.match,
                ml_model=self.ml_model,
                predicted_winner=self.away_team,
                predicted_margin=50,
            )
            self.assertFalse(
                Prediction.calculate_whether_correct(
                    self.match, prediction.predicted_winner
                )
            )

        with self.subTest("when match is a draw"):
            self.match.teammatch_set.update(score=100)
            prediction = Prediction(
                match=self.match,
                ml_model=self.ml_model,
                predicted_winner=self.away_team,
                predicted_margin=50,
            )

            self.assertTrue(
                Prediction.calculate_whether_correct(
                    self.match, prediction.predicted_winner
                )
            )