duck-booking-tool/booking/ducklevel.py

37 lines
678 B
Python
Raw Normal View History

2015-10-20 14:26:25 +00:00
# -*- coding: utf-8
"""
Duck level calculations
"""
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
"""
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
"""
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
"""
minutes = up_minutes + down_minutes / 10
level = 0 if minutes <= 0 else min(settings.MAX_DUCK_LEVEL, math.floor(math.log10(minutes)))
return level