from gm_types.gaia import USER_RIGHTS_LEVEL
from django.conf import settings

__doc__ = """用户成长值相关处理；
    tips：首先计算用户得分，同步level表，level变化后，触发回调
"""


def get_level_by_value(value):
    if value < settings.LEVEL_START_VALUE[USER_RIGHTS_LEVEL.V2]:
        return USER_RIGHTS_LEVEL.V1

    elif value < settings.LEVEL_START_VALUE[USER_RIGHTS_LEVEL.V3]:
        return USER_RIGHTS_LEVEL.V2

    elif value < settings.LEVEL_START_VALUE[USER_RIGHTS_LEVEL.V4]:
        return USER_RIGHTS_LEVEL.V3

    elif value < settings.LEVEL_START_VALUE[USER_RIGHTS_LEVEL.V5]:
        return USER_RIGHTS_LEVEL.V4

    elif value < settings.LEVEL_START_VALUE[USER_RIGHTS_LEVEL.V6]:
        return USER_RIGHTS_LEVEL.V5

    elif value < settings.LEVEL_START_VALUE[USER_RIGHTS_LEVEL.V7]:
        return USER_RIGHTS_LEVEL.V6

    else:
        return USER_RIGHTS_LEVEL.V7


