Skip to content

Commit

Permalink
Scaffolding for New Combat Time Requirements (#97)
Browse files Browse the repository at this point in the history
* Added Support for Winter Invasion

* Added new Combat Time Threshold Logic

* Set Second Between Combats to 60s to reduce false positives.

* Fixed Damage Out Parsing.
  • Loading branch information
Kraust authored Jan 7, 2025
1 parent 6a5d02b commit 7d8353b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
37 changes: 16 additions & 21 deletions combatlog/models/combatlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ def update_metadata_file(self, file, force=False):
results = []

parser_settings = {
'combats_to_parse': 1,
'seconds_between_combats': 100,
'graph_resolution': 2.0, # could probably use even greater resolution to save memory
"combats_to_parse": 1,
"seconds_between_combats": 60,
"graph_resolution": 2.0, # could probably use even greater resolution to save memory
}

parser = OSCR.OSCR(log_path=file.name, settings=parser_settings)
parser.analyze_log_file(max_combats=1)
try:
combat = parser.combats[0]
except IndexError:
raise APIException('Combat log is empty')
raise APIException("Combat log is empty")
damage_out = self.tree_to_dict(combat.damage_out._root)

players = {}
Expand All @@ -148,12 +148,6 @@ def update_metadata_file(self, file, force=False):
if len(players) == 0:
raise APIException("Combat log is empty")

# TBD: We use 0.9 combat time until a better choice can be made.
# +++ ADDED +++
# combat.meta['log_duration']
# combat.meta['player_duration']
combat_time = players[0][1]["combat_time"] * 0.90

# Check to see if map / difficulty combination exists in the ladder
# table. if it does, iterate over each player to see if they have a
# higher key. If any of them do, allow uploading of the log and
Expand Down Expand Up @@ -202,21 +196,22 @@ def update_metadata_file(self, file, force=False):

for _, player in players:
full_name = f"{player['name']}{player['handle']}"
if player["combat_time"] < combat_time:
results.append(
{
"name": full_name,
"updated": False,
"detail": f"{full_name}'s combat time was too low.",
"value": combat_time,
}
)
continue

for ladder in ladders:
if ladder.is_solo and len(players) != 1:
continue

combat_time = ladder.combat_time_threshold(combat, players)
if player["combat_time"] < combat_time:
results.append(
{
"name": full_name,
"updated": False,
"detail": f"{full_name}'s combat time was too low.",
"value": combat_time,
}
)
continue

if (
ladder.manual_review_threshold
and player.get(ladder.metric) > ladder.manual_review_threshold
Expand Down
23 changes: 23 additions & 0 deletions ladder/migrations/0004_variant_combat_time_source_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.9 on 2025-01-02 03:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("ladder", "0003_ladderentry_visible"),
]

operations = [
migrations.AddField(
model_name="variant",
name="combat_time_source",
field=models.TextField(default="combat_time"),
),
migrations.AddField(
model_name="variant",
name="combat_time_threshold",
field=models.FloatField(default=0.9),
),
]
17 changes: 16 additions & 1 deletion ladder/models/ladder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Ladder Models """
"""Ladder Models"""

import logging

Expand Down Expand Up @@ -26,6 +26,21 @@ class Ladder(BaseModel):

manual_review_threshold = models.IntegerField(default=0)

def combat_time_threshold(self, combat, players):
"""Fetch the combat time threshold based on the ladder."""
# "combat_time" is special and falls back to the original / broken
# combat time calculation.
if self.variant.combat_time_source == "combat_time":
return players[0][1]["combat_time"] * self.variant.combat_time_threshold

# Current possible values:
# - log_duration
# - player_duration
return (
combat.meta[self.variant.combat_time_source]
* self.variant.combat_time_threshold
)

def create_variant(self, variant):
"""Create variant of ladder"""
if not Ladder.objects.filter(
Expand Down
4 changes: 4 additions & 0 deletions ladder/models/variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ class Variant(BaseNameModel):
related_name="exclude_ground_variant_set",
)

# Support for configurable combat time source and threshold.
combat_time_source = models.TextField(default="combat_time")
combat_time_threshold = models.FloatField(default=0.90)

def __str__(self):
return f"{self.name} ({self.start_date} to {self.end_date})"

0 comments on commit 7d8353b

Please sign in to comment.