Calculate points

This commit is contained in:
Sebastian Lohff 2017-01-28 18:39:00 +01:00
parent 80900ecd21
commit f5cf3ac368
3 changed files with 38 additions and 2 deletions

2
TODO
View File

@ -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

View File

@ -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):

View File

@ -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 <em>{{ owner.cat }}</em>{% else %}has not selected a category{% endif %}.
</p>
<p>
{{ 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 %}
</p>
{% include "contest/qsoAdminTable.html" with qsoPage=qsoPage qsoPager=qsoPager %}
</div>