예제 #1
0
 def __init__(self, seed=None, num_robots=None, quads=None):
     wx.Frame.__init__(self, None, -1, 'Ricochet Robot!')
     print( seed, num_robots)
     match = model.Match(seed, quads=quads, num_robots=num_robots)
     #game = model.Game.hardest()
     self.view = View(self, match)
     self.view.SetSize((800, 800))
     self.Fit()
예제 #2
0
    def add_match_by_tournament_id(self, tournament_id, winner_id, loser_id):
        match_updates = False
        tourney_m = \
            M.Tournament.load(self.tournaments_col.find_one({'_id':tournament_id}), context='db')

        new_match_id = len(tourney_m.matches)
        new_match = M.Match(match_id=new_match_id, winner=winner_id, loser=loser_id, excluded=False)

        tourney_m.matches.append(new_match)

        if winner_id not in tourney_m.players:
            tourney_m.players.append(winner_id)
        if loser_id not in tourney_m.players:
            tourney_m.players.append(loser_id)

        self.tournaments_col.update({'_id': tournament_id}, tourney_m.dump(context='db'))
예제 #3
0
    def put(self, region, id):
        dao = get_dao(region)
        auth_user(request, dao)

        parser = reqparse.RequestParser() \
            .add_argument('name', type=str) \
            .add_argument('date', type=str) \
            .add_argument('players', type=list) \
            .add_argument('matches', type=list) \
            .add_argument('regions', type=list) \
            .add_argument('pending', type=bool)

        args = parser.parse_args()

        tournament = None
        try:
            if args['pending']:
                tournament = dao.get_pending_tournament_by_id(ObjectId(id))
            else:
                tournament = dao.get_tournament_by_id(ObjectId(id))
        except Exception as e: 
            log_exception()
            err('Invalid ObjectID')
        if not tournament:
            err("No tournament found with that id.")

        try:
            if args['name']:
                tournament.name = args['name']
            if args['date']:
                try:
                    tournament.date = datetime.strptime(
                        args['date'].strip(), '%m/%d/%y')
                except Exception as e: 
                    log_exception()
                    err("Invalid date format")
            if args['players']:
                # this should rarely be used (if it is used, players will not
                # unmerge reliably)
                for p in args['players']:
                    if not isinstance(p, unicode):
                        err("each player must be a string")
                tournament.players = [ObjectId(i) for i in args['players']]
                tournament.orig_ids = [pid for pid in tournament.players]
            if args['matches']:
                for d in args['matches']:
                    if not isinstance(d, dict):
                        err("matches must be a dict")
                    if (not isinstance(d['winner'], unicode)) or (
                            not isinstance(d['loser'], unicode)):
                        err("winner and loser must be strings")
                # turn the list of dicts into list of matchresults
                matches = [M.Match(winner=ObjectId(m['winner']), loser=ObjectId(
                    m['loser'])) for m in args['matches']]
                tournament.matches = matches
            if args['regions']:
                for p in args['regions']:
                    if not isinstance(p, unicode):
                        err("each region must be a string")
                tournament.regions = args['regions']
        except Exception as e: 
            log_exception()
            err('Invalid ObjectID')

        try:
            if args['pending']:
                dao.update_pending_tournament(tournament)
            else:
                print tournament
                dao.update_tournament(tournament)
        except Exception as e: 
            log_exception()
            err('Update Tournament Error')

        if args['pending']:
            return dao.get_pending_tournament_by_id(
                tournament.id).dump(context='web')
        else:
            return convert_tournament_to_response(
                dao.get_tournament_by_id(tournament.id), dao)
예제 #4
0
def track_live_series():
    # Series that are currently being tracked by the bot
    tracked_series = list(
        map(lambda live_match_tracked: model.LiveMatch(**live_match_tracked),
            data_access.get_tracked_series()))
    try:
        for league_id in data_access.get_league_ids():
            league = model.League(**make_request.get_league_data(
                league_id))  # Get current league as py object
            live_matches = make_request.get_live_league_matches(
                league_id)  # Get all live matches for that league JSON
            # Serialise the JSON data into py object
            live_matches = list(
                map(lambda live_match_live: model.LiveMatch(**live_match_live),
                    live_matches))

            for live_match in tracked_series:  # Foreach live match
                # If it's the potential final game...
                if util.is_potential_final_game(live_match.node_type,
                                                live_match.radiant_series_wins,
                                                live_match.dire_series_wins):
                    if util.match_has_disappeared(
                            live_matches, live_match
                    ):  # check if the match has disappeared from live series
                        winner = util.is_series_winner(
                            live_match
                        )  # Get the winner of the series by parsing the match
                        if winner is not False:  # If there actually is a winner, then the series is over
                            # Get match in series
                            node = util.get_league_node(
                                league, live_match.league_node_id)[0]
                            matches = []
                            for match in node.matches:
                                matches.append(match['match_id'])
                            # Add the last match to the un updated list of matches
                            matches.append(live_match.match_id)
                            matches = list(dict.fromkeys(matches))
                            # Get the match data by querying the API.
                            matches = list(
                                map(
                                    lambda x: model.Match(
                                        **make_request.get_match_details(x)),
                                    matches))
                            series = model.Series(matches, node, league,
                                                  winner)
                            data_access.stop_tracking_series(
                                live_match.league_node_id)
                            return {
                                'title': series.title,
                                'markdown': series.markdown
                            }

            for match in live_matches:
                if match.match_id not in [x.match_id for x in tracked_series]:
                    if match.league_node_id != 0:
                        node = util.get_league_node(league,
                                                    match.league_node_id)[0]
                        match.node_type = util.resolve_node_type(
                            node.node_type)
                        match.series_id = node.series_id
                        data_access.track_match_node(**match.__dict__)
    except util.APIDownException:
        print('API IS DOWN')
        pass