# -*- encoding: utf-8 -*-
from django.utils.log import getLogger
from django.core.cache import cache

KYU_RANKS = (
    (45, 1),
    (40, 2),
    (35, 3),
    (30, 4),
    (25, 5),
    (20, 6),
    (15, 7),
    (10, 8),
    (5, 9),
    (0, 10),
)

DAN_RANKS = (
    (80, 9),
    (70, 8),
    (60, 7),
    (50, 6),
    (40, 5),
    (30, 4),
    (20, 3),
    (10, 2),
    (0, 1),
)

DAN_RANKS_DICT = dict([(dan, points) for points, dan in DAN_RANKS])
MIN_HANCHANS_FOR_LADDER = 5

logger = getLogger('kasu.mahjong_ranking')


def set_dirty(event=None, season=None, user=None):
    if season and user:
        key_to_add = (season, user)
        queue_name = 'ladder_ranking_queue'
    elif season:
        key_to_add = season
        queue_name = 'ladder_season_queue'
    elif event and user:
        key_to_add = (event, user)
        queue_name = 'event_ranking_queue'
    elif user:
        key_to_add = user
        queue_name = 'kyu_dan_ranking_queue'
    if key_to_add and queue_name:
        recalculation_queue = cache.get(queue_name, set())
        recalculation_queue.add(key_to_add)
        cache.set(queue_name, recalculation_queue, 360)
