the racalc cronjob reports erronous partly recalculations now. A lot of code cleanups
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Recalculate Mahjong Rankings...
|
|
"""
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from mahjong_ranking import LOGGER
|
|
from mahjong_ranking import models
|
|
|
|
|
|
class Command(BaseCommand):
|
|
""" Recalculate all Kyu/Dan Rankings """
|
|
|
|
help = "Recalculate all Kyu/Dan Rankings"
|
|
|
|
def handle(self, *args, **options):
|
|
old_attr = {'dan': None, 'dan_points': None,
|
|
'kyu': None, 'kyu_points': None, 'won_hanchans': None,
|
|
'good_hanchans': None, 'hanchan_count': None}
|
|
for ranking in models.KyuDanRanking.objects.all():
|
|
old_attr = {attr: getattr(ranking, attr) for attr in old_attr.keys()}
|
|
ranking.recalculate()
|
|
for attr, old_value in old_attr.items():
|
|
if getattr(ranking, attr) != old_value:
|
|
LOGGER.warning(
|
|
"%(user)s recalc shows differences in %(attr)s! old: %(old)d, new: %(new)d",
|
|
{'user': ranking.user, 'attr': attr,
|
|
'old': old_value, 'new': getattr(ranking, attr)}
|
|
)
|