Update modules/studentact/current_situation_analysis.py
Browse files
modules/studentact/current_situation_analysis.py
CHANGED
@@ -444,14 +444,19 @@ def get_dependency_depths(token, depth=0, analyzed_tokens=None):
|
|
444 |
|
445 |
return current_result
|
446 |
|
447 |
-
|
|
|
|
|
|
|
448 |
optimal_connections=None, optimal_depth=None):
|
449 |
"""
|
450 |
-
Normaliza un valor
|
451 |
|
452 |
Args:
|
453 |
value: Valor a normalizar
|
454 |
-
|
|
|
|
|
455 |
range_factor: Factor para ajustar el rango
|
456 |
optimal_length: Longitud óptima (opcional)
|
457 |
optimal_connections: Número óptimo de conexiones (opcional)
|
@@ -461,6 +466,30 @@ def normalize_score(value, optimal_value=1.0, range_factor=2.0, optimal_length=N
|
|
461 |
float: Valor normalizado entre 0 y 1
|
462 |
"""
|
463 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
464 |
# Validar valores negativos o cero
|
465 |
if value < 0:
|
466 |
logger.warning(f"Valor negativo recibido: {value}")
|
@@ -471,6 +500,13 @@ def normalize_score(value, optimal_value=1.0, range_factor=2.0, optimal_length=N
|
|
471 |
logger.warning("Valor cero recibido")
|
472 |
return 0.0
|
473 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
# Identificar el valor de referencia a usar
|
475 |
if optimal_depth is not None:
|
476 |
reference = optimal_depth
|
@@ -479,25 +515,31 @@ def normalize_score(value, optimal_value=1.0, range_factor=2.0, optimal_length=N
|
|
479 |
elif optimal_length is not None:
|
480 |
reference = optimal_length
|
481 |
else:
|
482 |
-
reference =
|
483 |
|
484 |
# Validar valor de referencia
|
485 |
if reference <= 0:
|
486 |
logger.warning(f"Valor de referencia inválido: {reference}")
|
487 |
return 0.0
|
488 |
|
489 |
-
# Calcular
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
|
498 |
-
# Calcular score normalizado
|
499 |
-
score = 1.0 - min(diff / max_diff, 1.0)
|
500 |
-
|
501 |
# Asegurar que el resultado esté entre 0 y 1
|
502 |
return max(0.0, min(1.0, score))
|
503 |
|
@@ -505,6 +547,11 @@ def normalize_score(value, optimal_value=1.0, range_factor=2.0, optimal_length=N
|
|
505 |
logger.error(f"Error en normalize_score: {str(e)}")
|
506 |
return 0.0
|
507 |
|
|
|
|
|
|
|
|
|
|
|
508 |
# Funciones de generación de gráficos
|
509 |
def generate_sentence_graphs(doc):
|
510 |
"""Genera visualizaciones de estructura de oraciones"""
|
|
|
444 |
|
445 |
return current_result
|
446 |
|
447 |
+
###########################################################33
|
448 |
+
def normalize_score(value, metric_type,
|
449 |
+
min_threshold=0.0, target_threshold=1.0,
|
450 |
+
range_factor=2.0, optimal_length=None,
|
451 |
optimal_connections=None, optimal_depth=None):
|
452 |
"""
|
453 |
+
Normaliza un valor considerando umbrales específicos por tipo de métrica.
|
454 |
|
455 |
Args:
|
456 |
value: Valor a normalizar
|
457 |
+
metric_type: Tipo de métrica ('vocabulary', 'structure', 'cohesion', 'clarity')
|
458 |
+
min_threshold: Valor mínimo aceptable
|
459 |
+
target_threshold: Valor objetivo
|
460 |
range_factor: Factor para ajustar el rango
|
461 |
optimal_length: Longitud óptima (opcional)
|
462 |
optimal_connections: Número óptimo de conexiones (opcional)
|
|
|
466 |
float: Valor normalizado entre 0 y 1
|
467 |
"""
|
468 |
try:
|
469 |
+
# Definir umbrales por tipo de métrica
|
470 |
+
METRIC_THRESHOLDS = {
|
471 |
+
'vocabulary': {
|
472 |
+
'min': 0.60,
|
473 |
+
'target': 0.75,
|
474 |
+
'range_factor': 1.5
|
475 |
+
},
|
476 |
+
'structure': {
|
477 |
+
'min': 0.65,
|
478 |
+
'target': 0.80,
|
479 |
+
'range_factor': 1.8
|
480 |
+
},
|
481 |
+
'cohesion': {
|
482 |
+
'min': 0.55,
|
483 |
+
'target': 0.70,
|
484 |
+
'range_factor': 1.6
|
485 |
+
},
|
486 |
+
'clarity': {
|
487 |
+
'min': 0.60,
|
488 |
+
'target': 0.75,
|
489 |
+
'range_factor': 1.7
|
490 |
+
}
|
491 |
+
}
|
492 |
+
|
493 |
# Validar valores negativos o cero
|
494 |
if value < 0:
|
495 |
logger.warning(f"Valor negativo recibido: {value}")
|
|
|
500 |
logger.warning("Valor cero recibido")
|
501 |
return 0.0
|
502 |
|
503 |
+
# Obtener umbrales específicos para el tipo de métrica
|
504 |
+
thresholds = METRIC_THRESHOLDS.get(metric_type, {
|
505 |
+
'min': min_threshold,
|
506 |
+
'target': target_threshold,
|
507 |
+
'range_factor': range_factor
|
508 |
+
})
|
509 |
+
|
510 |
# Identificar el valor de referencia a usar
|
511 |
if optimal_depth is not None:
|
512 |
reference = optimal_depth
|
|
|
515 |
elif optimal_length is not None:
|
516 |
reference = optimal_length
|
517 |
else:
|
518 |
+
reference = thresholds['target']
|
519 |
|
520 |
# Validar valor de referencia
|
521 |
if reference <= 0:
|
522 |
logger.warning(f"Valor de referencia inválido: {reference}")
|
523 |
return 0.0
|
524 |
|
525 |
+
# Calcular score basado en umbrales
|
526 |
+
if value < thresholds['min']:
|
527 |
+
# Valor por debajo del mínimo
|
528 |
+
score = (value / thresholds['min']) * 0.5 # Máximo 0.5 para valores bajo el mínimo
|
529 |
+
elif value < thresholds['target']:
|
530 |
+
# Valor entre mínimo y objetivo
|
531 |
+
range_size = thresholds['target'] - thresholds['min']
|
532 |
+
progress = (value - thresholds['min']) / range_size
|
533 |
+
score = 0.5 + (progress * 0.5) # Escala entre 0.5 y 1.0
|
534 |
+
else:
|
535 |
+
# Valor alcanza o supera el objetivo
|
536 |
+
score = 1.0
|
537 |
+
|
538 |
+
# Penalizar valores muy por encima del objetivo
|
539 |
+
if value > (thresholds['target'] * thresholds['range_factor']):
|
540 |
+
excess = (value - thresholds['target']) / (thresholds['target'] * thresholds['range_factor'])
|
541 |
+
score = max(0.7, 1.0 - excess) # No bajar de 0.7 para valores altos
|
542 |
|
|
|
|
|
|
|
543 |
# Asegurar que el resultado esté entre 0 y 1
|
544 |
return max(0.0, min(1.0, score))
|
545 |
|
|
|
547 |
logger.error(f"Error en normalize_score: {str(e)}")
|
548 |
return 0.0
|
549 |
|
550 |
+
|
551 |
+
|
552 |
+
|
553 |
+
##############################################################
|
554 |
+
|
555 |
# Funciones de generación de gráficos
|
556 |
def generate_sentence_graphs(doc):
|
557 |
"""Genera visualizaciones de estructura de oraciones"""
|