Another Step in the Quest to clean up the code base.

This commit is contained in:
2017-09-08 07:19:50 +02:00
parent ce218080b2
commit b3ab9798b5
229 changed files with 1915 additions and 15175 deletions

View File

@@ -0,0 +1,42 @@
"""Export Mahjong Rankings as excel files."""
from operator import itemgetter
from django.core.management.base import BaseCommand
from openpyxl import Workbook
from mahjong_ranking.models import SeasonRanking
def geneate_seasonexcel(json_data):
"""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',
'⌀ Platz', '⌀ Punkte',
'Hanchans', 'Gut', 'Gewonnen'
])
json_data = sorted(json_data, key=itemgetter('placement'))
for row in json_data:
worksheet.append([
row['placement'], row['username'],
row['avg_placement'], row['avg_score'],
row['hanchan_count'],
row['good_hanchans'], row['won_hanchans']
])
workbook.save("sample.xlsx")
class Command(BaseCommand):
"""Exports the SeasonRankings"""
def handle(self, *args, **options):
"""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())