Esempio n. 1
0
    def test_notify_player_score_event_msg(self):
        event = events.NotifyPlayerScoreEvent(
            game_id=_TEST_GAME_ID,
            game_options=self.game_options,
            player=_gamedb.player_from_id(
                id="062496c3-b106-48ce-a498-dba2ec271a1c"),
            challenge=database.Challenge(
                name="Most creative way to make a mask.",
                message="Use your imagination to make a mask from items in your home.",
            ),
            entry=database.Entry(),
            points=100
        )

        self.assertEqual(
            _event_messages_as_json(event.messages(gamedb=_gamedb)),
            json.dumps(
                [
                    {
                        "class": "SMSEventMessage",
                        "content": ("\nVIR-US: You scored 100 points with your video! "
                                    "Winning teams for the day will be announced by 6PM EDT.\n"),
                        "recipient_phone_numbers": [
                            "751-005-3935"
                        ]
                    }
                ]
            )
        )
Esempio n. 2
0
    def _score_entries_top_k_teams_fn(self, entries: Iterable,
                                      challenge: Challenge, score_dict: Dict,
                                      gamedb: Database, engine: Engine):
        entries_iter = iter(entries)
        while not self._stop_event.is_set():
            try:
                entry = next(entries_iter)
                log_message(message="Entry {}.".format(entry),
                            game_id=self._game_id)
                points = self._score_entry(entry=entry)
                player = gamedb.player_from_id(entry.player_id)
                engine.add_event(
                    events.NotifyPlayerScoreEvent(game_id=self._game_id,
                                                  game_options=self._options,
                                                  player=player,
                                                  challenge=challenge,
                                                  entry=entry,
                                                  points=points))

                if player.team_id not in score_dict:
                    score_dict[player.team_id] = points
                else:
                    score_dict[player.team_id] += points
            except StopIteration:
                break
Esempio n. 3
0
    def _score_entries_tribe_aggregate_fn(self, entries: Iterable, challenge: Challenge, score_dict: Dict, gamedb: Database, engine: Engine):
        """Note that all built-ins are thread safe in python, meaning we can
        atomically increment the score int held in score_dict."""

        entries_iter = iter(entries)
        while not self._stop.is_set():
            try:
                entry = next(entries_iter)
                pprint.pprint(entry)
                points = entry.likes / entry.views
                player = gamedb.player_from_id(entry.player_id)
                engine.add_event(events.NotifyPlayerScoreEvent(
                    game_id=self._game_id, game_options=self._options,
                    player=player, challenge=challenge,
                    entry=entry, points=points))
                score_dict['score'] += points
            except StopIteration:
                break
Esempio n. 4
0
                   count_players=5,
                   tribe_id='tribe/foo')
_TEST_TRIBE1 = Tribe(id='id/foo1', name='SIDAMA', count_players=1e6)
_TEST_TRIBE2 = Tribe(id='id/foo2', name='TIGRAWAY', count_players=500e3)
_TEST_GAME_OPTIONS = GameOptions(game_schedule=STV_I18N_TABLE['US'])

_gamedb = FirestoreDB(json_config_path=_TEST_FIRESTORE_INSTANCE_JSON_PATH,
                      game_id=_TEST_GAME_ID)

_TEST_EVENTS = [
    events.NotifyTribalChallengeEvent(game_id=_TEST_GAME_ID,
                                      game_options=_TEST_GAME_OPTIONS,
                                      challenge=_TEST_CHALLENGE),
    events.NotifyPlayerScoreEvent(game_id=_TEST_GAME_ID,
                                  game_options=_TEST_GAME_OPTIONS,
                                  player=_TEST_PLAYER1,
                                  challenge=_TEST_CHALLENGE,
                                  entry=_TEST_ENTRY,
                                  points=100),
    events.NotifyTeamReassignmentEvent(game_id=_TEST_GAME_ID,
                                       game_options=_TEST_GAME_OPTIONS,
                                       player=_TEST_PLAYER1,
                                       team=_TEST_TEAM1),
    events.NotifySingleTeamCouncilEvent(
        game_id=_TEST_GAME_ID,
        game_options=_TEST_GAME_OPTIONS,
        winning_player=_TEST_PLAYER1,
        losing_players=[_TEST_PLAYER1, _TEST_PLAYER2]),
    events.NotifySingleTribeCouncilEvent(game_id=_TEST_GAME_ID,
                                         game_options=_TEST_GAME_OPTIONS,
                                         winning_teams=[_TEST_TEAM1],
                                         losing_teams=[_TEST_TEAM2]),