chartManD commited on
Commit
90a585d
·
1 Parent(s): be6f7ef

Mostrando datos de sesion con nappgin modalidad perfil ultra flash

Browse files
tecnicas/controllers/views_controller/session_management/details/details_napping_controller.py CHANGED
@@ -21,7 +21,7 @@ class DetallesNappingController(DetallesController):
21
 
22
  self.defineStatus()
23
  self.setIsEndSession()
24
- self.setDataTableNoMode()
25
 
26
  return self.context
27
 
@@ -77,7 +77,7 @@ class DetallesNappingController(DetallesController):
77
  return redirect(
78
  reverse(self.url_next, kwargs=parameters))
79
 
80
- def setDataTableNoMode(self):
81
  participations = Participacion.objects.filter(
82
  tecnica=self.session.tecnica).select_related("catador")
83
  testers = [participation.catador for participation in participations]
@@ -109,8 +109,44 @@ class DetallesNappingController(DetallesController):
109
  self.context["coordinates_no_mode"] = defaultdict_to_dict(
110
  coordinates_by_product)
111
 
 
 
 
 
 
112
  self.context["there_data"] = True
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  def setIsEndSession(self):
115
  if not self.session.activo and self.session.tecnica.repeticion < 1:
116
  self.context["finished"] = False
 
21
 
22
  self.defineStatus()
23
  self.setIsEndSession()
24
+ self.setDataTable()
25
 
26
  return self.context
27
 
 
77
  return redirect(
78
  reverse(self.url_next, kwargs=parameters))
79
 
80
+ def setDataTable(self):
81
  participations = Participacion.objects.filter(
82
  tecnica=self.session.tecnica).select_related("catador")
83
  testers = [participation.catador for participation in participations]
 
109
  self.context["coordinates_no_mode"] = defaultdict_to_dict(
110
  coordinates_by_product)
111
 
112
+ # Add word frequency data for perfil ultra flash mode
113
+ mod = TecnicaModalidad.objects.get(tecnica=self.session.tecnica)
114
+ if mod.modalidad.nombre == "perfil ultra flash":
115
+ self.setWordFrequencies(ratings)
116
+
117
  self.context["there_data"] = True
118
 
119
+ def setWordFrequencies(self, ratings):
120
+ from collections import Counter
121
+
122
+ # Prefetch palabras to optimize queries
123
+ ratings_with_words = ratings.prefetch_related('palabras').select_related('id_producto')
124
+
125
+ # Dictionary to store word frequencies by product
126
+ word_frequencies_by_product = defaultdict(Counter)
127
+ all_words_set = set()
128
+
129
+ for rating in ratings_with_words:
130
+ producto_code = rating.id_producto.codigoProducto
131
+ words = rating.palabras.all()
132
+
133
+ for word in words:
134
+ word_name = word.nombre_palabra
135
+ word_frequencies_by_product[producto_code][word_name] += 1
136
+ all_words_set.add(word_name)
137
+
138
+ # Convert Counter objects to regular dicts and sort words alphabetically
139
+ word_frequencies_dict = {
140
+ product: dict(frequencies)
141
+ for product, frequencies in word_frequencies_by_product.items()
142
+ }
143
+
144
+ # Sort all words alphabetically for consistent column ordering
145
+ all_words_sorted = sorted(all_words_set)
146
+
147
+ self.context["word_frequencies"] = word_frequencies_dict
148
+ self.context["all_words"] = all_words_sorted
149
+
150
  def setIsEndSession(self):
151
  if not self.session.activo and self.session.tecnica.repeticion < 1:
152
  self.context["finished"] = False
tecnicas/templates/tecnicas/components/table-napping-puf.html ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% load custom_filters %}
2
+ <article class="space-y-4 text-black">
3
+ <h2 class="font-bold text-xl text-center">
4
+ Datos de Napping con Perfil Ultra Flash
5
+ </h2>
6
+
7
+ <div class="overflow-x-auto rounded-lg border border-surface-general">
8
+ <table id="generic-donwload-table" class="min-w-max w-full text-sm text-center border-collapse">
9
+ <thead class="bg-surface-sweet font-semibold">
10
+ <tr>
11
+ <th class="py-2 px-3 border border-surface-general">Producto</th>
12
+ {% for tester in testers %}
13
+ <th class="py-2 px-3 border border-surface-general uppercase">
14
+ X{{ forloop.counter }}
15
+ </th>
16
+ <th class="py-2 px-3 border border-surface-general uppercase">
17
+ Y{{ forloop.counter }}
18
+ </th>
19
+ {% endfor %}
20
+ {% for word in all_words %}
21
+ <th class="py-2 px-3 border border-surface-general capitalize">
22
+ {{ word }}
23
+ </th>
24
+ {% endfor %}
25
+ </tr>
26
+ </thead>
27
+ <tbody class="bg-surface-ligt divide-y divide-gray-200">
28
+ {% for product, coordinates_tester in coordinates_no_mode.items %}
29
+ <tr>
30
+ <td class="py-2 px-3 border border-surface-general">{{ product }}</td>
31
+ {% for tester in testers %}
32
+ {% with points=coordinates_tester|get_item:tester.user.username %}
33
+ <td class="py-2 px-3 border border-surface-general">
34
+ {{ points.px }}
35
+ </td>
36
+ <td class="py-2 px-3 border border-surface-general">
37
+ {{ points.py }}
38
+ </td>
39
+ {% endwith %}
40
+ {% endfor %}
41
+ {% for word in all_words %}
42
+ {% with word_freq=word_frequencies|get_item:product|get_item:word %}
43
+ <td class="py-2 px-3 border border-surface-general">
44
+ {% if word_freq %}{{ word_freq }}{% else %}0{% endif %}
45
+ </td>
46
+ {% endwith %}
47
+ {% endfor %}
48
+ </tr>
49
+ {% endfor %}
50
+ </tbody>
51
+ </table>
52
+ </div>
53
+ </article>
tecnicas/templates/tecnicas/manage_sesions/details-session-napping.html CHANGED
@@ -192,7 +192,11 @@
192
  </p>
193
 
194
  {% if there_data %}
 
 
 
195
  {% include "../components/table-napping-no-mode.html" with testers=testers coordinates_no_mode=coordinates_no_mode %}
 
196
  {% else %}
197
  {% include "../components/error-message.html" with message='Sin datos por mostrar aún' %}
198
  {% endif %}
 
192
  </p>
193
 
194
  {% if there_data %}
195
+ {% if mode == "perfil ultra flash" %}
196
+ {% include "../components/table-napping-puf.html" with testers=testers coordinates_no_mode=coordinates_no_mode word_frequencies=word_frequencies all_words=all_words %}
197
+ {% else %}
198
  {% include "../components/table-napping-no-mode.html" with testers=testers coordinates_no_mode=coordinates_no_mode %}
199
+ {% endif %}
200
  {% else %}
201
  {% include "../components/error-message.html" with message='Sin datos por mostrar aún' %}
202
  {% endif %}