# -*- encoding: utf-8 -*-
from django.core.cache import cache
from django.conf import settings
import logging

DAN_RANKS_DICT = dict([(dan, points) for points, dan in settings.DAN_RANKS])

LOGGER = logging.getLogger('kasu.mahjong_ranking')


def set_dirty(event=None, season=None, user=None, hanchan_date=None):
    key_to_add = None
    queue_name = 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, hanchan_date)
        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)
