Spaces:
Sleeping
Sleeping
Calificacion en Fase 3 de PF por Catadores
Browse files- tecnicas/controllers/api_controller/rating_pf_list_controller.py +79 -1
- tecnicas/controllers/views_controller/session_management/details_pf_controller.py +2 -1
- tecnicas/static/js/test_pf_rating_list.js +33 -32
- tecnicas/templates/tecnicas/forms_tester/test_pf_rating_list.html +5 -5
- tecnicas/templates/tecnicas/manage_sesions/details-session-pf.html +11 -2
- tecnicas/views/apis/api_list_words_pf.py +10 -3
tecnicas/controllers/api_controller/rating_pf_list_controller.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from django.http import JsonResponse, HttpRequest
|
| 2 |
from django.db import transaction, IntegrityError
|
| 3 |
-
from tecnicas.models import Palabra, ListaPalabras, Participacion
|
| 4 |
from tecnicas.forms import ListWordsForm
|
| 5 |
|
| 6 |
|
|
@@ -141,3 +141,81 @@ class RatingPFListController():
|
|
| 141 |
list_tester.palabras.set(all_new_words)
|
| 142 |
|
| 143 |
return all_new_words
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from django.http import JsonResponse, HttpRequest
|
| 2 |
from django.db import transaction, IntegrityError
|
| 3 |
+
from tecnicas.models import Palabra, ListaPalabras, Participacion, Calificacion, Producto, Dato, ValorDecimal
|
| 4 |
from tecnicas.forms import ListWordsForm
|
| 5 |
|
| 6 |
|
|
|
|
| 141 |
list_tester.palabras.set(all_new_words)
|
| 142 |
|
| 143 |
return all_new_words
|
| 144 |
+
|
| 145 |
+
@staticmethod
|
| 146 |
+
def saveRatings(request: HttpRequest, word_rating: str, data: list):
|
| 147 |
+
participation = Participacion.objects.get(
|
| 148 |
+
id=request.session["id_participation"])
|
| 149 |
+
|
| 150 |
+
technique = participation.tecnica
|
| 151 |
+
products = Producto.objects.filter(id_tecnica=technique)
|
| 152 |
+
|
| 153 |
+
# Crear o obtener las instancias Calificacion en la repeticion de todos los producutos
|
| 154 |
+
ratings = Calificacion.objects.filter(
|
| 155 |
+
num_repeticion=technique.repeticion,
|
| 156 |
+
id_tecnica=technique,
|
| 157 |
+
id_catador=participation.catador,
|
| 158 |
+
id_producto__in=products
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
existing_dict = {rating.id_producto_id: rating for rating in ratings}
|
| 162 |
+
to_create = []
|
| 163 |
+
|
| 164 |
+
for product in products:
|
| 165 |
+
if product.id not in existing_dict:
|
| 166 |
+
to_create.append(
|
| 167 |
+
Calificacion(
|
| 168 |
+
num_repeticion=technique.repeticion,
|
| 169 |
+
id_producto=product,
|
| 170 |
+
id_tecnica=technique,
|
| 171 |
+
id_catador=participation.catador
|
| 172 |
+
)
|
| 173 |
+
)
|
| 174 |
+
Calificacion.objects.bulk_create(to_create)
|
| 175 |
+
|
| 176 |
+
ratings = Calificacion.objects.filter(
|
| 177 |
+
num_repeticion=technique.repeticion,
|
| 178 |
+
id_tecnica=technique,
|
| 179 |
+
id_catador=participation.catador,
|
| 180 |
+
id_producto__in=products
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
# Guardar datos con ValorDecimal
|
| 184 |
+
word = Palabra.objects.get(nombre_palabra=word_rating)
|
| 185 |
+
try:
|
| 186 |
+
if (
|
| 187 |
+
len(data) != len(products) or
|
| 188 |
+
len(data) != len(ratings) or
|
| 189 |
+
len(products) != len(ratings)
|
| 190 |
+
):
|
| 191 |
+
raise ValueError(
|
| 192 |
+
"Al parecer los datos mandados no corresponden con el total de productos")
|
| 193 |
+
|
| 194 |
+
product_values = {info["product"]["code"]: info["value"] for info in data}
|
| 195 |
+
|
| 196 |
+
datos_to_create = []
|
| 197 |
+
values_to_create = []
|
| 198 |
+
|
| 199 |
+
with transaction.atomic():
|
| 200 |
+
for rating in ratings:
|
| 201 |
+
datos_to_create.append(Dato(
|
| 202 |
+
id_palabra=word,
|
| 203 |
+
id_calificacion=rating
|
| 204 |
+
))
|
| 205 |
+
|
| 206 |
+
datos_save = Dato.objects.bulk_create(datos_to_create)
|
| 207 |
+
save_data = Dato.objects.filter(id_palabra=word, id_calificacion__in=ratings)
|
| 208 |
+
|
| 209 |
+
for data_save in save_data:
|
| 210 |
+
values_to_create.append(ValorDecimal(
|
| 211 |
+
id_dato=data_save,
|
| 212 |
+
valor=product_values.get(data_save.id_calificacion.id_producto.codigoProducto)
|
| 213 |
+
))
|
| 214 |
+
|
| 215 |
+
ValorDecimal.objects.bulk_create(values_to_create)
|
| 216 |
+
|
| 217 |
+
return JsonResponse({"message": "Calificaciones guardadas con exito"})
|
| 218 |
+
except ValueError as e:
|
| 219 |
+
error_message = str(e)
|
| 220 |
+
print(f"Error de calificacion: {error_message}")
|
| 221 |
+
return JsonResponse({"error": error_message})
|
tecnicas/controllers/views_controller/session_management/details_pf_controller.py
CHANGED
|
@@ -23,7 +23,8 @@ class DetallesPFController(DetallesController):
|
|
| 23 |
"calificaciones": [],
|
| 24 |
"existen_calificaciones": False,
|
| 25 |
"tipo_escala": technique.escala_tecnica.id_tipo_escala.nombre_escala,
|
| 26 |
-
"valor_max": technique.escala_tecnica.longitud
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
# Definir el estado de la sesion
|
|
|
|
| 23 |
"calificaciones": [],
|
| 24 |
"existen_calificaciones": False,
|
| 25 |
"tipo_escala": technique.escala_tecnica.id_tipo_escala.nombre_escala,
|
| 26 |
+
"valor_max": technique.escala_tecnica.longitud,
|
| 27 |
+
"repeticiones_max": technique.repeticiones_max - 2
|
| 28 |
}
|
| 29 |
|
| 30 |
# Definir el estado de la sesion
|
tecnicas/static/js/test_pf_rating_list.js
CHANGED
|
@@ -45,8 +45,11 @@ document.getElementById("save-data").addEventListener("click", async () => {
|
|
| 45 |
|
| 46 |
children.forEach((el) => {
|
| 47 |
currentDataRatend.push({
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
});
|
| 51 |
});
|
| 52 |
});
|
|
@@ -71,40 +74,38 @@ async function saveData(dataToSend = []) {
|
|
| 71 |
|
| 72 |
const requestData = {
|
| 73 |
phase: parseInt(document.querySelector(".cts-phase-pf").dataset.phase),
|
| 74 |
-
word: document.querySelector(".cts-
|
| 75 |
data: dataToSend,
|
| 76 |
};
|
| 77 |
|
| 78 |
-
console.log(requestData);
|
| 79 |
-
|
| 80 |
try {
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
const containerRatings = document.querySelector(".container-rating-word");
|
| 109 |
containerRatings.innerHTML = "";
|
| 110 |
containerRatings.innerHTML = nextProduct;
|
|
|
|
| 45 |
|
| 46 |
children.forEach((el) => {
|
| 47 |
currentDataRatend.push({
|
| 48 |
+
product: {
|
| 49 |
+
id: el.dataset.idProduct,
|
| 50 |
+
code: el.dataset.code,
|
| 51 |
+
},
|
| 52 |
+
value: index,
|
| 53 |
});
|
| 54 |
});
|
| 55 |
});
|
|
|
|
| 74 |
|
| 75 |
const requestData = {
|
| 76 |
phase: parseInt(document.querySelector(".cts-phase-pf").dataset.phase),
|
| 77 |
+
word: document.querySelector(".cts-word-rating").dataset.nameWord,
|
| 78 |
data: dataToSend,
|
| 79 |
};
|
| 80 |
|
|
|
|
|
|
|
| 81 |
try {
|
| 82 |
+
const response = await fetch(URL, {
|
| 83 |
+
method: "POST",
|
| 84 |
+
headers: {
|
| 85 |
+
"Content-Type": "application/json",
|
| 86 |
+
"X-CSRFToken": csrfToken,
|
| 87 |
+
"X-Requested-With": "XMLHttpRequest",
|
| 88 |
+
},
|
| 89 |
+
body: JSON.stringify(requestData),
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
if (!response.ok) {
|
| 93 |
+
spanNotifaction("Fallo con la respuesta recibida");
|
| 94 |
+
cancelLoading();
|
| 95 |
+
return false;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
const result = await response.json();
|
| 99 |
+
|
| 100 |
+
const messError = result.error;
|
| 101 |
+
|
| 102 |
+
if (messError) {
|
| 103 |
+
spanNotifaction(messError);
|
| 104 |
+
cancelLoading();
|
| 105 |
+
return false;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
spanNotifaction(result.message, false);
|
| 109 |
const containerRatings = document.querySelector(".container-rating-word");
|
| 110 |
containerRatings.innerHTML = "";
|
| 111 |
containerRatings.innerHTML = nextProduct;
|
tecnicas/templates/tecnicas/forms_tester/test_pf_rating_list.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
| 6 |
|
| 7 |
{% block content %}
|
| 8 |
<article class="cts-container-main">
|
| 9 |
-
<article class="cts-wrap-content text-black">
|
| 10 |
<header class="text-center flex-row w-full items-stretch flex justify-around flex-wrap gap-2">
|
| 11 |
<h1 class="rounded font-bold text-2xl bg-surface-ligt p-4 flex-1">
|
| 12 |
Sesión usando <br>técnica
|
|
@@ -61,12 +61,12 @@
|
|
| 61 |
</section>
|
| 62 |
|
| 63 |
<section class="flex items-center justify-center flex-wrap gap-4">
|
| 64 |
-
<div class="bg-surface-
|
| 65 |
<p class="text-lg font-bold text-center">
|
| 66 |
El atributo que se está evaluando:
|
| 67 |
</p>
|
| 68 |
-
<p class="word-rating text-2xl font-bold text-center" data-name-word="{{ word }}">
|
| 69 |
-
{{ word }}
|
| 70 |
</p>
|
| 71 |
</div>
|
| 72 |
</section>
|
|
@@ -78,7 +78,7 @@
|
|
| 78 |
<div id="items" class="flex gap-4 flex-wrap justify-center">
|
| 79 |
{% for product in products %}
|
| 80 |
<div class="draggable bg-surface-sweet text-black font-bold px-4 py-2 rounded cursor-grab"
|
| 81 |
-
draggable="true" data-code="{{ product.codigoProducto }}">{{ product.codigoProducto }}</div>
|
| 82 |
{% endfor %}
|
| 83 |
</div>
|
| 84 |
|
|
|
|
| 6 |
|
| 7 |
{% block content %}
|
| 8 |
<article class="cts-container-main">
|
| 9 |
+
<article class="cts-wrap-content text-black max-w-4xl">
|
| 10 |
<header class="text-center flex-row w-full items-stretch flex justify-around flex-wrap gap-2">
|
| 11 |
<h1 class="rounded font-bold text-2xl bg-surface-ligt p-4 flex-1">
|
| 12 |
Sesión usando <br>técnica
|
|
|
|
| 61 |
</section>
|
| 62 |
|
| 63 |
<section class="flex items-center justify-center flex-wrap gap-4">
|
| 64 |
+
<div class="bg-surface-card p-2 rounded-lg flex-1">
|
| 65 |
<p class="text-lg font-bold text-center">
|
| 66 |
El atributo que se está evaluando:
|
| 67 |
</p>
|
| 68 |
+
<p class="cts-word-rating text-2xl font-bold text-center" data-name-word="{{ word }}">
|
| 69 |
+
"{{ word }}"
|
| 70 |
</p>
|
| 71 |
</div>
|
| 72 |
</section>
|
|
|
|
| 78 |
<div id="items" class="flex gap-4 flex-wrap justify-center">
|
| 79 |
{% for product in products %}
|
| 80 |
<div class="draggable bg-surface-sweet text-black font-bold px-4 py-2 rounded cursor-grab"
|
| 81 |
+
draggable="true" data-id-product="{{ product.id }}" data-code="{{ product.codigoProducto }}">{{ product.codigoProducto }}</div>
|
| 82 |
{% endfor %}
|
| 83 |
</div>
|
| 84 |
|
tecnicas/templates/tecnicas/manage_sesions/details-session-pf.html
CHANGED
|
@@ -90,6 +90,13 @@
|
|
| 90 |
</p>
|
| 91 |
</section>
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
<section
|
| 94 |
class="col-span-2 max-sm:col-span-1 bg-surface-card flex flex-wrap items-center justify-center max-sm:justify-normal gap-x-2 p-4 rounded-2xl">
|
| 95 |
<p class="font-bold">
|
|
@@ -243,8 +250,10 @@
|
|
| 243 |
{% endblock %}
|
| 244 |
|
| 245 |
{% block extra_js %}
|
| 246 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js" crossorigin="anonymous"
|
| 247 |
-
|
|
|
|
|
|
|
| 248 |
<script src="{% static 'js/download-table-zip.js' %}"></script>
|
| 249 |
<script src="{% static 'js/details-session.js' %}"></script>
|
| 250 |
<script src="{% static 'js/showHiddenElement.js' %}"></script>
|
|
|
|
| 90 |
</p>
|
| 91 |
</section>
|
| 92 |
|
| 93 |
+
<section
|
| 94 |
+
class="bg-surface-card flex flex-wrap items-center justify-center max-sm:justify-normal gap-x-2 p-4 rounded-2xl">
|
| 95 |
+
<p class="font-sans">
|
| 96 |
+
<b>Repeticiones Max.</b> {{ repeticiones_max }}
|
| 97 |
+
</p>
|
| 98 |
+
</section>
|
| 99 |
+
|
| 100 |
<section
|
| 101 |
class="col-span-2 max-sm:col-span-1 bg-surface-card flex flex-wrap items-center justify-center max-sm:justify-normal gap-x-2 p-4 rounded-2xl">
|
| 102 |
<p class="font-bold">
|
|
|
|
| 250 |
{% endblock %}
|
| 251 |
|
| 252 |
{% block extra_js %}
|
| 253 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js" crossorigin="anonymous"
|
| 254 |
+
referrerpolicy="no-referrer"></script>
|
| 255 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js" crossorigin="anonymous"
|
| 256 |
+
referrerpolicy="no-referrer"></script>
|
| 257 |
<script src="{% static 'js/download-table-zip.js' %}"></script>
|
| 258 |
<script src="{% static 'js/details-session.js' %}"></script>
|
| 259 |
<script src="{% static 'js/showHiddenElement.js' %}"></script>
|
tecnicas/views/apis/api_list_words_pf.py
CHANGED
|
@@ -10,11 +10,18 @@ def apiListWordsPF(req: HttpRequest):
|
|
| 10 |
elif req.method == "POST":
|
| 11 |
try:
|
| 12 |
data = json.loads(req.body.decode("utf-8"))
|
| 13 |
-
raw_words = data.get("words", [])
|
| 14 |
phase = data.get("phase", [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
response = RatingPFListController.saveList(
|
| 17 |
-
request=req, current_phase=phase, words=raw_words)
|
| 18 |
return response
|
| 19 |
except Exception as e:
|
| 20 |
print("Error:", e)
|
|
|
|
| 10 |
elif req.method == "POST":
|
| 11 |
try:
|
| 12 |
data = json.loads(req.body.decode("utf-8"))
|
|
|
|
| 13 |
phase = data.get("phase", [])
|
| 14 |
+
if phase == 1 or phase == 2:
|
| 15 |
+
raw_words = data.get("words", [])
|
| 16 |
+
response = RatingPFListController.saveList(
|
| 17 |
+
request=req, current_phase=phase, words=raw_words)
|
| 18 |
+
|
| 19 |
+
elif phase >= 3:
|
| 20 |
+
word = data.get("word", [])
|
| 21 |
+
raw_data = data.get("data", [])
|
| 22 |
+
response = RatingPFListController.saveRatings(
|
| 23 |
+
request=req, word_rating=word, data=raw_data)
|
| 24 |
|
|
|
|
|
|
|
| 25 |
return response
|
| 26 |
except Exception as e:
|
| 27 |
print("Error:", e)
|