From f5cf3ac368a6a2ddf9ae6c3d0167fdd342981a00 Mon Sep 17 00:00:00 2001
From: Sebastian Lohff
Date: Sat, 28 Jan 2017 18:39:00 +0100
Subject: [PATCH] Calculate points
---
TODO | 2 +-
contest/models.py | 33 +++++++++++++++++++++++++++++
templates/contest/viewUserQSOs.html | 5 ++++-
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/TODO b/TODO
index e872283..3495d2e 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,3 @@
- - calculate "claimed points"
- listviews mit pagination evaluieren
- top overview mit claimed und real score
- check QSO checking, not both sides get linked to each other
@@ -31,6 +30,7 @@
- registered datum, name und "genauer standort" für benutzer und shadowbenutzer?
- copy data automatically from shadow users to registered users
- add times to contest
+ - calculate "claimed points"
Glaube nich, dass ich das mache
- call dupe validation könnte ins model wandern
diff --git a/contest/models.py b/contest/models.py
index 8598af7..30319e8 100644
--- a/contest/models.py
+++ b/contest/models.py
@@ -67,6 +67,39 @@ class User(AbstractUser):
def getCfmdRefCount(self):
return len(set(map(lambda _x: _x["refStr"], self.qso_set.filter(ref__isnull=False).values("ref", "refStr"))))
+
+ def calcClaimedPoints(self):
+ return self.calcPoints(cfmd=False)
+
+ def calcCfmdPoints(self):
+ return self.calcPoints(cfmd=True)
+
+ def calcPoints(self, cfmd):
+ contest = Contest.objects.get(id=1)
+
+ result = {"refCount": 0, "qsoCount": 0}
+ for band in contest.band_set.all():
+ result[band.name] = self.calcBandPoints(band, cfmd)
+ result["refCount"] += result[band.name]["refCount"]
+ result["qsoCount"] += result[band.name]["qsoCount"]
+
+ result["points"] = result["qsoCount"] * result["refCount"]
+
+ return result
+
+ def calcBandPoints(self, band, cfmd=False):
+ contest = band.contest
+ qsos = self.qso_set.filter(band=band, time__gte=contest.qsoStartTime, time__lte=contest.qsoEndTime)
+ if cfmd:
+ qsos = qsos.filter(cfmdQSO__isnull=False)
+ refs = set(map(lambda _x: _x["refStr"], qsos.values("refStr")))
+
+ return {
+ "band": band,
+ "refs": refs,
+ "qsoCount": qsos.count(),
+ "refCount": len(refs)
+ }
signals.post_save.connect(checkForShadowCall, sender=User)
class Band(models.Model):
diff --git a/templates/contest/viewUserQSOs.html b/templates/contest/viewUserQSOs.html
index 1745716..f898909 100644
--- a/templates/contest/viewUserQSOs.html
+++ b/templates/contest/viewUserQSOs.html
@@ -12,7 +12,10 @@
{{ owner }} {% if owner.ref %}is registeret at {{ owner.ref }}{% else %}has not registered an exchange{% endif %} and {% if owner.cat %}is in category {{ owner.cat }}{% else %}has not selected a category{% endif %}.
- {{ owner }} has {{ owner.getQSOCount }} QSO{{ owner.getQSOCount|pluralize }}, {{ owner.getCfmdQSOCount }} confirmed QSO{{ owner.getCfmdQSOCount|pluralize }} and worked the following {{ userRefs|length }} exchange{{ userRefs|length|pluralize }}: {{ userRefs|join:", " }}.
+ {% with claimed=owner.calcClaimedPoints cfmd=owner.calcCfmdPoints %}
+ Claimed: Score with {{ claimed.qsoCount}} QSO{{ claimed.qsoCount|pluralize }} * {{ claimed.refCount }} EXC{{ claimed.refCount|pluralize }} = {{ claimed.points }};
+ Cfmd: Score with {{ cfmd.qsoCount}} QSO{{ cfmd.qsoCount|pluralize }} * {{ cfmd.refCount }} EXC{{ cfmd.refCount|pluralize }} = {{ cfmd.points }}
+ {% endwith %}
{% include "contest/qsoAdminTable.html" with qsoPage=qsoPage qsoPager=qsoPager %}