Spaces:
Sleeping
Sleeping
Commit
·
05c441e
1
Parent(s):
bd4e284
app.py
CHANGED
|
@@ -245,13 +245,13 @@ def detectar_objetivo(texto: str) -> str:
|
|
| 245 |
return "hipertrofia" # padrão se nada for detectado
|
| 246 |
|
| 247 |
|
| 248 |
-
def montar_treino(musculos_alvo, budget=45,
|
| 249 |
treino = []
|
| 250 |
custo_total = 0
|
| 251 |
usados = set()
|
| 252 |
musculos_cobertos = set()
|
| 253 |
|
| 254 |
-
# 1️⃣
|
| 255 |
faixas_reps = {
|
| 256 |
"hipertrofia": (6, 15),
|
| 257 |
"forca": (2, 5),
|
|
@@ -260,26 +260,25 @@ def montar_treino(musculos_alvo, budget=45, objetivo="hipertrofia"):
|
|
| 260 |
}
|
| 261 |
|
| 262 |
def escolher_reps(objetivo):
|
| 263 |
-
"""Escolhe reps dentro da faixa do objetivo"""
|
| 264 |
faixa = faixas_reps.get(objetivo, (8, 12))
|
| 265 |
return random.randint(*faixa)
|
| 266 |
|
| 267 |
-
def add_exercicio(ex, variacao, series):
|
| 268 |
nonlocal custo_total
|
| 269 |
custo_ex = variacao["custo"] * series
|
| 270 |
-
reps = escolher_reps(
|
| 271 |
|
| 272 |
if ex["nome"] in usados:
|
| 273 |
return False
|
| 274 |
if custo_total + custo_ex <= budget:
|
| 275 |
|
| 276 |
descricao_final = variacao["descricao"]
|
| 277 |
-
#
|
| 278 |
-
if
|
| 279 |
if ex.get("equipamento") == "peso_livre":
|
| 280 |
descricao_final += " (executar com carga moderada e máxima velocidade)"
|
| 281 |
else:
|
| 282 |
-
return False # descarta máquinas, elásticos etc.
|
| 283 |
|
| 284 |
treino.append({
|
| 285 |
"nome": ex["nome"],
|
|
@@ -288,7 +287,8 @@ def montar_treino(musculos_alvo, budget=45, objetivo="hipertrofia"):
|
|
| 288 |
"reps": reps,
|
| 289 |
"custo_total": custo_ex,
|
| 290 |
"custo_unit": variacao["custo"],
|
| 291 |
-
"video": variacao["video"]
|
|
|
|
| 292 |
})
|
| 293 |
custo_total += custo_ex
|
| 294 |
usados.add(ex["nome"])
|
|
@@ -296,19 +296,12 @@ def montar_treino(musculos_alvo, budget=45, objetivo="hipertrofia"):
|
|
| 296 |
return True
|
| 297 |
return False
|
| 298 |
|
| 299 |
-
# 2️⃣
|
| 300 |
candidatos_multi = []
|
| 301 |
for ex in exercicios_db:
|
| 302 |
if any(m in ex["musculos"] for m in musculos_alvo):
|
| 303 |
for v in ex["variacoes"]:
|
| 304 |
if v["custo"] == 5:
|
| 305 |
-
# Se for explosividade, só aceita pliométrico
|
| 306 |
-
if objetivo == "explosividade":
|
| 307 |
-
if ex.get("pliometrico", False):
|
| 308 |
-
candidatos.append((ex, v, cobertura))
|
| 309 |
-
elif ex.get("equipamento") == "peso_livre":
|
| 310 |
-
candidatos.append((ex, v, cobertura, "explosivo"))
|
| 311 |
-
|
| 312 |
cobertura = len(set(ex["musculos"]) & set(musculos_alvo))
|
| 313 |
candidatos_multi.append((ex, v, cobertura))
|
| 314 |
|
|
@@ -317,17 +310,15 @@ def montar_treino(musculos_alvo, budget=45, objetivo="hipertrofia"):
|
|
| 317 |
melhor_cobertura = candidatos_multi[0][2]
|
| 318 |
top = [c for c in candidatos_multi if c[2] == melhor_cobertura]
|
| 319 |
ex, variacao, _ = random.choice(top)
|
| 320 |
-
|
|
|
|
| 321 |
|
| 322 |
-
# 3️⃣ Garantir pelo menos 1 exercício
|
| 323 |
for alvo in musculos_alvo:
|
| 324 |
if alvo not in musculos_cobertos:
|
| 325 |
candidatos = []
|
| 326 |
for ex in exercicios_db:
|
| 327 |
if alvo in ex["musculos"] and ex["nome"] not in usados:
|
| 328 |
-
# Se for explosividade, só aceita pliométrico
|
| 329 |
-
if objetivo == "explosividade" and not ex.get("pliometrico", False):
|
| 330 |
-
continue
|
| 331 |
for v in ex["variacoes"]:
|
| 332 |
candidatos.append((ex, v))
|
| 333 |
if candidatos:
|
|
@@ -335,29 +326,29 @@ def montar_treino(musculos_alvo, budget=45, objetivo="hipertrofia"):
|
|
| 335 |
top_custo = candidatos[0][1]["custo"]
|
| 336 |
top = [c for c in candidatos if c[1]["custo"] == top_custo]
|
| 337 |
ex, variacao = random.choice(top)
|
| 338 |
-
|
|
|
|
| 339 |
|
| 340 |
-
# 4️⃣ Completar
|
| 341 |
if custo_total < budget:
|
| 342 |
candidatos = []
|
| 343 |
for ex in exercicios_db:
|
| 344 |
if any(m in ex["musculos"] for m in musculos_alvo) and ex["nome"] not in usados:
|
| 345 |
-
# Se for explosividade, só aceita pliométrico
|
| 346 |
-
if objetivo == "explosividade" and not ex.get("pliometrico", False):
|
| 347 |
-
continue
|
| 348 |
for v in ex["variacoes"]:
|
| 349 |
if 2 <= v["custo"] <= 4:
|
| 350 |
candidatos.append((ex, v))
|
| 351 |
candidatos.sort(key=lambda x: x[1]["custo"], reverse=True)
|
| 352 |
|
| 353 |
for ex, variacao in candidatos:
|
| 354 |
-
|
|
|
|
| 355 |
continue
|
| 356 |
if custo_total >= budget:
|
| 357 |
break
|
| 358 |
|
| 359 |
return treino, custo_total
|
| 360 |
|
|
|
|
| 361 |
# -------------------------
|
| 362 |
# Função principal
|
| 363 |
# -------------------------
|
|
|
|
| 245 |
return "hipertrofia" # padrão se nada for detectado
|
| 246 |
|
| 247 |
|
| 248 |
+
def montar_treino(musculos_alvo, budget=45, objetivos=["hipertrofia"]):
|
| 249 |
treino = []
|
| 250 |
custo_total = 0
|
| 251 |
usados = set()
|
| 252 |
musculos_cobertos = set()
|
| 253 |
|
| 254 |
+
# 1️⃣ Faixas de repetições por objetivo
|
| 255 |
faixas_reps = {
|
| 256 |
"hipertrofia": (6, 15),
|
| 257 |
"forca": (2, 5),
|
|
|
|
| 260 |
}
|
| 261 |
|
| 262 |
def escolher_reps(objetivo):
|
|
|
|
| 263 |
faixa = faixas_reps.get(objetivo, (8, 12))
|
| 264 |
return random.randint(*faixa)
|
| 265 |
|
| 266 |
+
def add_exercicio(ex, variacao, series, objetivo_escolhido):
|
| 267 |
nonlocal custo_total
|
| 268 |
custo_ex = variacao["custo"] * series
|
| 269 |
+
reps = escolher_reps(objetivo_escolhido)
|
| 270 |
|
| 271 |
if ex["nome"] in usados:
|
| 272 |
return False
|
| 273 |
if custo_total + custo_ex <= budget:
|
| 274 |
|
| 275 |
descricao_final = variacao["descricao"]
|
| 276 |
+
# Regras específicas para explosividade
|
| 277 |
+
if objetivo_escolhido == "explosividade" and not ex.get("pliometrico", False):
|
| 278 |
if ex.get("equipamento") == "peso_livre":
|
| 279 |
descricao_final += " (executar com carga moderada e máxima velocidade)"
|
| 280 |
else:
|
| 281 |
+
return False # descarta máquinas, elásticos etc.
|
| 282 |
|
| 283 |
treino.append({
|
| 284 |
"nome": ex["nome"],
|
|
|
|
| 287 |
"reps": reps,
|
| 288 |
"custo_total": custo_ex,
|
| 289 |
"custo_unit": variacao["custo"],
|
| 290 |
+
"video": variacao["video"],
|
| 291 |
+
"objetivo": objetivo_escolhido
|
| 292 |
})
|
| 293 |
custo_total += custo_ex
|
| 294 |
usados.add(ex["nome"])
|
|
|
|
| 296 |
return True
|
| 297 |
return False
|
| 298 |
|
| 299 |
+
# 2️⃣ Multiarticulado principal
|
| 300 |
candidatos_multi = []
|
| 301 |
for ex in exercicios_db:
|
| 302 |
if any(m in ex["musculos"] for m in musculos_alvo):
|
| 303 |
for v in ex["variacoes"]:
|
| 304 |
if v["custo"] == 5:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
cobertura = len(set(ex["musculos"]) & set(musculos_alvo))
|
| 306 |
candidatos_multi.append((ex, v, cobertura))
|
| 307 |
|
|
|
|
| 310 |
melhor_cobertura = candidatos_multi[0][2]
|
| 311 |
top = [c for c in candidatos_multi if c[2] == melhor_cobertura]
|
| 312 |
ex, variacao, _ = random.choice(top)
|
| 313 |
+
obj_escolhido = random.choice(objetivos)
|
| 314 |
+
add_exercicio(ex, variacao, series=4, objetivo_escolhido=obj_escolhido)
|
| 315 |
|
| 316 |
+
# 3️⃣ Garantir pelo menos 1 exercício por músculo
|
| 317 |
for alvo in musculos_alvo:
|
| 318 |
if alvo not in musculos_cobertos:
|
| 319 |
candidatos = []
|
| 320 |
for ex in exercicios_db:
|
| 321 |
if alvo in ex["musculos"] and ex["nome"] not in usados:
|
|
|
|
|
|
|
|
|
|
| 322 |
for v in ex["variacoes"]:
|
| 323 |
candidatos.append((ex, v))
|
| 324 |
if candidatos:
|
|
|
|
| 326 |
top_custo = candidatos[0][1]["custo"]
|
| 327 |
top = [c for c in candidatos if c[1]["custo"] == top_custo]
|
| 328 |
ex, variacao = random.choice(top)
|
| 329 |
+
obj_escolhido = random.choice(objetivos)
|
| 330 |
+
add_exercicio(ex, variacao, series=3, objetivo_escolhido=obj_escolhido)
|
| 331 |
|
| 332 |
+
# 4️⃣ Completar treino respeitando objetivos múltiplos
|
| 333 |
if custo_total < budget:
|
| 334 |
candidatos = []
|
| 335 |
for ex in exercicios_db:
|
| 336 |
if any(m in ex["musculos"] for m in musculos_alvo) and ex["nome"] not in usados:
|
|
|
|
|
|
|
|
|
|
| 337 |
for v in ex["variacoes"]:
|
| 338 |
if 2 <= v["custo"] <= 4:
|
| 339 |
candidatos.append((ex, v))
|
| 340 |
candidatos.sort(key=lambda x: x[1]["custo"], reverse=True)
|
| 341 |
|
| 342 |
for ex, variacao in candidatos:
|
| 343 |
+
obj_escolhido = random.choice(objetivos)
|
| 344 |
+
if add_exercicio(ex, variacao, series=3, objetivo_escolhido=obj_escolhido):
|
| 345 |
continue
|
| 346 |
if custo_total >= budget:
|
| 347 |
break
|
| 348 |
|
| 349 |
return treino, custo_total
|
| 350 |
|
| 351 |
+
|
| 352 |
# -------------------------
|
| 353 |
# Função principal
|
| 354 |
# -------------------------
|