[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:
Mauro Rosero P. 2025-03-12 11:14:47 -05:00
parent a090f732f7
commit 794eeb9a71
Signed by: mrosero
GPG key ID: 83BD2A5F674B7E26

View file

@ -643,16 +643,20 @@ def update_rate_files():
content = f.read().strip() content = f.read().strip()
if content: if content:
other_rate = float(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): except (ValueError, FileNotFoundError):
continue continue
# Si encontramos tarifas del mismo tipo, calcular el promedio # Si encontramos tarifas del mismo tipo, calcular el promedio
if same_type_rates: if same_type_rates:
avg_rate = sum(same_type_rates) / len(same_type_rates) avg_rate = sum(same_type_rates) / len(same_type_rates)
# Asegurar que el promedio tampoco exceda el umbral # El promedio nunca excederá el umbral ya que solo incluimos tarifas válidas
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 válidas: {avg_rate:.2f}")
logger.warning(f"Tarifa {rate:.2f} supera el umbral de {rate_threshold}. Usando promedio de {len(same_type_rates)} tarifas: {avg_rate:.2f}")
rate = round(avg_rate, 2) rate = round(avg_rate, 2)
else: else:
# Si no hay otras tarifas para calcular el promedio, usar un valor de fallback # Si no hay otras tarifas para calcular el promedio, usar un valor de fallback