def pred_4pswiss(request): base = base_ctx('Predict', 'Predict', request=request) dbpl = [get_object_or_404(Player, id=int(i)) for i in request.GET['ps'].split(',')] sipl = [make_player(pl) for pl in dbpl] num = (int(request.GET['bo'])+1)/2 obj = mslgroup.MSLGroup(num) obj.set_players(sipl) def update(request, obj, match, r1, r2): if r1 in request.GET and r2 in request.GET: try: if obj.get_match(match).can_modify(): obj.get_match(match).modify(int(request.GET[r1]), int(request.GET[r2])) except: pass update(request, obj, 'first', '11', '12') update(request, obj, 'second', '21', '22') update(request, obj, 'winners', '31', '32') update(request, obj, 'losers', '41', '42') update(request, obj, 'final', '51', '52') obj.compute() tally = obj.get_tally() players = list(sipl) for p in players: p.tally = tally[p] for i in range(0, 4): players.sort(key=lambda p: p.tally[i], reverse=True) base['players'] = players MatchObj = namedtuple('MatchObj', 'obj pla plb modded canmod fixed sca scb') matches = [] for mname in ['first', 'second', 'winners', 'losers', 'final']: match = obj.get_match(mname) matches.append(MatchObj(match, match.get_player(0).dbpl, match.get_player(1).dbpl,\ match.is_modified(), match.can_modify(), match.is_fixed(), match._result[0], match._result[1])) base['matches'] = matches MeanRes = namedtuple('MeanRes', 'pla plb sca scb') meanres = [] for mname in ['first', 'second', 'winners', 'losers', 'final']: match = obj.get_match(mname) match.compute() lsup = match.find_lsup() meanres.append(MeanRes(match.get_player(0).dbpl, match.get_player(1).dbpl, lsup[1], lsup[2])) match.broadcast_instance((0, [lsup[4], lsup[3]], match)) base['meanres'] = meanres base['ps'] = request.GET['ps'] base['bo'] = request.GET['bo'] fpswiss_postable(base, obj, players, url='http://aligulac.com/predict/4pswiss/?bo=%s&ps=%s' % (base['bo'], base['ps'])) return render_to_response('pred_4pswiss.html', base)
def pred_proleague(request): base = base_ctx('Predict', 'Predict', request=request) dbpl = [get_object_or_404(Player, id=int(i)) for i in request.GET['ps'].split(',')] sipl = [make_player(pl) for pl in dbpl] num = (int(request.GET['bo'])+1)/2 nplayers = len(sipl) obj = teampl.TeamPL(num) obj.set_players(sipl) def update(request, obj, match, r1, r2): if r1 in request.GET and r2 in request.GET: try: if obj.get_match(match).can_modify(): obj.get_match(match).modify(int(request.GET[r1]), int(request.GET[r2])) except: pass else: obj.get_match(match).modify(0, 0) for i in range(0, obj._nplayers): update(request, obj, i, 'm%i-1' % i, 'm%i-2' % i) obj.compute() ResObj = namedtuple('ResObj', 'scl scw proba probb') base['results'] = [] base['prob_draw'] = 0.0 for score in range(0,obj._nplayers+1): if 2*score < obj._nplayers: base['results'].append(ResObj(score, obj._nplayers-score, obj.get_tally()[1][score], obj.get_tally()[0][score])) elif 2*score == obj._nplayers: base['prob_draw'] = obj.get_tally()[0][score] if 2*score >= obj._nplayers: break base['t1'] = sum([r.proba for r in base['results']]) base['t2'] = sum([r.probb for r in base['results']]) MatchObj = namedtuple('MatchObj', 'obj pla plb modded canmod fixed sca scb') matches = [] base['s1'], base['s2'] = 0, 0 for i in range(0, obj._nplayers): match = obj.get_match(i) matches.append(MatchObj(match, match.get_player(0).dbpl, match.get_player(1).dbpl,\ match.is_modified(), match.can_modify(), match.is_fixed(),\ match._result[0], match._result[1])) if match.is_fixed(): base['s1'] += 1 if match._result[0] > match._result[1] else 0 base['s2'] += 1 if match._result[1] > match._result[0] else 0 base['matches'] = matches base['ps'] = request.GET['ps'] base['bo'] = request.GET['bo'] proleague_postable(base, obj, base['results'], base['prob_draw'], url='http://aligulac.com/predict/proleague/?bo=%s&ps=%s' % (base['bo'], base['ps'])) return render_to_response('pred_proleague.html', base)
def pred_rrgroup(request): base = base_ctx('Predict', request=request) dbpl = [get_object_or_404(Player, id=int(i)) for i in request.GET['ps'].split(',')] sipl = [make_player(pl) for pl in dbpl] num = (int(request.GET['bo'])+1)/2 nplayers = len(sipl) obj = rrgroup.RRGroup(len(sipl), num, ['mscore', 'sscore', 'imscore', 'isscore', 'ireplay'], 1) obj.set_players(sipl) MeanRes = namedtuple('MeanRes', 'pla plb sca scb') meanres = [] for i in range(0, (nplayers-1)*nplayers/2): match = obj.get_match(i) match.compute() lsup = match.find_lsup() meanres.append(MeanRes(match.get_player(0).dbpl, match.get_player(1).dbpl, lsup[1], lsup[2])) match.modify(lsup[1], lsup[2]) base['meanres'] = meanres obj.compute() mtally = obj.get_tally() for p in sipl: p.mtally = mtally[p] base['mplayers'] = obj.table def update(request, obj, match, r1, r2): if r1 in request.GET and r2 in request.GET: try: if obj.get_match(match).can_modify(): obj.get_match(match).modify(int(request.GET[r1]), int(request.GET[r2])) except: pass else: obj.get_match(match).modify(0, 0) for i in range(0, (nplayers-1)*nplayers/2): update(request, obj, i, 'm%i-1' % i, 'm%i-2' % i) obj.compute() tally = obj.get_tally() players = list(sipl) for p in players: p.tally = tally[p][::-1] for i in range(len(players[0].tally)-1, -1, -1): players.sort(key=lambda p: p.tally[i], reverse=True) base['players'] = players MatchObj = namedtuple('MatchObj', 'obj pla plb modded canmod fixed sca scb') matches = [] for i in range(0, (nplayers-1)*nplayers/2): match = obj.get_match(i) matches.append(MatchObj(match, match.get_player(0).dbpl, match.get_player(1).dbpl,\ match.is_modified(), match.can_modify(), match.is_fixed(),\ match._result[0], match._result[1])) base['matches'] = matches base['ps'] = request.GET['ps'] base['bo'] = request.GET['bo'] rrgroup_postable(base, obj, players) return render_to_response('pred_rrgroup.html', base)
def pred_sebracket(request): base = base_ctx('Predict', request=request) dbpl = [get_object_or_404(Player, id=int(i)) for i in request.GET['ps'].split(',')] sipl = [make_player(pl) for pl in dbpl] nrounds = int(log(len(sipl),2)) num = [(int(bo)+1)/2 for bo in request.GET['bo'].split(',')] if len(num) == 1: num = num * nrounds obj = sebracket.SEBracket(num) obj.set_players(sipl) def update(request, obj, match, r1, r2): if r1 in request.GET and r2 in request.GET: try: if obj.get_match(match).can_modify(): obj.get_match(match).modify(int(request.GET[r1]), int(request.GET[r2])) except: pass for rnd in range(1, nrounds+1): for j in range(1, 2**(nrounds-rnd)+1): s = '%i-%i' % (rnd, j) update(request, obj, s, 'm' + s + '-1', 'm' + s + '-2') obj.compute() tally = obj.get_tally() players = list(sipl) for p in players: p.tally = tally[p][::-1] for i in range(len(players[0].tally)-1, -1, -1): players.sort(key=lambda p: p.tally[i], reverse=True) base['players'] = players base['nrounds'] = nrounds MatchObj = namedtuple('MatchObj', 'obj pla plb modded canmod fixed sca scb id') matches = [] for rnd in range(1, nrounds+1): matches.append('Round %i' % rnd) for j in range(1, 2**(nrounds-rnd)+1): match = obj.get_match('%i-%i' % (rnd, j)) matches.append(MatchObj(match, match.get_player(0).dbpl, match.get_player(1).dbpl,\ match.is_modified(), match.can_modify(), match.is_fixed(),\ match._result[0], match._result[1], '%i-%i' % (rnd, j))) base['matches'] = matches MeanRes = namedtuple('MeanRes', 'pla plb sca scb') meanres = [] for rnd in range(1, nrounds+1): meanres.append('Round %i' % rnd) for j in range(1, 2**(nrounds-rnd)+1): match = obj.get_match('%i-%i' % (rnd, j)) match.compute() lsup = match.find_lsup() meanres.append(MeanRes(match.get_player(0).dbpl, match.get_player(1).dbpl, lsup[1], lsup[2])) match.broadcast_instance((0, [lsup[4], lsup[3]], match)) base['meanres'] = meanres base['ps'] = request.GET['ps'] base['bo'] = request.GET['bo'] sebracket_postable(base, obj, players) return render_to_response('pred_sebracket.html', base)
def pred_rrgroup(request): base = base_ctx("Predict", request=request) dbpl = [get_object_or_404(Player, id=int(i)) for i in request.GET["ps"].split(",")] sipl = [make_player(pl) for pl in dbpl] num = (int(request.GET["bo"]) + 1) / 2 nplayers = len(sipl) obj = rrgroup.RRGroup(len(sipl), num, ["mscore", "sscore", "imscore", "isscore", "ireplay"], 1) obj.set_players(sipl) MeanRes = namedtuple("MeanRes", "pla plb sca scb") meanres = [] for i in range(0, (nplayers - 1) * nplayers / 2): match = obj.get_match(i) match.compute() lsup = match.find_lsup() meanres.append(MeanRes(match.get_player(0).dbpl, match.get_player(1).dbpl, lsup[1], lsup[2])) match.modify(lsup[1], lsup[2]) base["meanres"] = meanres obj.compute() mtally = obj.get_tally() for p in sipl: p.mtally = mtally[p] base["mplayers"] = obj.table def update(request, obj, match, r1, r2): if r1 in request.GET and r2 in request.GET: try: if obj.get_match(match).can_modify(): obj.get_match(match).modify(int(request.GET[r1]), int(request.GET[r2])) except: pass else: obj.get_match(match).modify(0, 0) for i in range(0, (nplayers - 1) * nplayers / 2): update(request, obj, i, "m%i-1" % i, "m%i-2" % i) obj.compute() tally = obj.get_tally() players = list(sipl) for p in players: p.tally = tally[p][::-1] for i in range(len(players[0].tally) - 1, -1, -1): players.sort(key=lambda p: p.tally[i], reverse=True) base["players"] = players MatchObj = namedtuple("MatchObj", "obj pla plb modded canmod fixed sca scb") matches = [] for i in range(0, (nplayers - 1) * nplayers / 2): match = obj.get_match(i) matches.append( MatchObj( match, match.get_player(0).dbpl, match.get_player(1).dbpl, match.is_modified(), match.can_modify(), match.is_fixed(), match._result[0], match._result[1], ) ) base["matches"] = matches base["ps"] = request.GET["ps"] base["bo"] = request.GET["bo"] rrgroup_postable( base, obj, players, url="http://aligulac.com/predict/rrgroup/?bo=%s&ps=%s" % (base["bo"], base["ps"]) ) return render_to_response("pred_rrgroup.html", base)
def pred_sebracket(request): base = base_ctx("Predict", request=request) dbpl = [] for i in request.GET["ps"].split(","): id = int(i) if id > 0: dbpl.append(get_object_or_404(Player, id=id)) else: dbpl.append(None) sipl = [make_player(pl) for pl in dbpl] nrounds = int(log(len(sipl), 2)) num = [(int(bo) + 1) / 2 for bo in request.GET["bo"].split(",")] if len(num) == 1: num = num * nrounds obj = sebracket.SEBracket(num) obj.set_players(sipl) def update(request, obj, match, r1, r2): if r1 in request.GET and r2 in request.GET: try: if obj.get_match(match).can_modify(): obj.get_match(match).modify(int(request.GET[r1]), int(request.GET[r2])) except: pass for rnd in range(1, nrounds + 1): for j in range(1, 2 ** (nrounds - rnd) + 1): s = "%i-%i" % (rnd, j) update(request, obj, s, "m" + s + "-1", "m" + s + "-2") obj.compute() tally = obj.get_tally() players = list(sipl) for p in players: p.tally = tally[p][::-1] for i in range(len(players[0].tally) - 1, -1, -1): players.sort(key=lambda p: p.tally[i], reverse=True) base["players"] = [p for p in players if p.dbpl is not None] base["nrounds"] = nrounds MatchObj = namedtuple("MatchObj", "obj pla plb modded canmod fixed sca scb id") matches = [] for rnd in range(1, nrounds + 1): matches.append("Round %i" % rnd) for j in range(1, 2 ** (nrounds - rnd) + 1): match = obj.get_match("%i-%i" % (rnd, j)) if match.get_player(0).dbpl is not None and match.get_player(1).dbpl is not None: matches.append( MatchObj( match, match.get_player(0).dbpl, match.get_player(1).dbpl, match.is_modified(), match.can_modify(), match.is_fixed(), match._result[0], match._result[1], "%i-%i" % (rnd, j), ) ) base["matches"] = matches MeanRes = namedtuple("MeanRes", "pla plb sca scb") meanres = [] for rnd in range(1, nrounds + 1): meanres.append("Round %i" % rnd) for j in range(1, 2 ** (nrounds - rnd) + 1): match = obj.get_match("%i-%i" % (rnd, j)) match.compute() lsup = match.find_lsup() meanres.append(MeanRes(match.get_player(0).dbpl, match.get_player(1).dbpl, lsup[1], lsup[2])) match.broadcast_instance((0, [lsup[4], lsup[3]], match)) base["meanres"] = meanres base["ps"] = request.GET["ps"] base["bo"] = request.GET["bo"] sebracket_postable( base, obj, players, url="http://aligulac.com/predict/sebracket/?bo=%s&ps=%s" % (base["bo"], base["ps"]) ) return render_to_response("pred_sebracket.html", base)
def pred_4pswiss(request): base = base_ctx("Predict", request=request) dbpl = [get_object_or_404(Player, id=int(i)) for i in request.GET["ps"].split(",")] sipl = [make_player(pl) for pl in dbpl] num = (int(request.GET["bo"]) + 1) / 2 obj = mslgroup.MSLGroup(num) obj.set_players(sipl) def update(request, obj, match, r1, r2): if r1 in request.GET and r2 in request.GET: try: if obj.get_match(match).can_modify(): obj.get_match(match).modify(int(request.GET[r1]), int(request.GET[r2])) except: pass update(request, obj, "first", "11", "12") update(request, obj, "second", "21", "22") update(request, obj, "winners", "31", "32") update(request, obj, "losers", "41", "42") update(request, obj, "final", "51", "52") obj.compute() tally = obj.get_tally() players = list(sipl) for p in players: p.tally = tally[p] for i in range(0, 4): players.sort(key=lambda p: p.tally[i], reverse=True) base["players"] = players MatchObj = namedtuple("MatchObj", "obj pla plb modded canmod fixed sca scb") matches = [] for mname in ["first", "second", "winners", "losers", "final"]: match = obj.get_match(mname) matches.append( MatchObj( match, match.get_player(0).dbpl, match.get_player(1).dbpl, match.is_modified(), match.can_modify(), match.is_fixed(), match._result[0], match._result[1], ) ) base["matches"] = matches MeanRes = namedtuple("MeanRes", "pla plb sca scb") meanres = [] for mname in ["first", "second", "winners", "losers", "final"]: match = obj.get_match(mname) match.compute() lsup = match.find_lsup() meanres.append(MeanRes(match.get_player(0).dbpl, match.get_player(1).dbpl, lsup[1], lsup[2])) match.broadcast_instance((0, [lsup[4], lsup[3]], match)) base["meanres"] = meanres base["ps"] = request.GET["ps"] base["bo"] = request.GET["bo"] fpswiss_postable( base, obj, players, url="http://aligulac.com/predict/4pswiss/?bo=%s&ps=%s" % (base["bo"], base["ps"]) ) return render_to_response("pred_4pswiss.html", base)