本文整理汇总了Python中ratings.tools.display_matches函数的典型用法代码示例。如果您正苦于以下问题:Python display_matches函数的具体用法?Python display_matches怎么用?Python display_matches使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了display_matches函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add_matches
def add_matches(request):
base = base_ctx('Submit', 'Matches', request)
login_message(base)
if request.method == 'POST' and 'submit' in request.POST:
form = AddMatchesForm(base['adm'], request=request)
base['matches'] = display_matches(form.parse_matches(request.user), messages=False)
base['messages'] += form.messages
else:
form = AddMatchesForm(base['adm'])
try:
get_event = Event.objects.get(id=request.GET['eventid'])
if get_event.closed:
get_event.open()
base['messages'].append(Message(_("Reopened '%s'.") % get_event.fullname, type=Message.SUCCESS))
form['eventobj'].field.choices.append((get_event.id, get_event.fullname))
form['eventobj'].field.choices.sort(key=lambda e: e[1])
base['event_override'] = get_event.id
except:
pass
base['form'] = form
base.update({"title": _("Submit results")})
return render_to_response('add.html', base)
开发者ID:kevinklaes,项目名称:aligulac,代码行数:26,代码来源:staff_views.py
示例2: player_results
def player_results(request, player_id):
player = get_object_or_404(Player, id=int(player_id))
matches = Match.objects.filter(Q(pla=player) | Q(plb=player))
base = base_ctx('Ranking', 'Match history', request, context=player)
if 'race' in request.GET:
q = None
for r in request.GET['race']:
try:
q |= Q(pla=player, rcb=r)
q |= Q(plb=player, rca=r)
except:
q = Q(pla=player, rcb=r)
q |= Q(plb=player, rca=r)
matches = matches.filter(q)
base['race'] = request.GET['race']
else:
base['race'] = 'ptzr'
if 'nats' in request.GET:
if request.GET['nats'] == 'foreigners':
matches = matches.exclude(Q(pla=player, plb__country='KR') | Q(plb=player, pla__country='KR'))
elif request.GET['nats'] == 'kr':
matches = matches.filter(Q(pla=player, plb__country='KR') | Q(plb=player, pla__country='KR'))
base['nats'] = request.GET['nats']
else:
base['nats'] = 'all'
if 'bo' in request.GET:
if request.GET['bo'] == '3':
matches = matches.filter(Q(sca__gte=2) | Q(scb__gte=2))
elif request.GET['bo'] == '5':
matches = matches.filter(Q(sca__gte=3) | Q(scb__gte=3))
base['bo'] = request.GET['bo']
else:
base['bo'] = 'all'
if 'offline' in request.GET:
if request.GET['offline'] == 'online':
matches = matches.filter(offline=0)
elif request.GET['offline'] == 'offline':
matches = matches.filter(offline=1)
base['offline'] = request.GET['offline']
else:
base['offline'] = 'both'
matches = matches.order_by('-date', '-eventobj__lft', 'event', '-id')
matches = matches.select_related('pla__rating').select_related('plb__rating').select_related('period')
base['matches'] = display_matches(matches, fix_left=player, ratings=True)
base['sc_my'] = sum([m.pla_score for m in base['matches']])
base['sc_op'] = sum([m.plb_score for m in base['matches']])
base['msc_my'] = sum([1 if m.pla_score > m.plb_score else 0 for m in base['matches']])
base['msc_op'] = sum([1 if m.plb_score > m.pla_score else 0 for m in base['matches']])
base['player'] = player
return render_to_response('player_results.html', base)
开发者ID:orangeups,项目名称:aligulac,代码行数:60,代码来源:views.py
示例3: review_matches
def review_matches(request):
base = base_ctx('Submit', 'Review', request)
if not base['adm']:
return redirect('/login/')
login_message(base)
if request.method == 'POST':
form = ReviewMatchesForm(request=request, submitter=request.user)
base['messages'] += form.messages
else:
form = ReviewMatchesForm()
base['form'] = form
base['groups'] = (
PreMatchGroup.objects.filter(prematch__isnull=False)
.prefetch_related('prematch_set')
.order_by('id', 'event')
.distinct()
)
for g in base['groups']:
g.prematches = display_matches(g.prematch_set.all(), messages=False)
base.update({"title": _("Review results")})
return render_to_response('review.html', base)
开发者ID:kevinklaes,项目名称:aligulac,代码行数:27,代码来源:staff_views.py
示例4: results
def results(request):
base = base_ctx('Results', 'By Date', request)
try:
day = datetime.strptime(get_param(request, 'd', None), '%Y-%m-%d').date()
except:
day = date.today()
bounds = Match.objects.aggregate(Min('date'), Max('date'))
day = min(max(bounds['date__min'], day), bounds['date__max'])
base.update({
'mindate': bounds['date__min'],
'maxdate': bounds['date__max'],
'td': day,
})
matches = (
Match.objects.filter(date=day).order_by('eventobj__idx', 'eventobj__latest', 'event', 'id')
.prefetch_related('message_set', 'rta', 'rtb', 'pla', 'plb', 'eventobj')
.annotate(Count('eventobj__match'))
)
add_links = request.user.is_authenticated() and request.user.is_staff
base['matches'] = display_matches(matches, date=False, ratings=True, messages=True,
eventcount=True, add_links=add_links)
return render_to_response('results.djhtml', base)
开发者ID:KenanY,项目名称:aligulac,代码行数:28,代码来源:results_views.py
示例5: results
def results(request, player_id):
# {{{ Get objects
player = get_object_or_404(Player, id=player_id)
base = base_ctx('Ranking', 'Match history', request, context=player)
base['player'] = player
# }}}
# {{{ Filtering
matches = player.get_matchset(related=['pla','plb','eventobj'])
form = ResultsFilterForm(request.GET)
base['form'] = form
form.is_valid()
q = Q()
for r in form.cleaned_data['race'].upper():
q |= Q(pla=player, rcb=r) | Q(plb=player, rca=r)
matches = matches.filter(q)
if form.cleaned_data['country'] == 'foreigners':
matches = matches.exclude(Q(pla=player, plb__country='KR') | Q(plb=player, pla__country='KR'))
elif form.cleaned_data['country'] != 'all':
matches = matches.filter(
Q(pla=player, plb__country=form.cleaned_data['country'])
| Q(plb=player, pla__country=form.cleaned_data['country'])
)
if form.cleaned_data['bestof'] != 'all':
sc = int(form.cleaned_data['bestof'])//2 + 1
matches = matches.filter(Q(sca__gte=sc) | Q(scb__gte=sc))
if form.cleaned_data['offline'] != 'both':
matches = matches.filter(offline=(form.cleaned_data['offline']=='offline'))
if form.cleaned_data['game'] != 'all':
matches = matches.filter(game=form.cleaned_data['game'])
if form.cleaned_data['after'] is not None:
matches = matches.filter(date__gte=form.cleaned_data['after'])
if form.cleaned_data['before'] is not None:
matches = matches.filter(date__lte=form.cleaned_data['before'])
# }}}
# {{{ Statistics
base['matches'] = display_matches(matches, fix_left=player)
base.update({
'sc_my': sum([m['pla_score'] for m in base['matches']]),
'sc_op': sum([m['plb_score'] for m in base['matches']]),
'msc_my': sum([1 if m['pla_score'] > m['plb_score'] else 0 for m in base['matches']]),
'msc_op': sum([1 if m['plb_score'] > m['pla_score'] else 0 for m in base['matches']]),
})
# }}}
base.update({"title": player.tag})
return render_to_response('player_results.html', base)
开发者ID:Lukepmcauley,项目名称:aligulac,代码行数:59,代码来源:player_views.py
示例6: integrity
def integrity(request):
base = base_ctx('Submit', 'Integrity', request)
if not base['adm']:
base.update(csrf(request))
return render_to_response('login.html', base)
add_login_message(base)
base.update(csrf(request))
with open(M_WARNINGS, 'r') as f:
warnings = pickle.load(f)
with open(M_APPROVED, 'r') as f:
approved = pickle.load(f)
if 'del' in request.POST or 'del_ok' in request.POST:
ndel = 0
for key in request.POST:
if request.POST[key] != 'y':
continue
if key[0:6] == 'match-':
try:
Match.objects.get(id=int(key.split('-')[-1])).delete()
ndel += 1
except:
pass
base['messages'].append(Message('Deleted %i match(es).' % ndel, type=Message.SUCCESS))
if 'del_ok' in request.POST or 'false' in request.POST:
warning = tuple([int(f) for f in request.POST['warning'].split(',')])
warnings.remove(warning)
approved.add(warning)
with open(M_WARNINGS, 'w') as f:
pickle.dump(warnings, f)
with open(M_APPROVED, 'w') as f:
pickle.dump(approved, f)
base['messages'].append(Message('Resolved one integrity warning.', type=Message.SUCCESS))
matches = []
for w in warnings:
block = []
for id in w:
try:
block.append(Match.objects.get(id=id))
except:
pass
matches.append((','.join(str(k) for k in list(w)), display_matches(block, messages=False)))
if len(matches) == 50:
break
base['matches'] = matches
if len(matches) == 0:
base['messages'].append(Message('There are currently no warnings pending resolution.',
type=Message.INFO))
base['num'] = len(warnings)
return render_to_response('integrity.html', base)
开发者ID:Arzar,项目名称:aligulac,代码行数:59,代码来源:submitviews.py
示例7: integrity
def integrity(request):
base = base_ctx('Submit', 'Integrity', request)
if not base['adm']:
base.update(csrf(request))
return render_to_response('login.html', base)
base['user'] = request.user.username
base.update(csrf(request))
with open(M_WARNINGS, 'r') as f:
warnings = pickle.load(f)
with open(M_APPROVED, 'r') as f:
approved = pickle.load(f)
if 'del' in request.POST or 'del_ok' in request.POST:
for key in request.POST:
if request.POST[key] != 'y':
continue
if key[0:6] == 'match-':
try:
Match.objects.get(id=int(key.split('-')[-1])).delete()
except:
pass
if 'del_ok' in request.POST or 'false' in request.POST:
warning = tuple([int(f) for f in request.POST['warning'].split(',')])
warnings.remove(warning)
approved.add(warning)
with open(M_WARNINGS, 'w') as f:
pickle.dump(warnings, f)
with open(M_APPROVED, 'w') as f:
pickle.dump(approved, f)
matches = []
for w in warnings:
block = []
for id in w:
try:
block.append(Match.objects.get(id=id))
except:
pass
matches.append((','.join(str(k) for k in list(w)), display_matches(block)))
if len(matches) == 50:
break
base['matches'] = matches
base['num'] = len(warnings)
return render_to_response('integrity.html', base)
开发者ID:orangeups,项目名称:aligulac,代码行数:51,代码来源:submitviews.py
示例8: results
def results(request):
base = base_ctx('Results', 'By Date', request)
try:
ints = [int(x) for x in request.GET['d'].split('-')]
td = datetime.date(ints[0], ints[1], ints[2])
except:
td = datetime.date.today()
matches = Match.objects.filter(date=td).order_by('eventobj__lft', 'event', 'id')
base['matches'] = display_matches(matches, date=False, ratings=True)
base['td'] = td
return render_to_response('results.html', base)
开发者ID:orangeups,项目名称:aligulac,代码行数:15,代码来源:views.py
示例9: clocks
def clocks(request):
ctx = base_ctx('Misc', 'Days Since…', request)
ctx["title"] = _("Number of days since…")
ctx["clocks"] = list()
for desc, alt_desc, q, t in CLOCKS:
obj = None
extra = None
date = None
if t == "match":
q = q.prefetch_related("pla", "plb", "eventobj")
matches = list(q[:10])
extra = display_matches(matches)
obj = matches[0]
date = obj.date
elif t == "event_winner":
q = q.prefetch_related("earnings_set")
events = list(q[:10])
obj = events[0]
extra = list()
for e in events:
pearnings = list(
e.earnings_set
.exclude(placement=0)
.order_by("placement")
.prefetch_related("player")[:2]
)
extra.append((e, pearnings))
date = obj.latest
elif t == "one_time":
date = q()
diff = datetime.today().date() - date
years = diff.days // 365
days = diff.days % 365
c = Clock(desc, alt_desc, obj, t, date, years, days, extra)
ctx["clocks"].append(c)
ctx["clocks"].sort(key=lambda c: c.date, reverse=True)
return render_to_response("clocks.html", ctx)
开发者ID:kevinklaes,项目名称:aligulac,代码行数:48,代码来源:misc_views.py
示例10: match
def match(request):
base = base_ctx('Inference', 'Predict', request=request)
# {{{ Get data, set up and simulate
form = SetupForm(request.GET)
if not form.is_valid():
return redirect('/inference/')
result = MatchPredictionResult(
dbpl=form.cleaned_data['ps'],
bos=form.cleaned_data['bo'],
s1=get_param(request, 's1', 0),
s2=get_param(request, 's2', 0),
)
# }}}
# {{{ Postprocessing
base.update({
'form': form,
'dbpl': result.dbpl,
'rta': result.rta,
'rtb': result.rtb,
'proba': result.proba,
'probb': result.probb,
'match': result.obj,
})
base.update({
'max': max(base['proba'], base['probb']),
'fav': result.dbpl[0] if base['proba'] > base['probb'] else result.dbpl[1],
})
resa = [oc for oc in result.outcomes if oc['sca'] > oc['scb']]
resb = [oc for oc in result.outcomes if oc['scb'] > oc['sca']]
if len(resa) < len(resb):
resa = [None] * (len(resb) - len(resa)) + resa
else:
resb = [None] * (len(resa) - len(resb)) + resb
base['res'] = list(zip(resa, resb))
# }}}
# {{{ Scores and other data
dbpl = result.dbpl
thr = date.today() - relativedelta(months=2)
pla_matches = dbpl[0].get_matchset()
plb_matches = dbpl[1].get_matchset()
base['tot_w_a'], base['tot_l_a'] = count_winloss_player(pla_matches, dbpl[0])
base['frm_w_a'], base['frm_l_a'] = count_winloss_player(pla_matches.filter(date__gte=thr), dbpl[0])
base['tot_w_b'], base['tot_l_b'] = count_winloss_player(plb_matches, dbpl[1])
base['frm_w_b'], base['frm_l_b'] = count_winloss_player(plb_matches.filter(date__gte=thr), dbpl[1])
if dbpl[1].race in 'PTZ':
base['mu_w_a'], base['mu_l_a'] = count_matchup_player(pla_matches, dbpl[0], dbpl[1].race)
base['fmu_w_a'], base['fmu_l_a'] = count_matchup_player(
pla_matches.filter(date__gte=thr), dbpl[0], dbpl[1].race
)
if dbpl[0].race in 'PTZ':
base['mu_w_b'], base['mu_l_b'] = count_matchup_player(plb_matches, dbpl[1], dbpl[0].race)
base['fmu_w_b'], base['fmu_l_b'] = count_matchup_player(
plb_matches.filter(date__gte=thr), dbpl[1], dbpl[0].race
)
wa_a, wb_a = count_winloss_games(Match.objects.filter(pla=dbpl[0], plb=dbpl[1]))
wb_b, wa_b = count_winloss_games(Match.objects.filter(pla=dbpl[1], plb=dbpl[0]))
base['vs_a'] = wa_a + wa_b
base['vs_b'] = wb_a + wb_b
base['matches'] = display_matches(
Match.objects.filter(Q(pla=dbpl[0], plb=dbpl[1]) | Q(plb=dbpl[0], pla=dbpl[1]))
.select_related('period', 'pla', 'plb')
.order_by('-date', 'id'),
fix_left=dbpl[0],
)
# }}}
postable_match(base, request)
return render_to_response('pred_match.djhtml', base)
开发者ID:Grovbolle,项目名称:aligulac,代码行数:76,代码来源:inference_views.py
示例11: events
def events(request, event_id=None):
# {{{ Get base context, redirect if necessary
if 'goto' in request.GET:
return redirect('/results/events/' + request.GET['goto'])
base = base_ctx('Results', 'By Event', request)
# }}}
# {{{ Display the main table if event ID is not given
if event_id is None:
root_events = (
Event.objects
.annotate(num_uplinks=Count("uplink"))
.filter(num_uplinks=1)
.order_by('name')
.only('id', 'name', 'big', 'category', 'fullname')
)
base.update({
'ind_bigs': collect(root_events.filter(big=True, category=CAT_INDIVIDUAL), 2),
'ind_smalls': root_events.filter(big=False, category=CAT_INDIVIDUAL).order_by('name'),
'team_bigs': collect(root_events.filter(big=True, category=CAT_TEAM), 2),
'team_smalls': root_events.filter(big=False, category=CAT_TEAM).order_by('name'),
'freq_bigs': collect(root_events.filter(big=True, category=CAT_FREQUENT), 2),
'freq_smalls': root_events.filter(big=False, category=CAT_FREQUENT).order_by('name'),
})
return render_to_response('events.html', base)
# }}}
# {{{ Get object, generate messages, and ensure big is set. Find familial relationships.
event = get_object_or_404(Event, id=event_id)
base['messages'] += generate_messages(event)
matches = event.get_matchset()
if matches.count() > 200 and not event.big:
event.set_big(True)
base.update({
'event': event,
'siblings': event.get_parent().get_immediate_children().exclude(id=event.id)
if event.get_parent() else None,
'path': event.get_ancestors(id=True),
'children': event.get_immediate_children(),
})
# }}}
# {{{ Make forms
if base['adm']:
def check_form(formname, cl, check):
if request.method == 'POST' and check in request.POST:
f = cl(request=request, event=event)
base['messages'] += f.update_event(event)
else:
f = cl(event=event)
base[formname] = f
check_form('form', EventModForm, 'modevent')
check_form('addform', AddForm, 'addevent')
if event.has_children():
check_form('reorderform', ReorderForm, 'reorder')
if event.type == TYPE_EVENT:
check_form('ppform', PrizepoolModForm, 'modpp')
if not event.has_children() and event.get_immediate_matchset().exists():
check_form('stform', StoryModForm, 'modstories')
# }}}
# {{{ Prizepool information for the public
total_earnings = Earnings.objects.filter(event__uplink__parent=event)
currencies = list({r['currency'] for r in total_earnings.values('currency').distinct()})
base.update({
'prizepool': total_earnings.aggregate(Sum('earnings'))['earnings__sum'],
'nousdpp': len(currencies) > 1 or len(currencies) == 1 and currencies[0] != 'USD',
'prizepoolorig': [{
'pp': total_earnings.filter(currency=k).aggregate(Sum('origearnings'))['origearnings__sum'],
'cur': k,
} for k in currencies],
})
# }}}
# {{{ Other easy statistics
base.update({
'game': etn(lambda: dict(Match.GAMES)[matches.values('game').distinct()[0]['game']]),
'offline': etn(lambda: matches.values('offline').distinct()[0]['offline']),
'nmatches': matches.count(),
'ngames': sum(count_winloss_games(matches)),
'pvp_games': count_mirror_games(matches, 'P'),
'tvt_games': count_mirror_games(matches, 'T'),
'zvz_games': count_mirror_games(matches, 'Z'),
'matches': display_matches(
matches.prefetch_related('message_set')
.prefetch_related('pla', 'plb', 'eventobj')
.annotate(Count('eventobj__match'))
.order_by('-eventobj__latest', '-eventobj__idx', '-date', '-id')[0:200],
eventcount=True,
),
'nplayers': Player.objects.filter(
Q(id__in=matches.values('pla')) | Q(id__in=matches.values('plb'))
).count(),
})
#.........这里部分代码省略.........
开发者ID:HotspurHN,项目名称:aligulac,代码行数:101,代码来源:results_views.py
示例12: match
def match(request):
base = base_ctx('Inference', 'Predict', request=request)
# {{{ Get data, set up and simulate
form = SetupForm(request.GET)
if not form.is_valid():
return redirect('/inference/')
num = form.cleaned_data['bo'][0]
dbpl = form.cleaned_data['ps']
sipl = [make_player(p) for p in dbpl]
match = MatchSim(num)
match.set_players(sipl)
match.modify(
get_param_range(request, 's1', (0, num), 0),
get_param_range(request, 's2', (0, num), 0),
)
match.compute()
# }}}
# {{{ Postprocessing
base.update({
'form': form,
'dbpl': dbpl,
'rta': sipl[0].elo_vs_opponent(sipl[1]),
'rtb': sipl[1].elo_vs_opponent(sipl[0]),
'proba': match.get_tally()[sipl[0]][1],
'probb': match.get_tally()[sipl[1]][1],
'match': match,
})
base.update({
'max': max(base['proba'], base['probb']),
'fav': dbpl[0] if base['proba'] > base['probb'] else dbpl[1],
})
resa, resb = [], []
outcomes = [
{'sca': outcome[1], 'scb': outcome[2], 'prob': outcome[0]}
for outcome in match.instances_detail()
]
resa = [oc for oc in outcomes if oc['sca'] > oc['scb']]
resb = [oc for oc in outcomes if oc['scb'] > oc['sca']]
if len(resa) < len(resb):
resa = [None] * (len(resb) - len(resa)) + resa
else:
resb = [None] * (len(resa) - len(resb)) + resb
base['res'] = list(zip(resa, resb))
# }}}
# {{{ Scores and other data
thr = date.today() - relativedelta(months=2)
pla_matches = dbpl[0].get_matchset()
plb_matches = dbpl[1].get_matchset()
base['tot_w_a'], base['tot_l_a'] = count_winloss_player(pla_matches, dbpl[0])
base['frm_w_a'], base['frm_l_a'] = count_winloss_player(pla_matches.filter(date__gte=thr), dbpl[0])
base['tot_w_b'], base['tot_l_b'] = count_winloss_player(plb_matches, dbpl[1])
base['frm_w_b'], base['frm_l_b'] = count_winloss_player(plb_matches.filter(date__gte=thr), dbpl[1])
if dbpl[1].race in 'PTZ':
base['mu_w_a'], base['mu_l_a'] = count_matchup_player(pla_matches, dbpl[0], dbpl[1].race)
base['fmu_w_a'], base['fmu_l_a'] = count_matchup_player(
pla_matches.filter(date__gte=thr), dbpl[0], dbpl[1].race
)
if dbpl[0].race in 'PTZ':
base['mu_w_b'], base['mu_l_b'] = count_matchup_player(plb_matches, dbpl[1], dbpl[0].race)
base['fmu_w_b'], base['fmu_l_b'] = count_matchup_player(
plb_matches.filter(date__gte=thr), dbpl[1], dbpl[0].race
)
wa_a, wb_a = count_winloss_games(Match.objects.filter(pla=dbpl[0], plb=dbpl[1]))
wb_b, wa_b = count_winloss_games(Match.objects.filter(pla=dbpl[1], plb=dbpl[0]))
base['vs_a'] = wa_a + wa_b
base['vs_b'] = wb_a + wb_b
base['matches'] = display_matches(
Match.objects.filter(Q(pla=dbpl[0], plb=dbpl[1]) | Q(plb=dbpl[0], pla=dbpl[1]))
.select_related('period', 'pla', 'plb')
.order_by('-date', 'id'),
fix_left=dbpl[0],
)
# }}}
postable_match(base, request)
base.update({"title": "{} vs. {}".format(dbpl[0].tag, dbpl[1].tag)})
return render_to_response('pred_match.html', base)
开发者ID:Lukepmcauley,项目名称:aligulac,代码行数:87,代码来源:inference_views.py
示例13: results
def results(request, player_id):
# {{{ Get objects
player = get_object_or_404(Player, id=player_id)
base = base_ctx("Ranking", "Match history", request, context=player)
base["player"] = player
# }}}
# {{{ Filtering
matches = player.get_matchset(related=["pla", "plb", "eventobj"])
form = ResultsFilterForm(request.GET)
base["form"] = form
form.is_valid()
q = Q()
for r in form.cleaned_data["race"].upper():
q |= Q(pla=player, rcb=r) | Q(plb=player, rca=r)
matches = matches.filter(q)
if form.cleaned_data["country"] == "foreigners":
matches = matches.exclude(Q(pla=player, plb__country="KR") | Q(plb=player, pla__country="KR"))
elif form.cleaned_data["country"] != "all":
matches = matches.filter(
Q(pla=player, plb__country=form.cleaned_data["country"])
| Q(plb=player, pla__country=form.cleaned_data["country"])
)
if form.cleaned_data["bestof"] != "all":
sc = int(form.cleaned_data["bestof"]) // 2 + 1
matches = matches.filter(Q(sca__gte=sc) | Q(scb__gte=sc))
if form.cleaned_data["offline"] != "both":
matches = matches.filter(offline=(form.cleaned_data["offline"] == "offline"))
if form.cleaned_data["game"] != "all":
matches = matches.filter(game=form.cleaned_data["game"])
if form.cleaned_data["after"] is not None:
matches = matches.filter(date__gte=form.cleaned_data["after"])
if form.cleaned_data["before"] is not None:
matches = matches.filter(date__lte=form.cleaned_data["before"])
if form.cleaned_data["event"] is not None:
lex = shlex.shlex(form.cleaned_data["event"], posix=True)
lex.wordchars += "'"
lex.quotes = '"'
terms = [s.strip() for s in list(lex) if s.strip() != ""]
matches = matches.filter(eventobj__fullname__iregex=(r"\s".join(r".*{}.*".format(term) for term in terms)))
# }}}
# {{{ Statistics
disp_matches = display_matches(matches, fix_left=player)
base["matches"] = disp_matches
base.update(
{
"sc_my": sum(m["pla"]["score"] for m in base["matches"]),
"sc_op": sum(m["plb"]["score"] for m in base["matches"]),
"msc_my": sum(1 for m in base["matches"] if m["pla"]["score"] > m["plb"]["score"]),
"msc_op": sum(1 for m in base["matches"] if m["plb"]["score"] > m["pla"]["score"]),
}
)
recent = matches.filter(date__gte=(date.today() - relativedelta(months=2)))
base.update(
{
"total": count_winloss_player(matches, player),
"vp": count_matchup_player(matches, player, P),
"vt": count_matchup_player(matches, player, T),
"vz": count_matchup_player(matches, player, Z),
"totalf": count_winloss_player(recent, player),
"vpf": count_matchup_player(recent, player, P),
"vtf": count_matchup_player(recent, player, T),
"vzf": count_matchup_player(recent, player, Z),
}
)
# }}}
# {{{ TL Postable
has_after = form.cleaned_data["after"] is not None
has_before = form.cleaned_data["before"] is not None
if not has_after and not has_before:
match_date = ""
elif not has_after: # and has_before
match_date = _(" before {}").format(form.cleaned_data["before"])
elif not has_before: # and has_after
match_date = _(" after {}").format(form.cleaned_data["after"])
else:
match_date = _(" between {} and {}").format(form.cleaned_data["after"], form.cleaned_data["before"])
match_filter = ""
def switcher(race):
if race == "S":
#.........这里部分代码省略.........
开发者ID:Grovbolle,项目名称:aligulac,代码行数:101,代码来源:player_views.py
示例14: adjustment
def adjustment(request, player_id, period_id):
# {{{ Get objects
period = get_object_or_404(Period, id=period_id, computed=True)
player = get_object_or_404(Player, id=player_id)
rating = get_object_or_404(Rating, player=player, period=period)
base = base_ctx("Ranking", "Adjustments", request, context=player)
base.update(
{
"period": period,
"player": player,
"rating": rating,
"prevlink": etn(lambda: player.rating_set.filter(period__lt=period, decay=0).latest("period")),
"nextlink": etn(lambda: player.rating_set.filter(period__gt=period, decay=0).earliest("period")),
}
)
# }}}
# {{{ Matches
matches = player.get_matchset(related=["rta", "rtb", "pla", "plb", "eventobj"]).filter(period=period)
# If there are no matches, we don't need to continue
if not matches.exists():
return render_to_response("ratingdetails.djhtml", base)
base.update(
{
"matches": display_matches(matches, fix_left=player, ratings=True),
"has_treated": False,
"has_nontreated": False,
}
)
# }}}
# {{{ Perform calculations
tot_rating = {"M": 0.0, "P": 0.0, "T": 0.0, "Z": 0.0}
ngames = {"M": 0.0, "P": 0.0, "T": 0.0, "Z": 0.0}
expwins = {"M": 0.0, "P": 0.0, "T": 0.0, "Z": 0.0}
nwins = {"M": 0.0, "P": 0.0, "T": 0.0, "Z": 0.0}
for m in base["matches"]:
if not m["match"].treated:
base["has_nontreated"] = True
continue
base["has_treated"] = True
total_score = m["pla"]["score"] + m["plb"]["score"]
scale = sqrt(1 + m["pla"]["dev"] ** 2 + m["plb"]["dev"] ** 2)
expected = total_score * cdf(m["pla"]["rating"] - m["plb"]["rating"], scale=scale)
ngames["M"] += total_score
tot_rating["M"] += m["plb"]["rating"] * total_score
expwins["M"] += expected
nwins["M"] += m["pla"]["score"]
vs_races = [m["plb"]["race"]] if m["plb"]["race"] in "PTZ" else "PTZ"
weight = 1 / len(vs_races)
for r in vs_races:
ngames[r] += weight * total_score
tot_rating[r] += weight * m["plb"]["rating"] * total_score
expwins[r] += weight * expected
nwins[r] += weight * m["pla"]["score"]
for r in "MPTZ":
if ngames[r] > 0:
tot_rating[r] /= ngames[r]
base.update({"ngames": ngames, "tot_rating": tot_rating, "expwins": expwins, "nwins": nwins})
# }}}
return render_to_response("ratingdetails.djhtml", base)
开发者ID:Grovbolle,项目名称:aligulac,代码行数:72,代码来源:player_views.py
示例15: review
def review(request):
base = base_ctx('Submit', 'Review', request)
if not base['adm']:
base.update(csrf(request))
return render_to_response('login.html', base)
add_login_message(base)
base['events'] = Event.objects.filter(closed=False, rgt=F('lft')+1).order_by('lft')
if 'act' in request.POST and base['adm'] == True:
if int(request.POST['eobj']) != 2:
eobj = Event.objects.get(id=int(request.POST['eobj']))
base['eobj'] = eobj.id
delete = True if request.POST['act'] == 'reject' else False
success = []
ndel = 0
for key in sorted(request.POST.keys()):
if request.POST[key] != 'y':
continue
if key[0:6] == 'match-':
pm = PreMatch.objects.get(id=int(key.split('-')[-1]))
if delete:
group = pm.group
pm.delete()
if not group.prematch_set.all().exists():
group.delete()
ndel += 1
continue
if pm.pla == None:
pm.pla_string = request.POST['match-%i-pla' % pm.id]
if pm.plb == None:
pm.plb_string = request.POST['match-%i-plb' % pm.id]
if pm.pla == None or pm.plb == None:
review_treat_players(pm, base)
if pm.pla and not pm.rca:
pm.pla = None
if pm.plb and not pm.rcb:
pm.plb = None
pm.save()
if pm.pla and pm.plb and pm.rca and pm.rcb:
m = Match()
m.pla = pm.pla
m.plb = pm.plb
m.sca = pm.sca
m.scb = pm.scb
m.rca = pm.rca
m.rcb = pm.rcb
if request.POST['date'].strip() == '':
m.date = pm.group.date
else:
m.date = request.POST['date']
m.event = pm.group.event
m.eventobj = eobj
m.submitter = request.user
m.set_period()
m.offline = pm.group.offline
m.game = pm.group.game
m.save()
success.append(m)
group = pm.group
pm.delete()
if not group.prematch_set.all().exists():
group.delete()
base['success'] = display_matches(success, messages=False)
if len(success) > 0:
base['messages'].append(Message('Approved %i match(es).' % len(success), type=Message.SUCCESS))
if ndel > 0:
base['messages'].append(Message('Rejected %i match(es).' % ndel, type=Message.SUCCESS))
groups = PreMatchGroup.objects.filter(prematch__isnull=False)\
.select_related('prematch').order_by('id', 'event').distinct()
for g in groups:
g.prematches = display_matches(g.prematch_set.all(), messages=False)
base['groups'] = groups
base.update(csrf(request))
return render_to_response('review.html', base)
开发者ID:Arzar,项目名称:aligulac,代码行数:91,代码来源:submitviews.py
示例16: results
def results(request, player_id):
# {{{ Get objects
player = get_object_or_404(Player, id=player_id)
base = base_ctx('Ranking', 'Match history', request, context=player)
base['player'] = player
# }}}
# {{{ Filtering
matches = player.get_matchset(related=['pla','plb','eventobj'])
form = ResultsFilterForm(request.GET)
base['form'] = form
form.is_valid()
q = Q()
for r in form.cleaned_data['race'].upper():
q |= Q(pla=player, rcb=r) | Q(plb=player, rca=r)
matches = matches.filter(q)
if form.cleaned_data['country'] == 'foreigners':
matches = matches.exclude(Q(pla=player, plb__country='KR') | Q(plb=player, pla__country='KR'))
elif form.cleaned_data['country'] != 'all':
matches = matches.filter(
Q(pla=player, plb__country=form.cleaned_data['country'])
| Q(plb=player, pla__country=form.cleaned_data['country'])
)
if form.cleaned_data['bestof'] != 'all':
sc = int(form.cleaned_data['bestof'])//2 + 1
matches = matches.filter(Q(sca__gte=sc) | Q(scb__gte=sc))
if form.cleaned_data['offline'] != 'both':
matches = matches.filter(offline=(form.cleaned_data['offline']=='offline'))
if form.cleaned_data['game'] != 'all':
matches = matches.filter(game=form.cleaned_data['game'])
if form.cleaned_data['wcs_season'] != '':
if form.cleaned_data['wcs_season'] == 'all':
matches = matches.filter(
eventobj__uplink__parent__wcs_year__isnull=False
)
else:
matches = matches.filter(
eventobj__uplink__parent__wcs_year=int(form.cleaned_data['wcs_season'])
)
if form.cleaned_data['wcs_tier'] != '':
tiers = list(map(int, form.cleaned_data['wcs_tier']))
matches = matches.filter(
eventobj__uplink__parent__wcs_tier__in=tiers
)
if form.cleaned_data['after'] is not None:
matches = matches.filter(date__gte=form.cleaned_data['after'])
if form.cleaned_data['before'] is not None:
matches = matches.filter(date__lte=form.cleaned_data['before'])
if form.cleaned_data['event'] is not None:
lex = shlex.shlex(form.cleaned_data['event'], posix=True)
lex.wordchars += "'"
lex.quotes = '"'
terms = [s.strip() for s in list(lex) if s.strip() != '']
matches = matches.filter(
eventobj__fullname__iregex=(
r"\s".join(r".*{}.*".format(term) for term in terms)
)
)
matches = matches.distinct()
# }}}
# {{{ Statistics
disp_matches = display_matches(matches, fix_left=player)
base['matches'] = disp_matches
base.update({
'sc_my': sum(m['pla']['score'] for m in base['matches']),
'sc_op': sum(m['plb']['score'] for m in base['matches']),
'msc_my': sum(1 for m in base['matches'] if m['pla']['score'] > m['plb']['score']),
'msc_op': sum(1 for m in base['matches'] if m['plb']['score'] > m['pla']['score']),
})
recent = matches.filter(date__gte=(date.today() - relativedelta(months=2)))
base.update({
'total': count_winloss_player(matches, player),
'vp': count_matchup_player(matches, player, P),
'vt': count_matchup_player(matches, player, T),
'vz': count_matchup_player(matches, player, Z),
'totalf': count_winloss_player(recent, player),
'vpf': count_matchup_player(recent, player, P),
'vtf': count_matchup_player(recent, player, T),
'vzf': count_matchup_player(recent, player, Z)
})
# }}}
# {{{ TL Postable
#.........这里部分代码省略.........
开发者ID:Prillan,项目名称:aligulac,代码行数:101,代码来源:player_views.py
示例17: adjustment
def adjustment(request, player_id, period_id):
# {{{ Get objects
period = get_object_or_404(Period, id=period_id, computed=True)
player = get_object_or_404(Player, id=player_id)
rating = get_object_or_404(Rating, player=player, period=period)
base = base_ctx('Ranking', 'Adjustments', request, context=player)
base.update({
'period': period,
'player': player,
'rating': rating,
'prevlink': etn(lambda: player.rating_set.filter(period__lt=period, decay=0).latest('period')),
'nextlink': etn(lambda: player.rating_set.filter(period__gt=period, decay=0).earliest('period')),
})
# }}}
# {{{ Matches
matches = player.get_matchset(related=['rta','rtb','pla','plb','eventobj']).filter(period=period)
base.update({"title": player.tag})
# If there are no matches, we don't need to continue
if not matches.exists():
return render_to_response('ratingdetails.html', base)
base.update({
'matches': display_matches(matches, fix_left=player, ratings=True),
'has_treated': False,
'has_nontreated': False,
})
# }}}
# {{{ Perform calculations
tot_rating = {'M': 0.0, 'P': 0.0, 'T': 0.0, 'Z': 0.0}
ngames = {'M': 0.0, 'P': 0.0, 'T': 0.0, 'Z': 0.0}
expwins = {'M': 0.0, 'P': 0.0, 'T': 0.0, 'Z': 0.0}
nwins = {'M': 0.0, 'P': 0.0, 'T': 0.0, 'Z': 0.0}
for m in base['matches']:
if not m['match'].treated:
base['has_nontreated'] = True
continue
base['has_treated'] = True
total_score = m['pla']['score'] + m['plb']['score']
scale = sqrt(1 + m['pla']['dev']**2 + m['plb']['dev']**2)
expected = total_score * cdf(m['pla']['rating'] - m['plb']['rating'], scale=scale)
ngames['M'] += total_score
tot_rating['M'] += m['plb']['rating'] * total_score
expwins['M'] += expected
nwins['M'] += m['pla']['score']
vs_races = [m['plb']['race']] if m['plb']['race'] in 'PTZ' else 'PTZ'
weight = 1/len(vs_races)
for r in vs_races:
ngames[r] += weight * total_score
tot_rating[r] += weight * m['plb']['rating'] * total_score
expwins[r] += weight * expected
nwins[r] += weight * m['pla']['score']
for r in 'MPTZ':
if ngames[r] > 0:
tot_rating[r] /= ngames[r]
base.update({
'ngames': ngames,
'tot_rating':
|
请发表评论