2015-10-20 14:26:25 +00:00
|
|
|
# -*- coding: utf-8
|
|
|
|
"""
|
|
|
|
Duck level calculations
|
|
|
|
"""
|
|
|
|
|
2015-01-16 14:38:59 +00:00
|
|
|
from django.conf import settings
|
|
|
|
import math
|
|
|
|
|
|
|
|
def level_to_up_minutes(level):
|
2015-10-20 14:26:25 +00:00
|
|
|
"""
|
|
|
|
Convert duck level to up minutes
|
|
|
|
"""
|
|
|
|
|
2015-01-16 14:38:59 +00:00
|
|
|
if level == 0:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
return 2 * pow(10, level)
|
|
|
|
|
|
|
|
def level_to_down_minutes(level):
|
2015-10-20 14:26:25 +00:00
|
|
|
"""
|
|
|
|
Convert duck level to down minutes
|
|
|
|
"""
|
|
|
|
|
2015-01-16 14:38:59 +00:00
|
|
|
if level == 0:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
return 20 * pow(10, level)
|
|
|
|
|
|
|
|
def minutes_to_level(up_minutes, down_minutes):
|
2015-10-20 14:26:25 +00:00
|
|
|
"""
|
|
|
|
Convert booking minutes to duck level
|
|
|
|
"""
|
2015-01-16 14:38:59 +00:00
|
|
|
minutes = up_minutes + down_minutes / 10
|
|
|
|
level = 0 if minutes <= 0 else min(settings.MAX_DUCK_LEVEL, math.floor(math.log10(minutes)))
|
|
|
|
|
|
|
|
return level
|