[IMPROVED] Refinar cálculo de promedio para tarifas excesivas
- Considerar solo tarifas que no exceden el umbral al calcular promedios - Añadir mensajes de log detallados sobre tarifas incluidas o excluidas - Eliminar verificación redundante de umbral en el cálculo del promedio - Mejorar la claridad de los mensajes sobre tarifas válidas utilizadas 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a090f732f7
commit
794eeb9a71
1 changed files with 8 additions and 4 deletions
|
@ -643,16 +643,20 @@ def update_rate_files():
|
|||
content = f.read().strip()
|
||||
if content:
|
||||
other_rate = float(content)
|
||||
same_type_rates.append(other_rate)
|
||||
# Solo incluir tarifas que no excedan el umbral
|
||||
if other_rate <= rate_threshold:
|
||||
same_type_rates.append(other_rate)
|
||||
logger.info(f"Considerando tarifa válida para promedio: {other_rate:.2f} de {other_region}")
|
||||
else:
|
||||
logger.info(f"Ignorando tarifa para promedio (excede umbral): {other_rate:.2f} de {other_region}")
|
||||
except (ValueError, FileNotFoundError):
|
||||
continue
|
||||
|
||||
# Si encontramos tarifas del mismo tipo, calcular el promedio
|
||||
if same_type_rates:
|
||||
avg_rate = sum(same_type_rates) / len(same_type_rates)
|
||||
# Asegurar que el promedio tampoco exceda el umbral
|
||||
avg_rate = min(avg_rate, rate_threshold)
|
||||
logger.warning(f"Tarifa {rate:.2f} supera el umbral de {rate_threshold}. Usando promedio de {len(same_type_rates)} tarifas: {avg_rate:.2f}")
|
||||
# El promedio nunca excederá el umbral ya que solo incluimos tarifas válidas
|
||||
logger.warning(f"Tarifa {rate:.2f} supera el umbral de {rate_threshold}. Usando promedio de {len(same_type_rates)} tarifas válidas: {avg_rate:.2f}")
|
||||
rate = round(avg_rate, 2)
|
||||
else:
|
||||
# Si no hay otras tarifas para calcular el promedio, usar un valor de fallback
|
||||
|
|
Loading…
Reference in a new issue