def _PossiblyAddTweetToGame(self, twt, existing_games, added_games, user_map, division, age_bracket, league): """Determine if a tweet is a game tweet and add it to a game if so. Args: twt: tweets.Tweet object to be processed. existing_games: list of game_model.Game objects that are currently in the db. added_games: list of game_model.Game objects that have been added as part of this crawl request. user_map: map of string user ids to users which have authored a tweet during this crawl cycle and thus may not be propagated in the db yet. division: Division to set new Game to, if creating one age_bracket: AgeBracket to set new Game to, if creating one league: League to set new Game to, if creating one """ if not twt: return if not twt.two_or_more_integers: return score_indicies = self._FindScoreIndicies(twt.entities.integers, twt.text) if not score_indicies: logging.debug('Ignoring tweet - numbers aren\'t scores: %s', twt.text) return teams = self._FindTeamsInTweet(twt, user_map) logging.debug('teams: %s', teams) scores = [ twt.entities.integers[score_indicies[0]].num, twt.entities.integers[score_indicies[1]].num ] logging.debug('scores: %s', scores) (consistency_score, game) = self._FindMostConsistentGame( twt, existing_games + added_games, teams, division, age_bracket, league, scores) logging.debug('consistency score %s for twt %s', consistency_score, twt.text) # TODO: detect tweets that are summaries for the day (eg, "We went # 3-0 today") # Some examples: # - "X and Y both finish 3-1 on the day. Final pool play game at 9am. @FCStourney" # - "Y is 3-0 playing Turbine at 3. X is 2-0 winning their third game. @FCStourney" # - "3-0 today with wins over Ozone, Grit, and Rut-ro. Quarters against Rogue tomorrow morning!" # Tricky cases: # - "A really great finals game with @PhxUltimate leaves us coming up a little short, 10-11. Great weekend everyone! #southeastreppin" # Try to find a game that matches this tweet in existing games. If no such # game exists, create one. if consistency_score < GAME_CONSISTENCY_THRESHOLD: added_games.append( Game.FromTweet(twt, teams, scores, division, age_bracket, league)) else: for source in game.sources: if twt.id_64 == source.tweet_id: logging.debug( 'Tried to add tweet more than once as game source %s', twt) return game.sources.append(GameSource.FromTweet(twt, scores)) game.sources.sort( cmp=lambda x, y: cmp(y.update_date_time, x.update_date_time)) self._MergeTeamsIntoGame(game, teams)