rework noita objectives + deathcounter

This commit is contained in:
2026-05-15 01:50:34 +02:00
parent 754b0b0803
commit 7cfab20826
14 changed files with 481 additions and 167 deletions
+33 -18
View File
@@ -1,22 +1,21 @@
from noita.models import LogfileSubmission, Objectiv
from noita.models import LogfileSubmission, Objectiv, DeathCounter
from noita.services.decode import parse_log, resolve
from collections import Counter
def parse_objectives_from_logfile(logfile: LogfileSubmission) -> Counter:
def parse_objectives_from_logfile(
logfile: LogfileSubmission,
) -> list[tuple[str, str, str]]:
"""Parse a log file, and output a count for each ID."""
file_data = logfile.file.read().decode()
ids = []
entries: list[tuple[str, str, str]] = []
for entry in parse_log(file_data):
idx, _seed = resolve(entry["hash"], entry["ts"])
idx, seed = resolve(entry["hash"], entry["ts"])
if idx:
ids.append(idx)
if idx and seed:
entries.append((idx, str(seed), entry["ts"]))
return Counter(ids)
return entries
def parse_objectives_and_store(logfile: LogfileSubmission) -> None:
@@ -25,16 +24,32 @@ def parse_objectives_and_store(logfile: LogfileSubmission) -> None:
if not logfile.user:
return
counter = parse_objectives_from_logfile(logfile)
for idx, count in counter.items():
objectives = []
deaths = []
for idx, seed, ts in parse_objectives_from_logfile(logfile):
print(idx, seed, ts)
if idx in {"-", "DEBUG", "polylan-mod"}:
continue
obj, created = Objectiv.objects.get_or_create(
objectiv_id=idx,
user=logfile.user,
if idx == "DEATH":
deaths.append(DeathCounter(user=logfile.user, seed=seed, seen_at=ts))
continue
objectives.append(
Objectiv(
objectiv_id=idx,
user=logfile.user,
first_seen_at=ts,
seed=seed,
submission=logfile,
)
)
obj.count += count
obj.save(update_fields=["count"])
Objectiv.objects.bulk_create(
objectives,
update_conflicts=True,
update_fields=["seed", "submission"],
unique_fields=["objectiv_id", "user", "first_seen_at"],
)
DeathCounter.objects.bulk_create(deaths, ignore_conflicts=True)