89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
import math
|
|
|
|
from people.models import Gymnast
|
|
from objectives.models import Skill
|
|
|
|
|
|
def suggest_routine(
|
|
request,
|
|
routine_length,
|
|
total_difficulty_score=None,
|
|
competition=True,
|
|
logic=True,
|
|
gymnast=None,
|
|
last_jump=None,
|
|
):
|
|
""" Construit et propose des séries.
|
|
|
|
Args:
|
|
routine_length (int): nombre de sauts que doit contenir la série.
|
|
total_difficulty_score (int): score de difficulté total souhaité de la série.
|
|
competition (bool): indique si la série doit pouvoir être utilisée en compétition.
|
|
logic (bool): indique si la série doit suivre certaines règles de logique (sportive).
|
|
gymnast (gymnast): gymnaste.
|
|
last_jump (skill): dernier saut sélectionné pour la série.
|
|
|
|
Returns:
|
|
??? (list): liste des séries correspondantes aux criètres.
|
|
"""
|
|
|
|
current_routine = []
|
|
|
|
if last_jump:
|
|
skill_list = Skill.objects.filter(
|
|
departure=last_jump.landing, difficulty__lte=total_difficulty_score
|
|
)
|
|
if logic and last_jump.landing == "Debout":
|
|
skill_list = skill_list.exclude(rotationType=last_jump.rotationType)
|
|
else:
|
|
skill_list = Skill.objects.filter(departure__longLabel="Debout")
|
|
|
|
if competition:
|
|
skill_list = skill_list.filter(is_competitive=True)
|
|
|
|
if logic and total_difficulty_score:
|
|
min_difficulty_score = math.ceil(max(0, ((total_difficulty_score / 10) - 5)))
|
|
|
|
if total_difficulty_score <= 65:
|
|
max_difficulty_score = math.ceil(total_difficulty_score / 5) + 1
|
|
elif total_difficulty_score <= 120:
|
|
max_difficulty_score = math.ceil(total_difficulty_score / 10) + 7
|
|
else:
|
|
max_difficulty_score = math.ceil(total_difficulty_score / 15) + 11
|
|
|
|
skill_list = skill_list.filter(
|
|
difficulty__gte=min_difficulty_score, difficulty__lte=max_difficulty_score
|
|
)
|
|
|
|
for skill in skill_list:
|
|
current_routine.append(skill)
|
|
current_routine.append(
|
|
self.suggest_routine(
|
|
request,
|
|
total_difficulty_score - skill.difficulty,
|
|
max_difficulty_score,
|
|
routine_length - 1,
|
|
competition,
|
|
logic,
|
|
gymnast,
|
|
skill,
|
|
)
|
|
)
|
|
current_routine.pop()
|
|
# def knapSack(W, wt, val, n):
|
|
# K = [[0 for x in range(W+1)] for x in range(n+1)]
|
|
# for i in range(n+1):
|
|
# for w in range(W+1):
|
|
# if i==0 or w==0:
|
|
# K[i][w] = 0
|
|
# elif wt[i-1] <= w:
|
|
# K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w])
|
|
# else:
|
|
# K[i][w] = K[i-1][w]
|
|
# return K[n][W]
|
|
# val = [60, 100, 120]
|
|
# wt = [10, 20, 30]
|
|
# W = 50
|
|
# n = len(val)
|
|
# print(knapSack(W, wt, val, n))
|