Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
lladdy committed Sep 22, 2020
2 parents 591cc7b + 731ff1f commit ebec5f1
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 101 deletions.
31 changes: 16 additions & 15 deletions aiarena/core/migrations/0107_auto_20200622_1841.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ class Migration(migrations.Migration):
]

operations = [
migrations.AddField(
model_name='bot',
name='is_probots_participant',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='bot',
name='probots_bot_data',
field=private_storage.fields.PrivateFileField(blank=True, null=True, storage=aiarena.core.storage.OverwritePrivateStorage(base_url='/'), upload_to=aiarena.core.models.bot.probots_bot_data_upload_to),
),
migrations.AddField(
model_name='bot',
name='probots_bot_zip',
field=private_storage.fields.PrivateFileField(blank=True, null=True, storage=aiarena.core.storage.OverwritePrivateStorage(base_url='/'), upload_to=aiarena.core.models.bot.probots_bot_zip_upload_to, validators=[aiarena.core.validators.validate_bot_zip_file]),
),
# Broken migrations - field removed
# migrations.AddField(
# model_name='bot',
# name='is_probots_participant',
# field=models.BooleanField(default=False),
# ),
# migrations.AddField(
# model_name='bot',
# name='probots_bot_data',
# field=private_storage.fields.PrivateFileField(blank=True, null=True, storage=aiarena.core.storage.OverwritePrivateStorage(base_url='/'), upload_to=aiarena.core.models.bot.probots_bot_data_upload_to),
# ),
# migrations.AddField(
# model_name='bot',
# name='probots_bot_zip',
# field=private_storage.fields.PrivateFileField(blank=True, null=True, storage=aiarena.core.storage.OverwritePrivateStorage(base_url='/'), upload_to=aiarena.core.models.bot.probots_bot_zip_upload_to, validators=[aiarena.core.validators.validate_bot_zip_file]),
# ),
]
11 changes: 6 additions & 5 deletions aiarena/core/migrations/0110_bot_probots_bot_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class Migration(migrations.Migration):
]

operations = [
migrations.AddField(
model_name='bot',
name='probots_bot_source',
field=private_storage.fields.PrivateFileField(blank=True, null=True, storage=aiarena.core.storage.OverwritePrivateStorage(base_url='/'), upload_to=aiarena.core.models.bot.probots_bot_source_upload_to),
),
# Broken migration - field removed
# migrations.AddField(
# model_name='bot',
# name='probots_bot_source',
# field=private_storage.fields.PrivateFileField(blank=True, null=True, storage=aiarena.core.storage.OverwritePrivateStorage(base_url='/'), upload_to=aiarena.core.models.bot.probots_bot_source_upload_to),
# ),
]
25 changes: 0 additions & 25 deletions aiarena/core/models/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ def bot_data_upload_to(instance, filename):
return '/'.join(['bots', str(instance.id), 'bot_data'])


def probots_bot_zip_upload_to(instance, filename):
return '/'.join(['bots', str(instance.id), 'probots', 'bot_zip_' + timezone.now().strftime("%Y%m%d_%H%M%S")])


def probots_bot_source_upload_to(instance, filename):
return '/'.join(['bots', str(instance.id), 'probots', 'bot_source_' + timezone.now().strftime("%Y%m%d_%H%M%S")])


def probots_bot_data_upload_to(instance, filename):
return '/'.join(['bots', str(instance.id), 'probots', 'bot_data_' + timezone.now().strftime("%Y%m%d_%H%M%S")])


class Bot(models.Model, LockableModelMixin):
RACES = (
('T', 'Terran'),
Expand Down Expand Up @@ -86,19 +74,6 @@ 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)

# probots
is_probots_participant = models.BooleanField(default=False)
probots_bot_zip = PrivateFileField(upload_to=probots_bot_zip_upload_to,
storage=HardcodedURLFilenamePrivateStorage(url_filename='bot_zip', base_url='/'),
validators=[validate_bot_zip_file, ], blank=True, null=True)
probots_bot_source = PrivateFileField(upload_to=probots_bot_source_upload_to,
storage=HardcodedURLFilenamePrivateStorage(url_filename='bot_source',
base_url='/'), blank=True,
null=True)
probots_bot_data = PrivateFileField(upload_to=probots_bot_data_upload_to,
storage=HardcodedURLFilenamePrivateStorage(url_filename='bot_data',
base_url='/'), blank=True, null=True)

@property
def current_matches(self):
return Match.objects.only('id').filter(matchparticipation__bot=self, started__isnull=False, result__isnull=True)
Expand Down
5 changes: 3 additions & 2 deletions aiarena/core/stats/stats_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ def _get_data(bot_id):
""")
cursor.execute(query)
elo_over_time = pd.DataFrame(cursor.fetchall())
elo_over_time.to_csv('tmp.csv')
elo_over_time = pd.read_csv('tmp.csv')
# HACK - saving to a csv and loading it back normalizes the time format
elo_over_time.to_csv('./tmp/tmp.csv')
elo_over_time = pd.read_csv('./tmp/tmp.csv')
elo_over_time = elo_over_time.drop('Unnamed: 0', axis=1)
return elo_over_time

Expand Down
16 changes: 0 additions & 16 deletions aiarena/frontend/templates/bot_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ <h3>Melee Ladder</h3>
<p>Bot data:<br/>
{{ form.bot_data }}<br/>
Publicly downloadable: {{ form.bot_data_publicly_downloadable }}</p>
{% if object.is_probots_participant %}
{% if config.PROBOTS_SUBMISSION_DEADLINE < now %}
<h4>ProBots submissions are currently closed.</h4>
{% else %}
<h3>ProBots</h3>
<h4>Next ProBots submission
deadline: {{ config.PROBOTS_SUBMISSION_DEADLINE|date:"d. N Y - H:i:s" }}
UTC</h4>
<p>Probots bot zip:<br/>
{{ form.probots_bot_zip }}</p>
<p>Probots bot source/change log zip:<br/>
{{ form.probots_bot_source }}</p>
<p>Probots bot data zip:<br/>
{{ form.probots_bot_data }}</p>
{% endif %}
{% endif %}
<h3>Bot page content</h3>
<p>
{{ form.wiki_article_content }}
Expand Down
34 changes: 1 addition & 33 deletions aiarena/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,10 @@ def __init__(self, *args, **kwargs, ):
self.fields['active'].required = False


if not self.instance.is_probots_participant:
# don't show these fields to non-probots participants
del self.fields['probots_bot_zip']
del self.fields['probots_bot_source']
del self.fields['probots_bot_data']


class Meta:
model = Bot
fields = ['active', 'bot_zip', 'bot_zip_publicly_downloadable', 'bot_data',
'bot_data_publicly_downloadable', 'probots_bot_zip', 'probots_bot_source', 'probots_bot_data']
'bot_data_publicly_downloadable']


class BotUpdate(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
Expand Down Expand Up @@ -442,31 +435,6 @@ def can_access_file(self, private_file):
return user.is_authenticated and user.is_staff or private_file.parent_object.user == user or private_file.parent_object.bot_data_publicly_downloadable


class ProbotsFileDownloadView(PrivateStorageDetailView):
model = Bot

content_disposition = 'attachment'

def get_content_disposition_filename(self, private_file):
return 'probots_{0}.zip'.format(private_file.relative_name.split('/')[-1])

def can_access_file(self, private_file):
user = private_file.request.user
# Allow if staff, the owner of the file, or the file is marked as publicly downloadable
return user.is_authenticated and user.is_staff or private_file.parent_object.user == user or private_file.parent_object.bot_data_publicly_downloadable

class ProbotsZipDownloadView(ProbotsFileDownloadView):
model_file_field = 'probots_bot_zip'


class ProbotsSourceDownloadView(ProbotsFileDownloadView):
model_file_field = 'probots_bot_source'


class ProbotsDataDownloadView(ProbotsFileDownloadView):
model_file_field = 'probots_bot_data'


class MatchLogDownloadView(PrivateStorageDetailView):
model = MatchParticipation
model_file_field = 'match_log'
Expand Down
2 changes: 0 additions & 2 deletions aiarena/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@
'1/(1+e^(-AVG_BOT_ELO/COMBINED_ELO_RATING_DIVISOR))-0.5'),
'ENABLE_ELO_SANITY_CHECK': (True, 'Whether to sanity check the total sum of bot ELO '
'on result submission in order to detect ELO corruption.'),
'PROBOTS_SUBMISSION_DEADLINE': (datetime.datetime.now(), 'The next ProBots submission deadline datetime.'),
'BOT_UPLOADS_ENABLED': (True, 'Whether authors can upload new bots to the website.'),
}

Expand All @@ -223,7 +222,6 @@
'BOT_CONSECUTIVE_CRASH_LIMIT', 'REISSUE_UNFINISHED_MATCHES',),
'Integrations': ('DISCORD_CLIENT_ID', 'DISCORD_CLIENT_SECRET', 'PATREON_CLIENT_ID', 'PATREON_CLIENT_SECRET',),
'Match interest analysis': ('ELO_DIFF_RATING_MODIFIER', 'COMBINED_ELO_RATING_DIVISOR',),
'ProBots': ('PROBOTS_SUBMISSION_DEADLINE',),
}

LOGGING = {
Expand Down
3 changes: 0 additions & 3 deletions aiarena/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@
path('bots/<int:pk>/edit/', core_views.BotUpdate.as_view(), name='bot_edit'),
path('bots/<int:pk>/bot_zip', core_views.BotZipDownloadView.as_view()),
path('bots/<int:pk>/bot_data', core_views.BotDataDownloadView.as_view()),
path('bots/<int:pk>/probots/bot_zip', core_views.ProbotsZipDownloadView.as_view()),
path('bots/<int:pk>/probots/bot_source', core_views.ProbotsSourceDownloadView.as_view()),
path('bots/<int:pk>/probots/bot_data', core_views.ProbotsDataDownloadView.as_view()),

path('match-logs/<int:pk>/', core_views.MatchLogDownloadView.as_view()),
path('authors/', core_views.AuthorList.as_view(), name='authors'),
Expand Down

0 comments on commit ebec5f1

Please sign in to comment.