Skip to content

Commit

Permalink
Allow for recalculating ladder data and add build detection support. (S…
Browse files Browse the repository at this point in the history
…TOCD#21)

* Added advanced lookups for ladder data.

* Added advanced filtering on Player, Ladder Name, Ladder Difficulty

* Added support for OSCR 2024.3b40

* Included type hint for rank field to fix bug in generated client.

* Fixed typo in Jupiter Station Showdown

* Updated to add support for build field.

* Updated requirements.
  • Loading branch information
Kraust authored Mar 16, 2024
1 parent c763cb1 commit 86b3e6c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
1 change: 0 additions & 1 deletion .env-server

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ client
media
staticfiles
.vercel
.env
17 changes: 17 additions & 0 deletions combatlog/management/commands/recalc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logging

from combatlog.models import CombatLog
from django.core.management.base import BaseCommand

LOGGER = logging.getLogger("django")


class Command(BaseCommand):
help = "Recalculates Combat Log Metadata"

def handle(self, *args, **options):
for combatlog in CombatLog.objects.all():
try:
combatlog.update_metadata_from_remote()
except Exception as e:
LOGGER.info(f"{e}: {combatlog}")
34 changes: 27 additions & 7 deletions combatlog/models/combatlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ class CombatLog(BaseModel):

name = models.TextField(null=True, default=None)

def update_metadata_file(self, file):
def update_metadata_from_remote(self):
"""Updates Metadata from remote storage"""
data = self.get_data()
if data:
self.update_metadata(data, force_update=True)

def update_metadata_file(self, file, force_update=False):
"""Update Metadata from a file"""

results = []
Expand Down Expand Up @@ -131,6 +137,13 @@ def update_metadata_file(self, file):
"detail": f"No updates for {full_name} on {ladder}",
"value": player.get(ladder.metric),
}
if force_update:
queryset.update(
player=full_name,
data=player,
combatlog=self,
ladder=ladder,
)

results.append(result)

Expand All @@ -140,6 +153,12 @@ def update_metadata_file(self, file):
updated += 1

if updated == 0:
if self.metadata:
self.metadata.summary = players
self.metadata.save()
self.save()
if force_update:
return
raise APIException("There are no new records in this combat log.")

with transaction.atomic():
Expand All @@ -158,18 +177,14 @@ def update_metadata_file(self, file):

return results

def update_metadata(self, data):
def update_metadata(self, data, force_update=True):
"""Parse the Combat Log and create Metadata"""

with tempfile.NamedTemporaryFile() as file:
file.write(data)
file.flush()
res = self.update_metadata_file(file)

try:
res = self.update_metadata_file(file, force_update=force_update)
self.put_data(data)
except Exception as e:
LOGGER.info(f"Failed to upload data to blob storage: {e}")

return res

Expand All @@ -191,6 +206,8 @@ def put_data(self, data):

def get_data(self):
"""Fetch the Combat Log data"""
if self.get_data_download_path() is None:
return b""
if not settings.ENABLE_DEBUG:
return requests.get(self.get_data_download_path()).content
return b""
Expand All @@ -209,3 +226,6 @@ def combat_log_post_delete(sender, instance, **kwargs):

if instance.metadata:
instance.metadata.delete()

if instance.get_data_download_path():
blob.delete(instance.get_data_download_path(), options={"debug": False})
2 changes: 1 addition & 1 deletion ladder/fixtures/ladders.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"model": "ladder.Ladder",
"pk": 7,
"fields": {
"name": "Jupiter Station Shoadown",
"name": "Jupiter Station Showdown",
"difficulty": "Elite",
"metric": "DPS",
"is_solo": false,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Django==4.2.9
djangorestframework==3.14.0
drf_yasg==1.21.7
django_filter==23.5
STO-OSCR>=2024.3b40
STO-OSCR>=2024.3b162
whitenoise==6.6.0
psycopg[binary,pool]==3.1.18
vercel_storage>=0.0.1
Expand Down

1 comment on commit 86b3e6c

@vercel
Copy link

@vercel vercel bot commented on 86b3e6c Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.