def make_player(player): if player is None: pl = Player('BYE', 'T', -10000, 0, 0, 0) pl.dbpl = None return pl try: rating = player.current_rating pl = Player( player.tag, player.race, rating.rating, rating.rating_vp, rating.rating_vt, rating.rating_vz, rating.dev, rating.dev_vp, rating.dev_vt, rating.dev_vz, ) except: pl = Player( player.tag, player.race, start_rating(player.country, etn(lambda: get_latest_period().id) or 1), 0.0, 0.0, 0.0, INIT_DEV, INIT_DEV, INIT_DEV, INIT_DEV, ) pl.dbpl = player return pl
def display_matches( matches, date=True, fix_left=None, ratings=False, messages=True, eventcount=False, add_links=False, no_events=False ): if isinstance(matches, QuerySet) and not no_events: matches = matches.prefetch_related("eventobj__uplink", "eventobj__uplink__parent") ret = [] for idx, m in enumerate(matches): # {{{ Basic stuff r = { "match": m, "match_id": m.id, "game": m.game if isinstance(m, Match) else m.group.game, "offline": m.offline if isinstance(m, Match) else m.group.offline, "treated": isinstance(m, Match) and m.treated, "pla": { "id": m.pla_id, "tag": m.pla.tag if m.pla is not None else m.pla_string, "race": m.rca or (m.pla.race if m.pla else None), "country": m.pla.country if m.pla else None, "score": m.sca, }, "plb": { "id": m.plb_id, "tag": m.plb.tag if m.plb is not None else m.plb_string, "race": m.rcb or (m.plb.race if m.plb else None), "country": m.plb.country if m.plb else None, "score": m.scb, }, } if eventcount and isinstance(m, Match): r["eventcount"] = m.eventobj__match__count if isinstance(m, Match): r["eventtext"] = m.eventobj.fullname if m.eventobj is not None else m.event # If event is not closed and add_links=True, show add link r["add_links"] = add_links and m.eventobj is not None and not m.eventobj.closed # }}} # {{{ Add dates and messages if needed if date and isinstance(m, Match): r["date"] = m.date if messages: r["messages"] = [aligulac.tools.Message(msg=msg, type=msg.type + "-small") for msg in m.message_set.all()] # }}} # {{{ Check ratings if needed if ratings and isinstance(m, Match): r["pla"].update( { "rating": m.rta.get_totalrating(m.rcb) if m.rta else start_rating(r["pla"]["country"], m.period_id), "dev": m.rta.get_totaldev(m.rcb) if m.rta else sqrt(2) * INIT_DEV, } ) r["plb"].update( { "rating": m.rtb.get_totalrating(m.rca) if m.rtb else start_rating(r["plb"]["country"], m.period_id), "dev": m.rtb.get_totaldev(m.rca) if m.rtb else sqrt(2) * INIT_DEV, } ) # }}} # {{{ Switch roles of pla and plb if needed if fix_left is not None and fix_left.id == r["plb"]["id"]: r["pla"], r["plb"] = r["plb"], r["pla"] # }}} ret.append(r) return ret
'rating': r, 'prev_ratings': { 'M': r.rating, 'P': r.rating_vp, 'T': r.rating_vt, 'Z': r.rating_vz }, 'prev_devs': { 'M': r.dev, 'P': r.dev_vp, 'T': r.dev_vt, 'Z': r.dev_vz }, 'opp_c': [], 'opp_r': [], 'opp_d': [], 'wins': [], 'losses': [], } new_players = ( Player.objects.filter(Q(match_pla__period=period) | Q(match_plb__period=period)) .exclude(id__in=players.keys()) ) for p in new_players: players[p.id] = { 'player': p, 'rating': None, 'prev_ratings': { 'M': start_rating(p.country, period.id), 'P': 0.0, 'T': 0.0, 'Z': 0.0 }, 'prev_devs': { 'M': INIT_DEV, 'P': INIT_DEV, 'T': INIT_DEV, 'Z': INIT_DEV }, 'opp_c': [], 'opp_r': [], 'opp_d': [], 'wins': [], 'losses': [], } # }}} # {{{ Decay all ratings for p in players.values(): for r in p['prev_devs']: p['prev_devs'][r] = min(sqrt(p['prev_devs'][r]**2 + DECAY_DEV**2), INIT_DEV) # }}} # {{{ Collect match information ngames = 0 for m in Match.objects.filter(period=period).select_related('pla','plb'):
"opp_c": [], "opp_r": [], "opp_d": [], "wins": [], "losses": [], } new_players = Player.objects.filter(Q(match_pla__period=period) | Q(match_plb__period=period)).exclude( id__in=players.keys() ) for p in new_players: players[p.id] = { "player": p, "rating": None, "prev_ratings": {"M": start_rating(p.country, period.id), "P": 0.0, "T": 0.0, "Z": 0.0}, "prev_devs": {"M": INIT_DEV, "P": INIT_DEV, "T": INIT_DEV, "Z": INIT_DEV}, "opp_c": [], "opp_r": [], "opp_d": [], "wins": [], "losses": [], } # }}} # {{{ Decay all ratings for p in players.values(): for r in p["prev_devs"]: p["prev_devs"][r] = min(sqrt(p["prev_devs"][r] ** 2 + DECAY_DEV ** 2), INIT_DEV) # }}}
def display_matches(matches, date=True, fix_left=None, ratings=False, messages=True, eventcount=False, add_links=False, no_events=False): if isinstance(matches, QuerySet) and not no_events: matches = matches.prefetch_related('eventobj__uplink', 'eventobj__uplink__parent') ret = [] for idx, m in enumerate(matches): # {{{ Basic stuff r = { 'match': m, 'match_id': m.id, 'game': m.game if isinstance(m, Match) else m.group.game, 'offline': m.offline if isinstance(m, Match) else m.group.offline, 'treated': isinstance(m, Match) and m.treated, 'pla': { 'id': m.pla_id, 'tag': m.pla.tag if m.pla is not None else m.pla_string, 'race': m.rca or (m.pla.race if m.pla else None), 'country': m.pla.country if m.pla else None, 'score': m.sca, }, 'plb': { 'id': m.plb_id, 'tag': m.plb.tag if m.plb is not None else m.plb_string, 'race': m.rcb or (m.plb.race if m.plb else None), 'country': m.plb.country if m.plb else None, 'score': m.scb, }, } if eventcount and isinstance(m, Match): r['eventcount'] = m.eventobj__match__count if isinstance(m, Match): r['eventtext'] = m.eventobj.fullname if m.eventobj is not None else m.event # If event is not closed and add_links=True, show add link r['add_links'] = add_links and m.eventobj is not None and not m.eventobj.closed # }}} # {{{ Add dates and messages if needed if date and isinstance(m, Match): r['date'] = m.date if messages: r['messages'] = [ aligulac.tools.Message(msg=msg, type=msg.type + '-small') for msg in m.message_set.all() ] # }}} # {{{ Check ratings if needed if ratings and isinstance(m, Match): r['pla'].update({ 'rating': m.rta.get_totalrating(m.rcb) if m.rta else start_rating(r['pla']['country'], m.period_id), 'dev': m.rta.get_totaldev(m.rcb) if m.rta else sqrt(2)*INIT_DEV, }) r['plb'].update({ 'rating': m.rtb.get_totalrating(m.rca) if m.rtb else start_rating(r['plb']['country'], m.period_id), 'dev': m.rtb.get_totaldev(m.rca) if m.rtb else sqrt(2)*INIT_DEV, }) # }}} # {{{ Switch roles of pla and plb if needed if fix_left is not None and fix_left.id == r['plb']['id']: r['pla'], r['plb'] = r['plb'], r['pla'] # }}} ret.append(r) return ret
'opp_r': [], 'opp_d': [], 'wins': [], 'losses': [], } new_players = (Player.objects.filter( Q(match_pla__period=period) | Q(match_plb__period=period)).exclude(id__in=players.keys())) for p in new_players: players[p.id] = { 'player': p, 'rating': None, 'prev_ratings': { 'M': start_rating(p.country, period.id), 'P': 0.0, 'T': 0.0, 'Z': 0.0 }, 'prev_devs': { 'M': INIT_DEV, 'P': INIT_DEV, 'T': INIT_DEV, 'Z': INIT_DEV }, 'opp_c': [], 'opp_r': [], 'opp_d': [], 'wins': [], 'losses': [],
def display_matches(matches, date=True, fix_left=None, ratings=False, messages=True, eventcount=False): ret = [] for idx, m in enumerate(matches): # {{{ Basic stuff r = { 'match': m, 'match_id': m.id, 'game': m.game if isinstance(m, Match) else m.group.game, 'offline': m.offline if isinstance(m, Match) else m.group.offline, 'treated': isinstance(m, Match) and m.treated, 'pla_id': m.pla_id, 'plb_id': m.plb_id, 'pla_tag': m.pla.tag if m.pla is not None else m.pla_string, 'plb_tag': m.plb.tag if m.plb is not None else m.plb_string, 'pla_race': m.rca, 'plb_race': m.rcb, 'pla_country': m.pla.country if m.pla else None, 'plb_country': m.plb.country if m.plb else None, 'pla_score': m.sca, 'plb_score': m.scb, } if eventcount: r['eventcount'] = m.eventobj__match__count if isinstance(m, Match): r['eventtext'] = m.eventobj.fullname if m.eventobj is not None else m.event # }}} # {{{ Add dates and messages if needed if date and isinstance(m, Match): r['date'] = m.date if messages: r['messages'] = [ aligulac.tools.Message(msg.text, msg.title, msg.type + '-small') for msg in m.message_set.all() ] # }}} # {{{ Check ratings if needed if ratings and isinstance(m, Match): r.update({ 'pla_rating': m.rta.get_totalrating(m.rcb) if m.rta else start_rating(r['pla_country'], m.period_id), 'plb_rating': m.rtb.get_totalrating(m.rca) if m.rtb else start_rating(r['plb_country'], m.period_id), 'pla_dev': m.rta.get_totaldev(m.rcb) if m.rta else sqrt(2)*INIT_DEV, 'plb_dev': m.rtb.get_totaldev(m.rca) if m.rtb else sqrt(2)*INIT_DEV, }) # }}} # {{{ Switch roles of pla and plb if needed if fix_left is not None and fix_left.id == r['plb_id']: for k in r.keys(): if k[0:3] == 'pla': l = 'plb' + k[3:] r[k], r[l] = r[l], r[k] # }}} ret.append(r) return ret