Another Step in the Quest to clean up the code base.
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Export Mahjong Rankings...
|
||||
"""
|
||||
"""Export Mahjong Rankings as excel files."""
|
||||
|
||||
from operator import itemgetter
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from mahjong_ranking.models import SeasonRanking
|
||||
from openpyxl import Workbook
|
||||
|
||||
from mahjong_ranking.models import SeasonRanking
|
||||
|
||||
|
||||
def geneate_seasonexcel(json_data):
|
||||
wb = Workbook()
|
||||
worksheet = wb.active
|
||||
"""Generate an excel .xlsx spreadsheet from json data of the kyu/dan
|
||||
rankings.
|
||||
|
||||
:param json_data: The ladder ranking as JSON export."""
|
||||
workbook = Workbook()
|
||||
worksheet = workbook.active
|
||||
|
||||
worksheet.append([
|
||||
'Rang', 'Spitzname',
|
||||
@@ -20,7 +22,6 @@ def geneate_seasonexcel(json_data):
|
||||
'Hanchans', 'Gut', 'Gewonnen'
|
||||
])
|
||||
|
||||
json_data = json_data.values()
|
||||
json_data = sorted(json_data, key=itemgetter('placement'))
|
||||
for row in json_data:
|
||||
worksheet.append([
|
||||
@@ -29,13 +30,13 @@ def geneate_seasonexcel(json_data):
|
||||
row['hanchan_count'],
|
||||
row['good_hanchans'], row['won_hanchans']
|
||||
])
|
||||
wb.save("sample.xlsx")
|
||||
workbook.save("sample.xlsx")
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Exports the SeasonRankings"
|
||||
|
||||
"""Exports the SeasonRankings"""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
season_json = SeasonRanking.objects.json_data()
|
||||
geneate_seasonexcel(season_json)
|
||||
"""Exports the current ladder ranking in a spreadsheet.
|
||||
This is useful as a backup in form of a hardcopy."""
|
||||
geneate_seasonexcel(SeasonRanking.objects.json_data())
|
||||
@@ -9,7 +9,9 @@ from mahjong_ranking import models
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Recalculate all Rankings"
|
||||
""" Recalculate all Kyu/Dan Rankings """
|
||||
|
||||
help = "Recalculate all Kyu/Dan Rankings"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
for ranking in models.KyuDanRanking.objects.all():
|
||||
Reference in New Issue
Block a user