Files @ 0a3d8c06e5b3
Branch filter:

Location: Rank-Progress/rank_progress.py - annotation

Laman
a hgignore
import re
from itertools import groupby
from datetime import datetime
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("since", help="a date in YYYYMMDD format")
parser.add_argument("to", nargs="?", help="a date in YYYYMMDD format")
parser.add_argument("-c", "--country-code", default="CZ", help="a two letter country code, default=CZ")

args = parser.parse_args()


def parse_record(record):
	types = [int, str, str, str, str, str, int, int, int, int]
	columns = [f(token) for (f, token) in zip(types, record)] + [datetime.strptime(record[5][1:7], "%y%m%d")]
	return tuple(columns)


def round_rating(r):
	return (r+50)//100*100


since = datetime.strptime(args.since, "%Y%m%d")
to = datetime.strptime(args.to, "%Y%m%d") if args.to else datetime.now()

with open("/tmp/all.hst") as f:
	s = f.read()

records = [re.split(r" {2,}", line.strip()) for line in s.splitlines()]
records = filter(lambda rec: len(rec) == 10, records)
records = map(parse_record, records)
national_records = filter(lambda rec: rec[2] == args.country_code, records)
players = groupby(national_records, lambda rec: rec[0])

for (pin, recs) in players:
	tourneys = list(recs)
	rounded_rating = round_rating(tourneys[0][9])

	steps = []

	for r in tourneys:
		if rounded_rating != round_rating(r[8]):
			rounded_rating = round_rating(r[8])

		if r[9]-rounded_rating >= 50 or rounded_rating-r[9] > 100:
			steps.append(r)
			rounded_rating = round_rating(r[9])

	steps = [r for r in steps if since <= r[10] <= to]
	if steps:
		print(steps)