Skip to content

Commit

Permalink
Merge pull request #556 from aiarena/staging
Browse files Browse the repository at this point in the history
Release v1.10.3
  • Loading branch information
lladdy authored Feb 21, 2023
2 parents dbcdaaa + ef1629d commit b0da085
Show file tree
Hide file tree
Showing 29 changed files with 626 additions and 433 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

RUN apt-get update \
&& apt-get install -y gcc libmariadb-dev
&& apt-get install -y gcc

COPY . workspace

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Deploy Staging
uses: garygrossgarten/github-action-ssh@release
with:
command: cd /home/aiarena/ai-arena/ && git checkout staging && git pull origin staging && git submodule update --init --recursive && source venv/bin/activate && python3 ./pip/pip-install.py && python3 manage.py collectstatic --noinput && /home/aiarena/cleardb.sh && python3 manage.py migrate && python3 manage.py purgesensitivedata && sudo apachectl graceful && pw=`cat ~/.redis` && redis-cli -a "$pw" -n 1 FLUSHDB && exit
command: cd /home/aiarena/ai-arena/ && git checkout staging && git pull origin staging && git submodule update --init --recursive && source venv/bin/activate && python3 ./pip/pip-install.py && python3 manage.py collectstatic --noinput && /home/aiarena/refreshdb.sh && python3 manage.py migrate && python3 manage.py purgesensitivedata && python3 manage.py repairbothashes && python3 manage.py cancelmatches --active && sudo apachectl graceful && pw=`cat ~/.redis` && redis-cli -a "$pw" -n 1 FLUSHDB && exit
host: ${{ secrets.STAGING_HOST }}
port: ${{ secrets.STAGING_PORT }}
username: ${{ secrets.STAGING_USERNAME }}
Expand Down
76 changes: 0 additions & 76 deletions .gitlab-ci.yml

This file was deleted.

15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
# aiarena-web
A website for running the aiarena.net ladder.
A website for running the aiarena.net infrastructure.

[See the live website here](https://aiarena.net/)

[Dev Install instructions](./doc/INSTALL.md)

## Module structure:
### aiarena/core
Core ladder/project functionality
Core project functionality

### aiarena/api
Web API endpoints and functionality
Web API endpoints and functionality.
This root api folder contains views for public use.

#### aiarena/api/arenaclient
API endpoints specifically for use by the arenaclients to obtain new matches and report results.

#### aiarena/api/stream
API endpoints specifically for use by the livestream player to obtain a curated list of match replays to feature.

### aiarena/frontend
Django template website frontend

### aiarena/patreon
A module for linking website users to their patreon counterparts.

## License

Expand Down
108 changes: 64 additions & 44 deletions aiarena/api/arenaclient/ac_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from typing import TYPE_CHECKING

from django.core.cache import cache
from django.dispatch import receiver

from aiarena.core.api.competitions import Competitions

if TYPE_CHECKING:
Expand All @@ -17,6 +20,7 @@
CompetitionPaused, CompetitionClosing
from aiarena.core.api import Matches
from aiarena.core.models import Match, Competition
from django.db.models.signals import pre_save

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -86,47 +90,63 @@ def _get_competition_priority_order():
In otherwords, campetitions with higher active participant counts should play more matches overall.
:return:
"""
with connection.cursor() as cursor:
# I don't know why but for some reason CTEs didn't work so here; have a massive query.
cursor.execute("""
select perc_active.competition_id
from (select competition_id,
competition_participations.competition_participations_cnt / cast(total_active_cnt as float) as perc_active
from (select cp.competition_id, count(cp.competition_id) competition_participations_cnt
from core_competitionparticipation cp
join core_competition cc on cp.competition_id = cc.id
where cp.active
and cc.status in ('open', 'closing', 'paused')
group by cp.competition_id) as competition_participations
join
(select count(*) total_active_cnt
from core_competitionparticipation cp
join core_competition cc on cp.competition_id = cc.id
where cp.active
and cc.status in ('open', 'closing', 'paused')) as competition_participations_total on 1=1) as perc_active
left join
(select competition_id, perc_recent_matches_cnt / cast(recent_matches_total_cnt as float) as perc_recent_matches
from (select competition_id,
count(competition_id) perc_recent_matches_cnt,
(select count(*)
from (select competition_id
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) matches2) recent_matches_total_cnt
from (select competition_id
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) matches
group by competition_id) as recent_matches) as perc_recent_matches
on perc_recent_matches.competition_id = perc_active.competition_id
order by COALESCE(perc_recent_matches, 0) - perc_active
""")
return [row[0] for row in cursor.fetchall()] # return competition ids

competition_priority_order = cache.get('competition_priority_order')
if not competition_priority_order:
with connection.cursor() as cursor:
# I don't know why but for some reason CTEs didn't work so here; have a massive query.
cursor.execute("""
select perc_active.competition_id
from (select competition_id,
competition_participations.competition_participations_cnt / cast(total_active_cnt as float) as perc_active
from (select cp.competition_id, count(cp.competition_id) competition_participations_cnt
from core_competitionparticipation cp
join core_competition cc on cp.competition_id = cc.id
where cp.active
and cc.status in ('open', 'closing', 'paused')
group by cp.competition_id) as competition_participations
join
(select count(*) total_active_cnt
from core_competitionparticipation cp
join core_competition cc on cp.competition_id = cc.id
where cp.active
and cc.status in ('open', 'closing', 'paused')) as competition_participations_total on 1=1) as perc_active
left join
(select competition_id, perc_recent_matches_cnt / cast(recent_matches_total_cnt as float) as perc_recent_matches
from (select competition_id,
count(competition_id) perc_recent_matches_cnt,
(select count(*)
from (select competition_id
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) matches2) recent_matches_total_cnt
from (select competition_id
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) matches
group by competition_id) as recent_matches) as perc_recent_matches
on perc_recent_matches.competition_id = perc_active.competition_id
order by COALESCE(perc_recent_matches, 0) - perc_active
""")
competition_priority_order = [row[0] for row in cursor.fetchall()] # return competition ids
cache.set('competition_priority_order', competition_priority_order,
config.COMPETITION_PRIORITY_ORDER_CACHE_TIME)

return competition_priority_order


@receiver(pre_save, sender=Competition)
def post_save_competition(sender, instance, **kwargs):
# if it's not a new instance...
if instance.id is not None:
previous = Competition.objects.get(id=instance.id)
if previous.status != instance.status and cache.has_key('competition_priority_order'):
cache.delete('competition_priority_order') # if the status changed, bust our competition_priority_order cache
Loading

0 comments on commit b0da085

Please sign in to comment.