Esempio n. 1
0
    def test_get_or_create_latest(self):
        # First game
        r0, status = Round.get_or_create_latest(num=0)
        assert_equals(status, Round.FIRST_GAME)
        assert_equals(r0.num, 0)
        assert_equals(r0, Round.current_round())

        # New round
        r1, status = Round.get_or_create_latest(num=1)
        assert_equals(status, Round.NEW_ROUND)
        assert_equals(r1.num, 1)
        assert_equals(r1, Round.current_round())
        assert_equals(r0, Round.prev_round())

        # Same round
        r1b, status = Round.get_or_create_latest(num=1)
        assert_equals(status, Round.SAME_ROUND)
        assert_equals(r1b.num, 1)
        assert_equals(r1b, Round.current_round())
        assert_equals(r0, Round.prev_round())
        assert_equals(r1, r1b)

        # New game
        r0b, status = Round.get_or_create_latest(num=0)
        assert_equals(status, Round.NEW_GAME)
        assert_equals(r0b.num, 0)
        assert_equals(r0b, Round.current_round())
        assert_is_none(Round.prev_round())
Esempio n. 2
0
    def _submit_ids_rule(self, cable):
        if cable.cbns and (cable.cbns[0].ids_rule is not None):
            ids_rule = cable.cbns[0].ids_rule
            result = self._cgc.uploadIDS(str(cable.cs.name),
                                         str(ids_rule.rules))

            submission_round, status = Round.get_or_create_latest(
                num=result['round'])

            if status == Round.FIRST_GAME:
                LOG.error(
                    "Submission in first round of first game (round #%d)",
                    submission_round.num)
            elif status == Round.NEW_GAME:
                LOG.info("Submission in first round of new game (round #%d)",
                         submission_round.num)
            elif status == Round.NEW_ROUND:
                LOG.info("Submission beginning of new round #%d",
                         submission_round.num)

            irf, _ = IDSRuleFielding.get_or_create(
                ids_rule=ids_rule,
                submission_round=submission_round,
                team=Team.get_our())
            return irf
Esempio n. 3
0
    def run(self):
        """
        Update game status, including round number and the current scores.

        If we notice that the round number has jumped backward, explicitly create a new round.
        """
        LOG.debug("Getting status")
        status = self._cgc.getStatus()
        self._round, round_status = Round.get_or_create_latest(
            num=status['round'])

        if round_status == Round.FIRST_GAME:
            LOG.info("First game starts")
        elif round_status == Round.NEW_GAME:
            LOG.info("New game started")
        elif round_status == Round.NEW_ROUND:
            LOG.info("New round started")
        elif round_status == Round.SAME_ROUND:
            LOG.debug("Continuing current round")

        Score.update_or_create(self._round, scores=status['scores'])
Esempio n. 4
0
    def _submit_patches(self, cable):
        patches = [
            (str(cbn.root.name) if cbn.root is not None else str(cbn.name),
             str(cbn.blob)) for cbn in cable.cbns
        ]
        result = self._cgc.uploadRCB(str(cable.cs.name), *patches)
        LOG.debug("Submitted RB! Response: %s", result)

        submission_round, status = Round.get_or_create_latest(
            num=result['round'])

        if status == Round.FIRST_GAME:
            LOG.error("Submission in first round of first game (round #%d)",
                      submission_round.num)
        elif status == Round.NEW_GAME:
            LOG.info("Submission in first round of new game (round #%d)",
                     submission_round.num)
        elif status == Round.NEW_ROUND:
            LOG.info("Submission beginning of new round #%d",
                     submission_round.num)

        return ChallengeSetFielding.create_or_update_submission(
            cbns=cable.cbns, team=Team.get_our(), round=submission_round)
Esempio n. 5
0
    def run(self):
        """Amazing docstring"""
        fielded_cses = ChallengeSet.fielded_in_round()
        most_recent = ExploitSubmissionCable.most_recent()
        for cable in most_recent.where(
                ExploitSubmissionCable.cs << fielded_cses):
            pov = cable.exploit
            LOG.info("Submitting POV %d for challenge %s", pov.id, pov.cs.name)
            try:
                result = self._cgc.uploadPOV(str(pov.cs.name),
                                             str(cable.team.name),
                                             str(cable.throws), str(pov.blob))
                LOG.debug("Submitted POV! Response: %s", result)

                submission_round, status = Round.get_or_create_latest(
                    num=result['round'])

                if status == Round.FIRST_GAME:
                    LOG.error(
                        "Submission in first round of first game (round #%d)",
                        submission_round.num)
                elif status == Round.NEW_GAME:
                    LOG.info(
                        "Submission in first round of new game (round #%d)",
                        submission_round.num)
                elif status == Round.NEW_ROUND:
                    LOG.info("Submission beginning of new round #%d",
                             submission_round.num)

                pov.submit_to(team=cable.team,
                              throws=cable.throws,
                              round=submission_round)

            except TiError as err:
                LOG.error("POV Submission error: %s", err.message)

            cable.process()