Spaces:
Sleeping
Sleeping
Refactorizacion al guardar datos, correccion de algunos errores
Browse files- tecnicas/controllers/models_controller/calificacion_controller.py +42 -55
- tecnicas/controllers/models_controller/dato_controller.py +13 -14
- tecnicas/controllers/views_controller/api_rating_controller.py +6 -53
- tecnicas/controllers/views_controller/session_management/details_escala_controller.py +10 -9
- tecnicas/controllers/views_controller/sessions_tester/convencional_scales_controller.py +77 -68
- tecnicas/controllers/views_controller/sessions_tester/init_session_tester_controller.py +8 -5
- tecnicas/models/calificacion.py +4 -1
- tecnicas/models/dato.py +1 -1
- tecnicas/models/dato_valor.py +2 -2
tecnicas/controllers/models_controller/calificacion_controller.py
CHANGED
|
@@ -6,49 +6,22 @@ from tecnicas.utils import controller_error, getId
|
|
| 6 |
|
| 7 |
class CalificacionController():
|
| 8 |
def __init__(self, product: Producto | int, technique: Tecnica | int, tester: Catador | int):
|
|
|
|
|
|
|
|
|
|
| 9 |
atributes = {
|
| 10 |
-
"num_repeticion":
|
| 11 |
-
"
|
| 12 |
"id_producto_id": getId(product),
|
| 13 |
"id_catador_id": getId(tester),
|
| 14 |
}
|
| 15 |
|
| 16 |
-
self.rating = Calificacion(**atributes)
|
| 17 |
-
|
| 18 |
-
def validateRating(self):
|
| 19 |
-
try:
|
| 20 |
-
self.rating.clean()
|
| 21 |
-
return self.rating
|
| 22 |
-
except ValidationError as e:
|
| 23 |
-
return controller_error("No es posible validar la calificación")
|
| 24 |
-
|
| 25 |
-
def setRepetition(self, repetition: int = None) -> int | dict:
|
| 26 |
-
try:
|
| 27 |
-
if repetition is not None:
|
| 28 |
-
self.rating.num_repeticion = repetition
|
| 29 |
-
else:
|
| 30 |
-
self.rating.num_repeticion = self.rating.id_tecnica.repeticion
|
| 31 |
-
|
| 32 |
-
return self.rating.num_repeticion
|
| 33 |
-
except ValidationError as e:
|
| 34 |
-
return controller_error(e)
|
| 35 |
-
|
| 36 |
-
def saveRating(self):
|
| 37 |
-
try:
|
| 38 |
-
self.rating.save()
|
| 39 |
-
return self.rating
|
| 40 |
-
except ValidationError as e:
|
| 41 |
-
return controller_error(e)
|
| 42 |
|
| 43 |
@staticmethod
|
| 44 |
def getRatingsByTechnique(technique: Tecnica):
|
| 45 |
repetition = technique.repeticion
|
| 46 |
-
|
| 47 |
-
if not repetition:
|
| 48 |
-
return controller_error("Sin datos calificados aún")
|
| 49 |
-
|
| 50 |
ratings = list(Calificacion.objects.filter(id_tecnica=technique))
|
| 51 |
-
|
| 52 |
return ratings
|
| 53 |
|
| 54 |
@staticmethod
|
|
@@ -94,39 +67,53 @@ class CalificacionController():
|
|
| 94 |
return ratings
|
| 95 |
|
| 96 |
@staticmethod
|
| 97 |
-
def
|
| 98 |
positions: list[Posicion] = None,
|
| 99 |
-
user_cata: str = None,
|
| 100 |
repetition: int = None,
|
| 101 |
-
technique: Tecnica = None,
|
| 102 |
-
id_technique: int = None,
|
| 103 |
num_words: int = None):
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
filters = {
|
| 107 |
-
"
|
| 108 |
-
"
|
| 109 |
}
|
| 110 |
|
| 111 |
-
if
|
| 112 |
-
filters["
|
| 113 |
-
|
| 114 |
-
filters["
|
|
|
|
| 115 |
|
| 116 |
-
ratings =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
|
|
|
| 118 |
if len(ratings) == 0:
|
| 119 |
-
return positions
|
| 120 |
|
| 121 |
-
|
|
|
|
| 122 |
|
| 123 |
-
for
|
| 124 |
-
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
class CalificacionController():
|
| 8 |
def __init__(self, product: Producto | int, technique: Tecnica | int, tester: Catador | int):
|
| 9 |
+
technique = Tecnica.objects.only(
|
| 10 |
+
"repeticion").get(id=getId(technique))
|
| 11 |
+
|
| 12 |
atributes = {
|
| 13 |
+
"num_repeticion": technique.repeticion,
|
| 14 |
+
"id_tecnica": technique,
|
| 15 |
"id_producto_id": getId(product),
|
| 16 |
"id_catador_id": getId(tester),
|
| 17 |
}
|
| 18 |
|
| 19 |
+
(self.rating, created) = Calificacion.objects.get_or_create(**atributes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@staticmethod
|
| 22 |
def getRatingsByTechnique(technique: Tecnica):
|
| 23 |
repetition = technique.repeticion
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
ratings = list(Calificacion.objects.filter(id_tecnica=technique))
|
|
|
|
| 25 |
return ratings
|
| 26 |
|
| 27 |
@staticmethod
|
|
|
|
| 67 |
return ratings
|
| 68 |
|
| 69 |
@staticmethod
|
| 70 |
+
def checkPositionWithoutRating(
|
| 71 |
positions: list[Posicion] = None,
|
| 72 |
+
user_cata: Catador | str = None,
|
| 73 |
repetition: int = None,
|
| 74 |
+
technique: Tecnica | int = None,
|
|
|
|
| 75 |
num_words: int = None):
|
| 76 |
+
end_rating = False
|
| 77 |
+
|
| 78 |
+
# Obtener lista con codigos de productos
|
| 79 |
+
check_products = [
|
| 80 |
+
position.id_producto.codigoProducto for position in positions]
|
| 81 |
|
| 82 |
filters = {
|
| 83 |
+
"num_repeticion": repetition,
|
| 84 |
+
"id_tecnica": getId(technique)
|
| 85 |
}
|
| 86 |
|
| 87 |
+
if isinstance(user_cata, Catador):
|
| 88 |
+
filters["id_catador"] = user_cata
|
| 89 |
+
else:
|
| 90 |
+
filters["id_catador"] = Catador.objects.get(
|
| 91 |
+
user__username=user_cata)
|
| 92 |
|
| 93 |
+
ratings = list(Calificacion.objects.filter(**filters).select_related(
|
| 94 |
+
"id_producto",
|
| 95 |
+
"id_tecnica",
|
| 96 |
+
"id_catador",
|
| 97 |
+
))
|
| 98 |
|
| 99 |
+
# Si no hay calificaciones regresar las posiciones
|
| 100 |
if len(ratings) == 0:
|
| 101 |
+
return (positions, end_rating)
|
| 102 |
|
| 103 |
+
rating_products = [
|
| 104 |
+
rating.id_producto.codigoProducto for rating in ratings]
|
| 105 |
|
| 106 |
+
for index, rating in enumerate(ratings):
|
| 107 |
+
data_rating = rating.dato_calificacion.all()
|
| 108 |
|
| 109 |
+
if len(data_rating) < num_words or len(data_rating) == 0:
|
| 110 |
+
return (positions[index], end_rating)
|
| 111 |
|
| 112 |
+
next_product = list(set(check_products) - set(rating_products))
|
| 113 |
+
if len(next_product) != 0:
|
| 114 |
+
next_position = [
|
| 115 |
+
position for position in positions if position.id_producto.codigoProducto == next_product[0]][0]
|
| 116 |
+
return (next_position, end_rating)
|
| 117 |
+
else:
|
| 118 |
+
end_rating = True
|
| 119 |
+
return (positions[-1], end_rating)
|
tecnicas/controllers/models_controller/dato_controller.py
CHANGED
|
@@ -12,7 +12,11 @@ class DatoController():
|
|
| 12 |
}
|
| 13 |
|
| 14 |
self.data = Dato(**atributes)
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def setRating(self, new_rating: Calificacion):
|
| 18 |
try:
|
|
@@ -35,19 +39,14 @@ class DatoController():
|
|
| 35 |
except ValidationError as e:
|
| 36 |
return controller_error(e.message)
|
| 37 |
|
| 38 |
-
def
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
valor=self.value_data.valor
|
| 45 |
-
)
|
| 46 |
else:
|
| 47 |
-
self.value_data =
|
| 48 |
-
id_dato=self.data,
|
| 49 |
-
valor=self.value_data.valor
|
| 50 |
-
)
|
| 51 |
|
| 52 |
return self.value_data
|
| 53 |
|
|
@@ -88,7 +87,7 @@ class DatoController():
|
|
| 88 |
repeticion=F("id_dato__id_calificacion__num_repeticion"),
|
| 89 |
producto_code=F(
|
| 90 |
"id_dato__id_calificacion__id_producto__codigoProducto"),
|
| 91 |
-
|
| 92 |
"id_dato__id_calificacion__id_catador__user__username"),
|
| 93 |
dato_valor=F("valor")
|
| 94 |
)
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
self.data = Dato(**atributes)
|
| 15 |
+
|
| 16 |
+
if isinstance(value_rating, bool):
|
| 17 |
+
self.value_data = ValorBooleano(valor=value_rating)
|
| 18 |
+
else:
|
| 19 |
+
self.value_data = ValorDecimal(valor=value_rating)
|
| 20 |
|
| 21 |
def setRating(self, new_rating: Calificacion):
|
| 22 |
try:
|
|
|
|
| 39 |
except ValidationError as e:
|
| 40 |
return controller_error(e.message)
|
| 41 |
|
| 42 |
+
def setValue(self, new_value=None):
|
| 43 |
+
if new_value:
|
| 44 |
+
if isinstance(new_value, bool):
|
| 45 |
+
self.value_data = ValorBooleano(valor=new_value)
|
| 46 |
+
else:
|
| 47 |
+
self.value_data = ValorDecimal(valor=new_value)
|
|
|
|
|
|
|
| 48 |
else:
|
| 49 |
+
self.value_data.id_dato = self.data
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
return self.value_data
|
| 52 |
|
|
|
|
| 87 |
repeticion=F("id_dato__id_calificacion__num_repeticion"),
|
| 88 |
producto_code=F(
|
| 89 |
"id_dato__id_calificacion__id_producto__codigoProducto"),
|
| 90 |
+
usuario_catador=F(
|
| 91 |
"id_dato__id_calificacion__id_catador__user__username"),
|
| 92 |
dato_valor=F("valor")
|
| 93 |
)
|
tecnicas/controllers/views_controller/api_rating_controller.py
CHANGED
|
@@ -7,65 +7,18 @@ class ApiRatingController():
|
|
| 7 |
self.rating_controller = rating_controller
|
| 8 |
self.data_controller = data_controller
|
| 9 |
|
| 10 |
-
def setRating(self) -> int | dict:
|
| 11 |
-
repetition = self.rating_controller.setRepetition()
|
| 12 |
-
if isinstance(repetition, dict):
|
| 13 |
-
return controller_error(repetition["error"])
|
| 14 |
-
return repetition
|
| 15 |
-
|
| 16 |
-
def saveRating(self):
|
| 17 |
-
rating = self.rating_controller.saveRating()
|
| 18 |
-
if isinstance(rating, dict):
|
| 19 |
-
return controller_error(rating["error"])
|
| 20 |
-
return rating
|
| 21 |
-
|
| 22 |
-
def setRatingInData(self):
|
| 23 |
-
update_rating = self.data_controller.setRating(
|
| 24 |
-
self.rating_controller.rating)
|
| 25 |
-
if isinstance(update_rating, dict):
|
| 26 |
-
return controller_error(update_rating["error"])
|
| 27 |
-
return update_rating
|
| 28 |
-
|
| 29 |
-
def saveData(self):
|
| 30 |
-
data = self.data_controller.saveData()
|
| 31 |
-
if isinstance(data, dict):
|
| 32 |
-
return controller_error(data["error"])
|
| 33 |
-
return data
|
| 34 |
-
|
| 35 |
-
def setValueRating(self):
|
| 36 |
-
self.data_controller.setInstanceValue()
|
| 37 |
-
|
| 38 |
-
def saveValue(self):
|
| 39 |
-
value = self.data_controller.saveValue()
|
| 40 |
-
if isinstance(value, dict):
|
| 41 |
-
return controller_error(value["error"])
|
| 42 |
-
|
| 43 |
def controllPostScales(self) -> dict:
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
reptition = self.setRating()
|
| 49 |
-
if isinstance(reptition, dict):
|
| 50 |
-
return controller_error(reptition["error"])
|
| 51 |
|
| 52 |
-
|
| 53 |
-
if isinstance(rating, dict):
|
| 54 |
-
return controller_error(rating["error"])
|
| 55 |
-
|
| 56 |
-
rating_data = self.setRatingInData()
|
| 57 |
-
if isinstance(rating_data, dict):
|
| 58 |
-
return controller_error(rating_data["error"])
|
| 59 |
-
|
| 60 |
-
data = self.saveData()
|
| 61 |
if isinstance(data, dict):
|
| 62 |
return controller_error(data["error"])
|
| 63 |
|
| 64 |
-
|
| 65 |
-
if isinstance(value, dict):
|
| 66 |
-
return controller_error(value["error"])
|
| 67 |
|
| 68 |
-
value_save = self.saveValue()
|
| 69 |
if isinstance(value_save, dict):
|
| 70 |
return controller_error(value_save["error"])
|
| 71 |
|
|
|
|
| 7 |
self.rating_controller = rating_controller
|
| 8 |
self.data_controller = data_controller
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def controllPostScales(self) -> dict:
|
| 11 |
+
self.data_controller.setRating(
|
| 12 |
+
new_rating=self.rating_controller.rating
|
| 13 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
data = self.data_controller.saveData()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
if isinstance(data, dict):
|
| 17 |
return controller_error(data["error"])
|
| 18 |
|
| 19 |
+
self.data_controller.setValue()
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
value_save = self.data_controller.saveValue()
|
| 22 |
if isinstance(value_save, dict):
|
| 23 |
return controller_error(value_save["error"])
|
| 24 |
|
tecnicas/controllers/views_controller/session_management/details_escala_controller.py
CHANGED
|
@@ -14,8 +14,8 @@ Encabezados de como deben de aparecer los datos juntos
|
|
| 14 |
from django.http import HttpRequest
|
| 15 |
from django.shortcuts import render, redirect
|
| 16 |
from django.urls import reverse
|
| 17 |
-
from tecnicas.models import SesionSensorial, Presentador, Participacion
|
| 18 |
-
from tecnicas.controllers import DatoController,
|
| 19 |
from .details_controller import DetallesController
|
| 20 |
from tecnicas.utils import defaultdict_to_dict, controller_error
|
| 21 |
from collections import defaultdict
|
|
@@ -52,10 +52,10 @@ class DetallesEscalasController(DetallesController):
|
|
| 52 |
# Se recuperan las calificaciones
|
| 53 |
ratings_for_repetition = []
|
| 54 |
|
| 55 |
-
ratings =
|
| 56 |
-
|
| 57 |
|
| 58 |
-
if
|
| 59 |
self.context["calificaciones"] = ratings_for_repetition
|
| 60 |
self.context["existen_calificaciones"] = False
|
| 61 |
return self.context
|
|
@@ -67,7 +67,7 @@ class DetallesEscalasController(DetallesController):
|
|
| 67 |
lambda: defaultdict(lambda: defaultdict(list)))
|
| 68 |
|
| 69 |
for item in data:
|
| 70 |
-
user = item["
|
| 71 |
rep = item["repeticion"]
|
| 72 |
prod = item["producto_code"]
|
| 73 |
|
|
@@ -95,12 +95,13 @@ class DetallesEscalasController(DetallesController):
|
|
| 95 |
return self.getResponse(error="La sesión ya está activada", request=request)
|
| 96 |
elif technique.repeticion >= technique.repeticiones_max:
|
| 97 |
return self.getResponse(error="Se ha alcanzado el número de repeticiones máxima", request=request)
|
| 98 |
-
|
| 99 |
-
there_participacions = Participacion.objects.filter(
|
|
|
|
| 100 |
|
| 101 |
if there_participacions:
|
| 102 |
(is_update_participations,
|
| 103 |
-
|
| 104 |
if not is_update_participations:
|
| 105 |
return self.getResponse(error=message, request=request)
|
| 106 |
|
|
|
|
| 14 |
from django.http import HttpRequest
|
| 15 |
from django.shortcuts import render, redirect
|
| 16 |
from django.urls import reverse
|
| 17 |
+
from tecnicas.models import SesionSensorial, Presentador, Participacion, Calificacion
|
| 18 |
+
from tecnicas.controllers import DatoController, PalabrasController, ParticipacionController
|
| 19 |
from .details_controller import DetallesController
|
| 20 |
from tecnicas.utils import defaultdict_to_dict, controller_error
|
| 21 |
from collections import defaultdict
|
|
|
|
| 52 |
# Se recuperan las calificaciones
|
| 53 |
ratings_for_repetition = []
|
| 54 |
|
| 55 |
+
ratings = list(Calificacion.objects.filter(
|
| 56 |
+
id_tecnica=self.session.tecnica))
|
| 57 |
|
| 58 |
+
if not ratings:
|
| 59 |
self.context["calificaciones"] = ratings_for_repetition
|
| 60 |
self.context["existen_calificaciones"] = False
|
| 61 |
return self.context
|
|
|
|
| 67 |
lambda: defaultdict(lambda: defaultdict(list)))
|
| 68 |
|
| 69 |
for item in data:
|
| 70 |
+
user = item["usuario_catador"]
|
| 71 |
rep = item["repeticion"]
|
| 72 |
prod = item["producto_code"]
|
| 73 |
|
|
|
|
| 95 |
return self.getResponse(error="La sesión ya está activada", request=request)
|
| 96 |
elif technique.repeticion >= technique.repeticiones_max:
|
| 97 |
return self.getResponse(error="Se ha alcanzado el número de repeticiones máxima", request=request)
|
| 98 |
+
|
| 99 |
+
there_participacions = Participacion.objects.filter(
|
| 100 |
+
tecnica=technique).exists()
|
| 101 |
|
| 102 |
if there_participacions:
|
| 103 |
(is_update_participations,
|
| 104 |
+
message) = ParticipacionController.outAllInSession(self.session)
|
| 105 |
if not is_update_participations:
|
| 106 |
return self.getResponse(error=message, request=request)
|
| 107 |
|
tecnicas/controllers/views_controller/sessions_tester/convencional_scales_controller.py
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
from django.http import HttpRequest
|
| 2 |
from django.shortcuts import redirect, render
|
| 3 |
from django.urls import reverse
|
| 4 |
-
from tecnicas.models import SesionSensorial, Catador, Participacion, Producto
|
| 5 |
from tecnicas.controllers import PosicionController, CalificacionController, ParticipacionController, PalabrasController, EscalaController, DatoController
|
| 6 |
|
| 7 |
|
| 8 |
class ConvencionalScalesController:
|
| 9 |
context = {}
|
| 10 |
current_directory = "tecnicas/forms_tester/convencional.html"
|
|
|
|
| 11 |
|
| 12 |
def __init__(self, sensorial_session: SesionSensorial, user_tester: Catador):
|
| 13 |
self.tester = user_tester
|
|
@@ -18,68 +19,70 @@ class ConvencionalScalesController:
|
|
| 18 |
self.participation = Participacion.objects.get(
|
| 19 |
tecnica=technique, catador=request.user.user_catador)
|
| 20 |
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
|
|
|
| 24 |
id_order=request.session["id_order"])
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
words = PalabrasController.getWordsInTechnique(technique=technique)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
repetition=technique.repeticion,
|
| 35 |
technique=technique,
|
| 36 |
num_words=len(words)
|
| 37 |
)
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
params = {
|
| 43 |
-
"code_sesion": self.session.codigo_sesion
|
| 44 |
-
}
|
| 45 |
return redirect(reverse('cata_system:catador_init_session', kwargs=params))
|
| 46 |
|
|
|
|
| 47 |
if isinstance(next_position, list):
|
| 48 |
next_position = next_position[0]
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
elif not ratings_product:
|
| 63 |
-
self.context["words"] = words
|
| 64 |
else:
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
self.context["words"] = words_to_use
|
| 73 |
|
|
|
|
| 74 |
scale = EscalaController.getScaleByTechnique(technique=technique)
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
self.context["tags"] = use_tags
|
| 80 |
-
|
| 81 |
-
print(self.context)
|
| 82 |
-
return render(request, self.current_directory, self.context)
|
| 83 |
|
| 84 |
def controllGetRATA(self, request: HttpRequest):
|
| 85 |
technique = self.session.tecnica
|
|
@@ -92,32 +95,35 @@ class ConvencionalScalesController:
|
|
| 92 |
|
| 93 |
words = PalabrasController.getWordsInTechnique(technique=technique)
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
ratings_product = CalificacionController.getRatings(
|
| 98 |
-
technique=technique,
|
| 99 |
-
product=product_in,
|
| 100 |
-
repetition=technique.repeticion,
|
| 101 |
-
user_tester=request.user.username
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
if isinstance(ratings_product, dict):
|
| 105 |
-
self.context["error"] = ratings_product.get("error")
|
| 106 |
-
return render(request, self.current_directory, self.context)
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
break
|
| 113 |
|
| 114 |
-
# Obtener los datos asociados
|
| 115 |
-
recoreded_data =
|
| 116 |
|
| 117 |
if not recoreded_data:
|
| 118 |
# Si no hay datos entonces devolver el producto con todas las palabras
|
| 119 |
-
|
| 120 |
-
|
| 121 |
break
|
| 122 |
else:
|
| 123 |
words_to_use = PalabrasController.getWordsWithoutData(
|
|
@@ -125,18 +131,21 @@ class ConvencionalScalesController:
|
|
| 125 |
|
| 126 |
# Si quedan palabras por calificar mandar las palabras con el producto
|
| 127 |
if not isinstance(words_to_use, dict) and words_to_use:
|
| 128 |
-
|
| 129 |
-
|
| 130 |
break
|
| 131 |
|
| 132 |
# Si no hay producto que falta por calificar finalizar sesion para el Catador
|
| 133 |
-
if
|
| 134 |
updated_participation = ParticipacionController.finishSession(
|
| 135 |
self.participation)
|
| 136 |
params = {
|
| 137 |
"code_sesion": self.session.codigo_sesion
|
| 138 |
}
|
| 139 |
-
return redirect(reverse(
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
# Agregar informacion de la escala
|
| 142 |
scale = EscalaController.getScaleByTechnique(technique=technique)
|
|
|
|
| 1 |
from django.http import HttpRequest
|
| 2 |
from django.shortcuts import redirect, render
|
| 3 |
from django.urls import reverse
|
| 4 |
+
from tecnicas.models import SesionSensorial, Catador, Participacion, Producto, Calificacion, Palabra
|
| 5 |
from tecnicas.controllers import PosicionController, CalificacionController, ParticipacionController, PalabrasController, EscalaController, DatoController
|
| 6 |
|
| 7 |
|
| 8 |
class ConvencionalScalesController:
|
| 9 |
context = {}
|
| 10 |
current_directory = "tecnicas/forms_tester/convencional.html"
|
| 11 |
+
previus_directory = "cata_system:catador_init_session"
|
| 12 |
|
| 13 |
def __init__(self, sensorial_session: SesionSensorial, user_tester: Catador):
|
| 14 |
self.tester = user_tester
|
|
|
|
| 19 |
self.participation = Participacion.objects.get(
|
| 20 |
tecnica=technique, catador=request.user.user_catador)
|
| 21 |
|
| 22 |
+
ctx = self.context
|
| 23 |
+
ctx["session"] = self.session
|
| 24 |
|
| 25 |
+
# Obtener posiciones y palabras de la técnica
|
| 26 |
+
positions_in_order = PosicionController.getPostionsInOrder(
|
| 27 |
id_order=request.session["id_order"])
|
| 28 |
+
aligned_positions_in_order = sorted(
|
| 29 |
+
positions_in_order, key=lambda p: p.posicion)
|
|
|
|
| 30 |
words = PalabrasController.getWordsInTechnique(technique=technique)
|
| 31 |
|
| 32 |
+
# Comprobar siguiente posición sin calificar
|
| 33 |
+
(next_position, end_products) = CalificacionController.checkPositionWithoutRating(
|
| 34 |
+
positions=aligned_positions_in_order,
|
| 35 |
+
user_cata=request.user.user_catador,
|
| 36 |
repetition=technique.repeticion,
|
| 37 |
technique=technique,
|
| 38 |
num_words=len(words)
|
| 39 |
)
|
| 40 |
|
| 41 |
+
# Si no hay productos se finaliza la sesion
|
| 42 |
+
if end_products:
|
| 43 |
+
ParticipacionController.finishSession(self.participation)
|
| 44 |
+
params = {"code_sesion": self.session.codigo_sesion}
|
|
|
|
|
|
|
| 45 |
return redirect(reverse('cata_system:catador_init_session', kwargs=params))
|
| 46 |
|
| 47 |
+
# Si devuelve una lista, tomar el primer elemento
|
| 48 |
if isinstance(next_position, list):
|
| 49 |
next_position = next_position[0]
|
| 50 |
|
| 51 |
+
# Producto a calificar ahora
|
| 52 |
+
product = next_position.id_producto
|
| 53 |
+
ctx["product"] = product
|
| 54 |
+
|
| 55 |
+
# Revisar las palabras para calificar
|
| 56 |
+
try:
|
| 57 |
+
rating = Calificacion.objects.get(
|
| 58 |
+
num_repeticion=technique.repeticion,
|
| 59 |
+
id_producto=product,
|
| 60 |
+
id_tecnica=technique,
|
| 61 |
+
id_catador=self.tester
|
| 62 |
+
)
|
| 63 |
+
there_rating = True
|
| 64 |
+
except Calificacion.DoesNotExist:
|
| 65 |
+
there_rating = False
|
| 66 |
|
| 67 |
+
# Si no hay calificaciones previas, usar todas las palabras
|
| 68 |
+
if not there_rating:
|
| 69 |
+
ctx["words"] = words
|
|
|
|
|
|
|
| 70 |
else:
|
| 71 |
+
ratings_product = rating.dato_calificacion.all()
|
| 72 |
+
# Filtrar palabras que faltan
|
| 73 |
+
words_to_use = PalabrasController.getWordsWithoutData(
|
| 74 |
+
recoreded_data=ratings_product,
|
| 75 |
+
words=words
|
| 76 |
+
)
|
| 77 |
+
ctx["words"] = words_to_use
|
|
|
|
| 78 |
|
| 79 |
+
# Escala y etiquetas relacionadas
|
| 80 |
scale = EscalaController.getScaleByTechnique(technique=technique)
|
| 81 |
+
ctx["scale"] = scale
|
| 82 |
+
ctx["type_scale"] = scale.id_tipo_escala.nombre_escala
|
| 83 |
+
ctx["tags"] = EscalaController.getRelatedTagsInScale(scale=scale)
|
| 84 |
|
| 85 |
+
return render(request, self.current_directory, ctx)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
def controllGetRATA(self, request: HttpRequest):
|
| 88 |
technique = self.session.tecnica
|
|
|
|
| 95 |
|
| 96 |
words = PalabrasController.getWordsInTechnique(technique=technique)
|
| 97 |
|
| 98 |
+
use_product: Producto = None
|
| 99 |
+
use_words: list[Palabra] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
# Revisamos el producto que le falten calificaciones
|
| 102 |
+
for current_product in products_in_technique:
|
| 103 |
+
try:
|
| 104 |
+
rating = Calificacion.objects.get(
|
| 105 |
+
num_repeticion=technique.repeticion,
|
| 106 |
+
id_producto=current_product,
|
| 107 |
+
id_tecnica=technique,
|
| 108 |
+
id_catador=self.tester
|
| 109 |
+
)
|
| 110 |
+
there_rating = True
|
| 111 |
+
except Calificacion.DoesNotExist:
|
| 112 |
+
there_rating = False
|
| 113 |
+
|
| 114 |
+
# Si no hay calificacion mandamos el producto actual y todas la palabras
|
| 115 |
+
if not there_rating:
|
| 116 |
+
use_product = current_product
|
| 117 |
+
use_words = words
|
| 118 |
break
|
| 119 |
|
| 120 |
+
# Obtener los datos asociados para la calificacion para ver que palabras quedan por calificar
|
| 121 |
+
recoreded_data = rating.dato_calificacion.all()
|
| 122 |
|
| 123 |
if not recoreded_data:
|
| 124 |
# Si no hay datos entonces devolver el producto con todas las palabras
|
| 125 |
+
use_product = current_product
|
| 126 |
+
use_words = words
|
| 127 |
break
|
| 128 |
else:
|
| 129 |
words_to_use = PalabrasController.getWordsWithoutData(
|
|
|
|
| 131 |
|
| 132 |
# Si quedan palabras por calificar mandar las palabras con el producto
|
| 133 |
if not isinstance(words_to_use, dict) and words_to_use:
|
| 134 |
+
use_product = current_product
|
| 135 |
+
use_words = words_to_use
|
| 136 |
break
|
| 137 |
|
| 138 |
# Si no hay producto que falta por calificar finalizar sesion para el Catador
|
| 139 |
+
if not use_product:
|
| 140 |
updated_participation = ParticipacionController.finishSession(
|
| 141 |
self.participation)
|
| 142 |
params = {
|
| 143 |
"code_sesion": self.session.codigo_sesion
|
| 144 |
}
|
| 145 |
+
return redirect(reverse(self.previus_directory, kwargs=params))
|
| 146 |
+
|
| 147 |
+
self.context["product"] = use_product
|
| 148 |
+
self.context["words"] = use_words
|
| 149 |
|
| 150 |
# Agregar informacion de la escala
|
| 151 |
scale = EscalaController.getScaleByTechnique(technique=technique)
|
tecnicas/controllers/views_controller/sessions_tester/init_session_tester_controller.py
CHANGED
|
@@ -2,7 +2,7 @@ from django.db import transaction
|
|
| 2 |
from django.http import HttpRequest
|
| 3 |
from django.shortcuts import render, redirect
|
| 4 |
from django.urls import reverse
|
| 5 |
-
from tecnicas.models import Catador, SesionSensorial, Orden, Participacion, Producto, EsAtributo, Calificacion, EsVocabulario
|
| 6 |
from tecnicas.controllers import ParticipacionController
|
| 7 |
from tecnicas.utils import controller_error, shuffleArray
|
| 8 |
|
|
@@ -125,8 +125,8 @@ class InitSessionTesterController():
|
|
| 125 |
|
| 126 |
# ////////////////////////////////////////////////////////////// #
|
| 127 |
#
|
| 128 |
-
#
|
| 129 |
-
# Si
|
| 130 |
# Ha terminado la repeticion
|
| 131 |
#
|
| 132 |
# ////////////////////////////////////////////////////////////// #
|
|
@@ -149,8 +149,11 @@ class InitSessionTesterController():
|
|
| 149 |
|
| 150 |
expected_ratings_repetition = num_products * num_words
|
| 151 |
|
| 152 |
-
num_ratings_now =
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
is_end = num_ratings_now >= expected_ratings_repetition
|
| 156 |
|
|
|
|
| 2 |
from django.http import HttpRequest
|
| 3 |
from django.shortcuts import render, redirect
|
| 4 |
from django.urls import reverse
|
| 5 |
+
from tecnicas.models import Catador, SesionSensorial, Orden, Participacion, Producto, EsAtributo, Calificacion, EsVocabulario, Dato
|
| 6 |
from tecnicas.controllers import ParticipacionController
|
| 7 |
from tecnicas.utils import controller_error, shuffleArray
|
| 8 |
|
|
|
|
| 125 |
|
| 126 |
# ////////////////////////////////////////////////////////////// #
|
| 127 |
#
|
| 128 |
+
# numero_datos_esperadas = num_productos * num_palabras
|
| 129 |
+
# Si numero_datos_esperadas es igual a numero_datos_actuales en la repetcion R
|
| 130 |
# Ha terminado la repeticion
|
| 131 |
#
|
| 132 |
# ////////////////////////////////////////////////////////////// #
|
|
|
|
| 149 |
|
| 150 |
expected_ratings_repetition = num_products * num_words
|
| 151 |
|
| 152 |
+
num_ratings_now = Dato.objects.filter(
|
| 153 |
+
id_calificacion__id_catador=self.tester,
|
| 154 |
+
id_calificacion__id_tecnica=technique,
|
| 155 |
+
id_calificacion__num_repeticion=technique.repeticion
|
| 156 |
+
).count()
|
| 157 |
|
| 158 |
is_end = num_ratings_now >= expected_ratings_repetition
|
| 159 |
|
tecnicas/models/calificacion.py
CHANGED
|
@@ -8,4 +8,7 @@ class Calificacion(models.Model):
|
|
| 8 |
num_repeticion = models.IntegerField()
|
| 9 |
id_producto = models.ForeignKey(Producto, on_delete=models.CASCADE, related_name="calificacion_producto")
|
| 10 |
id_tecnica = models.ForeignKey(Tecnica, on_delete=models.CASCADE, related_name="calificacion_tecnica")
|
| 11 |
-
id_catador = models.ForeignKey(Catador, on_delete=models.CASCADE, related_name="calificacion_catador")
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
num_repeticion = models.IntegerField()
|
| 9 |
id_producto = models.ForeignKey(Producto, on_delete=models.CASCADE, related_name="calificacion_producto")
|
| 10 |
id_tecnica = models.ForeignKey(Tecnica, on_delete=models.CASCADE, related_name="calificacion_tecnica")
|
| 11 |
+
id_catador = models.ForeignKey(Catador, on_delete=models.CASCADE, related_name="calificacion_catador")
|
| 12 |
+
|
| 13 |
+
def __str__(self):
|
| 14 |
+
return f"{self.id} - {self.id_tecnica.sesion_tecnica} - {self.num_repeticion} - {self.id_catador.user.username}"
|
tecnicas/models/dato.py
CHANGED
|
@@ -11,4 +11,4 @@ class Dato(models.Model):
|
|
| 11 |
Calificacion, on_delete=models.CASCADE, related_name="dato_calificacion")
|
| 12 |
|
| 13 |
def __str__(self):
|
| 14 |
-
return f"{self.id_calificacion.id_tecnica.sesion_tecnica} - {self.id_palabra.nombre_palabra} - {self.id_calificacion.id_producto.codigoProducto} - {self.id_calificacion.id_catador.user.username}"
|
|
|
|
| 11 |
Calificacion, on_delete=models.CASCADE, related_name="dato_calificacion")
|
| 12 |
|
| 13 |
def __str__(self):
|
| 14 |
+
return f"{self.id_calificacion.id_tecnica.sesion_tecnica}- {self.id_calificacion.num_repeticion} - {self.id_palabra.nombre_palabra} - {self.id_calificacion.id_producto.codigoProducto} - {self.id_calificacion.id_catador.user.username}"
|
tecnicas/models/dato_valor.py
CHANGED
|
@@ -9,7 +9,7 @@ class ValorDecimal(models.Model):
|
|
| 9 |
valor = models.FloatField()
|
| 10 |
|
| 11 |
def __str__(self):
|
| 12 |
-
return f"{self.id} - {self.id_dato.id_palabra}: {self.valor} - {self.id_dato.id_calificacion.id_catador.
|
| 13 |
|
| 14 |
|
| 15 |
class ValorBooleano(models.Model):
|
|
@@ -18,4 +18,4 @@ class ValorBooleano(models.Model):
|
|
| 18 |
valor = models.BooleanField()
|
| 19 |
|
| 20 |
def __str__(self):
|
| 21 |
-
return f"{self.id} - {self.id_dato.id_palabra}: {self.valor} - {self.id_dato.id_calificacion.id_catador.
|
|
|
|
| 9 |
valor = models.FloatField()
|
| 10 |
|
| 11 |
def __str__(self):
|
| 12 |
+
return f"{self.id} - {self.id_dato.id_palabra}: {self.valor} - {self.id_dato.id_calificacion.id_catador.user.username}"
|
| 13 |
|
| 14 |
|
| 15 |
class ValorBooleano(models.Model):
|
|
|
|
| 18 |
valor = models.BooleanField()
|
| 19 |
|
| 20 |
def __str__(self):
|
| 21 |
+
return f"{self.id} - {self.id_dato.id_palabra}: {self.valor} - {self.id_dato.id_calificacion.id_catador.user.username}"
|