Skip to content

Commit

Permalink
Merge pull request #220 from aiarena/staging
Browse files Browse the repository at this point in the history
Release v1.3.9
  • Loading branch information
lladdy authored Feb 16, 2021
2 parents eed1210 + 6add8bd commit 0976b75
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
13 changes: 2 additions & 11 deletions aiarena/api/arenaclient/ac_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _get_competition_priority_order():
and cc.status in ('open', 'closing', 'paused')) as competition_participations_total) as perc_active
left join
(select competition_id, perc_recent_matches_cnt / recent_matches_total_cnt as perc_recent_matches
from (select competition_id, count(competition_id) perc_recent_matches_cnt
from (select competition_id, count(competition_id) perc_recent_matches_cnt, count(*) recent_matches_total_cnt
from (select competition_id
from core_match cm
join core_round cr on cm.round_id = cr.id
Expand All @@ -99,16 +99,7 @@ def _get_competition_priority_order():
and cc.status in ('open', 'closing', 'paused')
order by cm.started desc
limit 100) as matches
group by competition_id) as recent_matches
join
(select count(*) recent_matches_total_cnt
from core_match cm
join core_round cr on cm.round_id = cr.id
join core_competition cc on cr.competition_id = cc.id
where cm.started is not null
and cc.status in ('open', 'closing', 'paused')
order by cm.started desc
limit 100) as recent_matches_total) as perc_recent_matches
group by competition_id) as recent_matchesl) as perc_recent_matches
on perc_recent_matches.competition_id = perc_active.competition_id
order by COALESCE(perc_recent_matches, 0) - perc_active
""")
Expand Down
5 changes: 2 additions & 3 deletions aiarena/core/models/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ class Bot(models.Model, LockableModelMixin):
game_display_id = models.UUIDField(default=uuid.uuid4)
wiki_article = models.OneToOneField(Article, on_delete=models.PROTECT, blank=True, null=True)

@property
def current_elo_trend(self):
def current_elo_trend(self, competition):
from .relative_result import RelativeResult
return (RelativeResult.objects
.filter(me__bot=self, match__requested_by__isnull=True)
.filter(me__bot=self, match__requested_by__isnull=True, match__round__competition=competition)
.order_by('-created')[:config.ELO_TREND_N_MATCHES]
.aggregate(Sum('elo_change'))['elo_change__sum'])

Expand Down
8 changes: 7 additions & 1 deletion aiarena/core/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def test_competition_states(self):
competition2.freeze()

self.assertEqual(Match.objects.exclude(round__competition_id=competition2.id).filter(result__isnull=True)
.count(), 19, msg='This test expects 19 unplayed matches in order to work.')
.count(), 16, msg='This test expects 16 unplayed matches in order to work.')

# cache the bots - list forces the queryset to be evaluated
bots = list(Bot.objects.all())
Expand Down Expand Up @@ -659,6 +659,12 @@ def test_cancel_matches(self):
def test_cleanup_replays_and_logs(self):
NUM_MATCHES = 12
self.client.login(username='staff_user', password='x')

# freeze competition2, so we can get anticipatable results
competition1 = Competition.objects.filter(status='open').first()
competition2 = Competition.objects.exclude(id=competition1.id).get()
competition2.freeze()

# generate some matches so we have replays to delete...
for x in range(NUM_MATCHES): # 12 = two rounds
response = self._post_to_matches()
Expand Down
5 changes: 4 additions & 1 deletion aiarena/frontend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ class MapPoolAdmin(admin.ModelAdmin):
@admin.register(Competition)
class CompetitionAdmin(admin.ModelAdmin):
list_display = (
'name',
'id',
'name',
'type',
'game_mode',
'date_created',
'date_opened',
'date_closed',
'status',
'max_active_rounds',
)
list_filter = (
'date_created',
Expand Down
6 changes: 3 additions & 3 deletions aiarena/frontend/templates/competition.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load i18n %}
{% load i18n core_filters %}

{% block content %}

Expand Down Expand Up @@ -70,7 +70,7 @@
{% endif %}
<td>
{{ participant.elo }}
{% with trend=participant.bot.current_elo_trend %}
{% bot_competition_trend participant.bot competition as trend %}
{% if trend > 40 %}
<em class="material-icons" style="padding: 0; margin:0; vertical-align: -0.3em; transform: rotate(-90deg);" title="ELO gained {{trend}} in the last 30 games">
trending_flat
Expand All @@ -92,7 +92,7 @@
trending_flat
</em>
{% endif %}
{% endwith %}</td>
</td>
<td><a href="{% url 'bot_competition_stats' participant.id participant.slug %}">Stats</a></td>

</tr>
Expand Down
5 changes: 5 additions & 0 deletions aiarena/frontend/templatetags/core_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ def shorten_naturaltime(naturaltime):
.replace(' years', 'y').replace(' year', 'y'))


def bot_competition_trend(bot, competition):
return bot.current_elo_trend(competition)


register = template.Library()
register.filter('pretty_bool', pretty_bool)
register.filter('format_elo_change', format_elo_change)
register.filter('smooth_timedelta', smooth_timedelta)
register.filter('cents_to_usd', cents_to_usd)
register.filter('step_time_color', step_time_color)
register.filter('shorten_naturaltime', shorten_naturaltime)
register.simple_tag(bot_competition_trend, name='bot_competition_trend')
7 changes: 4 additions & 3 deletions aiarena/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,13 @@ def get_context_data(self, **kwargs):
.order_by('-created'))
result_filter = RelativeResultFilter(self.request.GET, queryset=results_qs, user=self.request.user)
result_table = BotResultTable(data=result_filter.qs, user=self.request.user)
result_table.exclude = []
# Exclude log column if not staff or user
if not (self.request.user == self.object.user or self.request.user.is_staff):
result_table.exclude = ("match_log",)
result_table.exclude.append("match_log")
# Exclude tags column if anonymous user
if not self.request.user.is_authenticated:
result_table.exclude = ("match__tags",)
result_table.exclude.append("match__tags")
# Update table based on request information
RequestConfig(self.request, paginate={"per_page": 30}).configure(result_table)
context['results_table'] = result_table
Expand All @@ -394,7 +395,7 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['competition_bot_matchups'] = self.object.competition_matchup_stats.filter(
opponent__competition=context['competitionparticipation'].competition).order_by('-win_perc').distinct()
context['updated'] = context['competition_bot_matchups'][0].updated
context['updated'] = context['competition_bot_matchups'][0].updated if context['competition_bot_matchups'] else "Never"
return context


Expand Down

0 comments on commit 0976b75

Please sign in to comment.