Commit a0d43118a67c85ecb9f77ed11d8f4a6489b8fb5f

Authored by Felipe Bormann
1 parent 9727e86c

finished messages variables in report view and translation, started tests for such functionality

reports/locale/pt_BR/LC_MESSAGES/django.po
... ... @@ -8,7 +8,7 @@ msgid ""
8 8 msgstr ""
9 9 "Project-Id-Version: PACKAGE VERSION\n"
10 10 "Report-Msgid-Bugs-To: \n"
11   -"POT-Creation-Date: 2017-04-15 00:13-0300\n"
  11 +"POT-Creation-Date: 2017-04-29 21:14-0300\n"
12 12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13 13 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14 14 "Language-Team: LANGUAGE <LL@li.org>\n"
... ... @@ -18,287 +18,308 @@ msgstr &quot;&quot;
18 18 "Content-Transfer-Encoding: 8bit\n"
19 19 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
20 20  
21   -#: reports/forms.py:23
  21 +#: .\forms.py:23
22 22 msgid "Kind Of Resource"
23 23 msgstr "Tipo de recurso"
24 24  
25   -#: reports/forms.py:24
  25 +#: .\forms.py:24
26 26 msgid "Tag"
27 27 msgstr "Tag"
28 28  
29   -#: reports/forms.py:35
  29 +#: .\forms.py:35
30 30 msgid "Topics"
31 31 msgstr "Tópicos"
32 32  
33   -#: reports/forms.py:36 reports/templates/reports/view.html:58
  33 +#: .\forms.py:36 .\templates\reports\view.html:58
34 34 msgid "Initial Date"
35 35 msgstr "Data inicial"
36 36  
37   -#: reports/forms.py:37
  37 +#: .\forms.py:37
38 38 msgid "Final Date"
39 39 msgstr "Data Final"
40 40  
41   -#: reports/forms.py:39
  41 +#: .\forms.py:39
42 42 msgid "From Mural"
43 43 msgstr "Mural da disciplina"
44 44  
45   -#: reports/forms.py:40
  45 +#: .\forms.py:40
46 46 msgid "Messages"
47 47 msgstr "Mensagens"
48 48  
49   -#: reports/forms.py:51 reports/views.py:127 reports/views.py:198
  49 +#: .\forms.py:51 .\views.py:145 .\views.py:218
50 50 msgid "All"
51 51 msgstr "Todos"
52 52  
53   -#: reports/forms.py:60
  53 +#: .\forms.py:60
54 54 msgid "The initial date can't be after the end one."
55 55 msgstr "A data inicial não pode ser depois da final"
56 56  
57   -#: reports/forms.py:65
  57 +#: .\forms.py:65
58 58 msgid "This date should be right or after "
59 59 msgstr "Esta data deve ser igual ou após"
60 60  
61   -#: reports/forms.py:71
  61 +#: .\forms.py:71
62 62 msgid "This date should be right or before "
63 63 msgstr "Esta data deve ser igual ou anterior à"
64 64  
65   -#: reports/templates/reports/_form.html:19
  65 +#: .\templates\reports\_form.html:19
66 66 msgid "General Parameters"
67 67 msgstr "Escolha o Tópico e o Período"
68 68  
69   -#: reports/templates/reports/_form.html:37
  69 +#: .\templates\reports\_form.html:37
70 70 msgid "Choose the Data Source (is possible to pick more than one)"
71 71 msgstr "Escolha a fonte de dados (é possível escolher mais de uma)"
72 72  
73   -#: reports/templates/reports/_form.html:62
  73 +#: .\templates\reports\_form.html:62
74 74 msgid "Interaction with resources"
75 75 msgstr "Interação com recursos"
76 76  
77   -#: reports/templates/reports/_form.html:97
  77 +#: .\templates\reports\_form.html:97
78 78 msgid "Search Report"
79 79 msgstr "Buscar"
80 80  
81   -#: reports/templates/reports/create.html:27
82   -#: reports/templates/reports/view.html:33
  81 +#: .\templates\reports\create.html:27 .\templates\reports\view.html:33
83 82 msgid "Analytics"
84 83 msgstr ""
85 84  
86   -#: reports/templates/reports/create.html:37
87   -#: reports/templates/reports/view.html:43
  85 +#: .\templates\reports\create.html:36 .\templates\reports\view.html:43
88 86 msgid "Interaction Data"
89 87 msgstr "Dados de Interação"
90 88  
91   -#: reports/templates/reports/create.html:40
92   -#: reports/templates/reports/view.html:46
  89 +#: .\templates\reports\create.html:39 .\templates\reports\view.html:46
93 90 msgid "Report Card"
94 91 msgstr "Boletim do Tópico"
95 92  
96   -#: reports/templates/reports/create.html:43
97   -#: reports/templates/reports/view.html:49
  93 +#: .\templates\reports\create.html:42 .\templates\reports\view.html:49
98 94 msgid "Participation"
99 95 msgstr "Participações"
100 96  
101   -#: reports/templates/reports/create.html:55
  97 +#: .\templates\reports\create.html:55
102 98 msgid "add data source"
103 99 msgstr "Adicionar nova fonte de dados"
104 100  
105   -#: reports/templates/reports/create.html:56
  101 +#: .\templates\reports\create.html:56
106 102 msgid "remove data source"
107 103 msgstr "Remover esta fonte"
108 104  
109   -#: reports/templates/reports/view.html:56
  105 +#: .\templates\reports\view.html:56
110 106 msgid "Subject"
111 107 msgstr "Assunto"
112 108  
113   -#: reports/templates/reports/view.html:57
  109 +#: .\templates\reports\view.html:57
114 110 msgid "Topic"
115 111 msgstr "Tópico"
116 112  
117   -#: reports/templates/reports/view.html:59
  113 +#: .\templates\reports\view.html:59
118 114 msgid "End Date"
119 115 msgstr "Data final"
120 116  
121   -#: reports/templates/reports/view.html:60
  117 +#: .\templates\reports\view.html:60
122 118 msgid "new search"
123 119 msgstr "Nova Busca"
124 120  
125   -#: reports/templates/reports/view.html:66
  121 +#: .\templates\reports\view.html:66
126 122 msgid "register(s)"
127 123 msgstr "registro(s)"
128 124  
129   -#: reports/templates/reports/view.html:68
  125 +#: .\templates\reports\view.html:68
130 126 msgid "Interactions Data (.csv)"
131 127 msgstr "Dados de interação (.csv)"
132 128  
133   -#: reports/templates/reports/view.html:72
  129 +#: .\templates\reports\view.html:72
134 130 msgid "Interactions Data (.xls)"
135 131 msgstr "Dados de interação (.xls)"
136 132  
137   -#: reports/views.py:60
  133 +#: .\views.py:78
138 134 msgid "Report created successfully"
139 135 msgstr "Relatório criado com sucesso!"
140 136  
141   -#: reports/views.py:202
  137 +#: .\views.py:222
142 138 msgid "User"
143 139 msgstr ""
144 140  
145   -#: reports/views.py:222
  141 +#: .\views.py:245
146 142 msgid "Number of help posts created by the user."
147 143 msgstr "Número de postagens de dúvidas criadas no mural da disciplina."
148 144  
149   -#: reports/views.py:228
  145 +#: .\views.py:251
150 146 msgid "Amount of comments on help posts created by the student."
151 147 msgstr ""
152 148 "Número de comentários criados para as próprias postagens de dúvidas no mural "
153 149 "da disciplina."
154 150  
155   -#: reports/views.py:233
  151 +#: .\views.py:256
156 152 msgid "Amount of comments made by the student on teachers help posts."
157 153 msgstr ""
158 154 "Número de comentários às postagens de dúvidas no mural da disciplina criadas "
159 155 "pelo professor."
160 156  
161   -#: reports/views.py:237
  157 +#: .\views.py:260
162 158 msgid "Amount of comments made by the student on other students help posts."
163 159 msgstr ""
164 160 "Número de comentários às postagens de dúvidas no mural da disciplina criadas "
165 161 "por outros estudantes."
166 162  
167   -#: reports/views.py:248
  163 +#: .\views.py:271
168 164 msgid "Number of help posts created by the user that the teacher commented on."
169 165 msgstr ""
170 166 "Número de comentários às postagens de dúvidas no mural da disciplina criadas "
171 167 "por outros estudantes"
172 168  
173   -#: reports/views.py:256
  169 +#: .\views.py:279
174 170 msgid "Number of help posts created by the user others students commented on."
175 171 msgstr ""
176 172 " Número de postagens de dúvidas criadas no mural da disciplina que foram "
177 173 "comentadas por outros estudantes."
178 174  
179   -#: reports/views.py:259
  175 +#: .\views.py:282
180 176 msgid "Number of student visualizations on the mural of the subject."
181 177 msgstr "Número de visualizações do mural da disciplina."
182 178  
183   -#: reports/views.py:271
  179 +#: .\views.py:303
184 180 msgid "Number of access to mural between 6 a.m to 12a.m. ."
185 181 msgstr ""
186 182 "Número de acessos ao ambiente virtual da disciplina no horário de 06h às 12h."
187 183  
188   -#: reports/views.py:275
  184 +#: .\views.py:307
189 185 msgid "Number of access to mural between 0 p.m to 6p.m. ."
190 186 msgstr ""
191 187 "Número de acessos ao ambiente virtual da disciplina no horário de 12h às 18h."
192 188  
193   -#: reports/views.py:278
  189 +#: .\views.py:310
194 190 msgid "Number of access to mural between 6 p.m to 12p.m. ."
195 191 msgstr ""
196 192 "Número de acessos ao ambiente virtual da disciplina no horário de 18h às 24h."
197 193  
198   -#: reports/views.py:282
  194 +#: .\views.py:314
199 195 msgid "Number of access to mural between 0 a.m to 6a.m. ."
200 196 msgstr ""
201 197 "Número de acessos ao ambiente virtual da disciplina no horário de 24h às 06h."
202 198  
203   -#: reports/views.py:287
  199 +#: .\views.py:319
204 200 msgid "sunday"
205 201 msgstr "domingo"
206 202  
207   -#: reports/views.py:287
  203 +#: .\views.py:319
208 204 msgid "monday"
209 205 msgstr "segunda"
210 206  
211   -#: reports/views.py:287
  207 +#: .\views.py:319
212 208 msgid "tuesday"
213 209 msgstr "terça-feira"
214 210  
215   -#: reports/views.py:287
  211 +#: .\views.py:319
216 212 msgid "wednesday"
217 213 msgstr "quarta"
218 214  
219   -#: reports/views.py:287
  215 +#: .\views.py:319
220 216 msgid "thursday"
221 217 msgstr "quinta-feira"
222 218  
223   -#: reports/views.py:288
  219 +#: .\views.py:320
224 220 msgid "friday"
225 221 msgstr "sexta"
226 222  
227   -#: reports/views.py:288
  223 +#: .\views.py:320
228 224 msgid "saturday"
229 225 msgstr "sábado"
230 226  
231   -#: reports/views.py:292 reports/views.py:295
  227 +#: .\views.py:324 .\views.py:327
232 228 msgid "Number of access to the subject on "
233 229 msgstr "Número de acessos ao assunto na(o) "
234 230  
235   -#: reports/views.py:298
  231 +#: .\views.py:330
236 232 msgid "Number of distinct days the user access the subject. "
237 233 msgstr "Número de dias distintos que acessou o ambiente virtual da disciplina."
238 234  
239   -#: reports/views.py:299
  235 +#: .\views.py:331
240 236 msgid "Class"
241 237 msgstr "Classe"
242 238  
243   -#: reports/views.py:299 reports/views.py:300
  239 +#: .\views.py:331 .\views.py:332
244 240 msgid "Undefined"
245 241 msgstr "Indefinido"
246 242  
247   -#: reports/views.py:300
  243 +#: .\views.py:332
248 244 msgid "Performance"
249 245 msgstr "Desempenho"
250 246  
251   -#: reports/views.py:448 reports/views.py:498
  247 +#: .\views.py:482 .\views.py:583
252 248 msgid "PDF File"
253 249 msgstr ""
254 250  
255   -#: reports/views.py:449 reports/views.py:499
  251 +#: .\views.py:483 .\views.py:584
256 252 #, fuzzy
257 253 #| msgid "Topics"
258 254 msgid "Topic Goals"
259 255 msgstr "Tópicos"
260 256  
261   -#: reports/views.py:450 reports/views.py:500
  257 +#: .\views.py:484 .\views.py:585
262 258 msgid "Link to Website"
263 259 msgstr ""
264 260  
265   -#: reports/views.py:451 reports/views.py:501
  261 +#: .\views.py:485 .\views.py:586
266 262 msgid "File Link"
267 263 msgstr ""
268 264  
269   -#: reports/views.py:452 reports/views.py:502
  265 +#: .\views.py:486 .\views.py:587
270 266 msgid "Web Conference"
271 267 msgstr ""
272 268  
273   -#: reports/views.py:453 reports/views.py:503
  269 +#: .\views.py:487 .\views.py:588
274 270 msgid "YouTube Video"
275 271 msgstr ""
276 272  
277   -#: reports/views.py:454 reports/views.py:504
  273 +#: .\views.py:488 .\views.py:589
278 274 msgid "WebPage"
279 275 msgstr ""
280 276  
281   -#: reports/views.py:456 reports/views.py:463
  277 +#: .\views.py:490 .\views.py:497
282 278 msgid "number of visualizations of "
283 279 msgstr "Número de visualizações do(e) "
284 280  
285   -#: reports/views.py:456 reports/views.py:457 reports/views.py:458
286   -#: reports/views.py:461
  281 +#: .\views.py:490 .\views.py:491 .\views.py:492 .\views.py:495
287 282 msgid " with tag "
288 283 msgstr " com a tag "
289 284  
290   -#: reports/views.py:457 reports/views.py:464
  285 +#: .\views.py:491 .\views.py:498
291 286 msgid "number of visualizations of distintic "
292 287 msgstr "Número de visualizações dos distintos "
293 288  
294   -#: reports/views.py:458 reports/views.py:465
  289 +#: .\views.py:492 .\views.py:499
295 290 msgid "distintic days "
296 291 msgstr "número de dias distintos "
297 292  
298   -#: reports/views.py:461 reports/views.py:468
  293 +#: .\views.py:495 .\views.py:502
299 294 msgid "hours viewed of "
300 295 msgstr "quantidade de horas vistas "
301 296  
  297 +#: .\views.py:522 .\views.py:523 .\views.py:525
  298 +msgid " amount of messages sent to other students"
  299 +msgstr " quantidade mensagens enviadas para outros estudantes"
  300 +
  301 +#: .\views.py:527 .\views.py:528 .\views.py:531
  302 +msgid "amount of messages received from other students"
  303 +msgstr "quantidade de mensagens recebidas de outros estudantes"
  304 +
  305 +#: .\views.py:537
  306 +msgid "amount of distinct students to whom sent messages"
  307 +msgstr "quantidade de estudantes distintos para quem enviou mensagem"
  308 +
  309 +#: .\views.py:546 .\views.py:547 .\views.py:549
  310 +msgid "amount messages sent to professors"
  311 +msgstr "quantidade mensagens enviadas para o(s) professor(es)"
  312 +
  313 +#: .\views.py:551 .\views.py:552 .\views.py:554
  314 +msgid "amount of messages received from professors"
  315 +msgstr "quantidade de mensagens recebidas do(s) professor(es)"
  316 +
  317 +#~ msgid " amount messages sent to other students"
  318 +#~ msgstr " número de mensagens enviadas para outros estudantes"
  319 +
  320 +#~ msgid " amount of messages sent to others students"
  321 +#~ msgstr " número de mensagens enviadas para outros estudantes"
  322 +
302 323 #~ msgid "distintic "
303 324 #~ msgstr "distintos "
304 325  
... ...
reports/tests.py
1   -from django.test import TestCase
2   -
3   -# Create your tests here.
  1 +from django.test import TestCase
4 2 \ No newline at end of file
... ...
reports/tests/test_report_auth.py
... ... @@ -3,8 +3,12 @@ from django.core.urlresolvers import resolve
3 3 from reports.views import ReportView
4 4 from subjects.models import Subject
5 5 from users.models import User
6   -
  6 +from topics.models import Topic
  7 +from chat.models import Conversation, TalkMessages
7 8 from datetime import datetime
  9 +from log.models import Log
  10 +from django.db.models import Q
  11 +
8 12  
9 13 class ReportTest(TestCase):
10 14  
... ... @@ -42,4 +46,29 @@ class ReportTest(TestCase):
42 46 report_view = self.c.get('/subjects/report/create/interactions/?subject_id='+ str(self.subject.id))
43 47  
44 48 self.assertEqual(report_view.url, "/subjects/home/")
45   -
46 49 \ No newline at end of file
  50 +
  51 +
  52 + @override_settings(STATICFILES_STORAGE = None)
  53 + def test_message_data_from_view(self):
  54 + """
  55 + test if I'm capturing the message data correctly in all scenarios
  56 + """
  57 +
  58 + #scenario 01: the number of messages a student receives from other students
  59 + topic = Topic.objects.create(name="novo topico", subject= self.subject, visible = True)
  60 + topic.save()
  61 + student02 = User.objects.create(username="student02", email= "student02@gmail.com", password="amadeus")
  62 + student02.save()
  63 + conversation_01 = Conversation.objects.create(user_one = self.student, user_two = student02)
  64 +
  65 + #building messages
  66 + message01 = TalkMessages(text="hi", talk = conversation_01, subject = self.subject, user = self.student)
  67 + message01.save()
  68 + message02 = TalkMessages(text="hello, how are you?", talk = conversation_01, subject = self.subject, user = student02)
  69 + message02.save()
  70 + #get all conversations where a student of the subject is in and the amount of messages the hey sent to other students
  71 + conversations = Conversation.objects.filter(Q(user_one = self.student) | Q(user_two = self.student) )
  72 +
  73 + amount_of_messages = TalkMessages.objects.filter(talk__in= conversations).count()
  74 + print(amount_of_messages)
  75 + self.assertEqual(3,3)
47 76 \ No newline at end of file
... ...
reports/views.py
... ... @@ -26,6 +26,9 @@ import os
26 26 import copy
27 27 from django.shortcuts import render, get_object_or_404, redirect
28 28  
  29 +from chat.models import Conversation, TalkMessages
  30 +
  31 +
29 32 from amadeus.permissions import has_category_permissions, has_subject_permissions
30 33  
31 34 class ReportView(LoginRequiredMixin, generic.FormView):
... ... @@ -146,15 +149,17 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
146 149 context['init_date'] = params_data['init_date']
147 150 context['end_date'] = params_data['end_date']
148 151 context['subject'] = subject
  152 +
149 153  
150 154 #I used getlist method so it can get more than one tag and one resource class_name
151 155 resources = params_data.getlist('resource')
152 156 tags = params_data.getlist('tag')
153 157  
154 158 self.from_mural = params_data['from_mural']
155   -
  159 + self.from_messages = params_data['from_messages']
  160 +
156 161 context['data'], context['header'] = self.get_mural_data(subject, params_data['topic'], params_data['init_date'], params_data['end_date'],
157   - resources, tags )
  162 + resources, tags )
158 163  
159 164  
160 165 #this is to save the csv for further download
... ... @@ -226,8 +231,11 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
226 231  
227 232 data[student.id].append(student.social_name)
228 233  
229   - interactions = OrderedDict()
230   -
  234 + interactions = OrderedDict()
  235 +
  236 +
  237 +
  238 +
231 239 #interactions['username'] = student.social_name
232 240 if self.from_mural == "True":
233 241 help_posts_made_by_user = SubjectPost.objects.filter(action="help",space__id=subject.id, user=student,
... ... @@ -275,6 +283,15 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
275 283 user = student).count()
276 284  
277 285  
  286 + #variables from messages
  287 +
  288 +
  289 + if self.from_messages == "True":
  290 +
  291 + message_data = self.get_messages_data(subject, student)
  292 + for key, value in message_data.items():
  293 + interactions[key] = value
  294 +
278 295 #VAR08 through VAR_019 of documenttation:
279 296 if len(resources_type_names) > 0:
280 297 resources_data = self.get_resources_and_tags_data(resources_type_names, tags_id, student, subject, topics, init_date, end_date)
... ... @@ -376,7 +393,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
376 393 for resource in resources:
377 394  
378 395 if isinstance(topics,Topic):
379   - #or it selected only one topic to work with
  396 + #if it selected only one topic to work with
380 397 count = Log.objects.filter(action="view", resource=resources_types[i].lower(),
381 398 user_id = student.id, context__contains = {'subject_id': subject.id,
382 399 resources_types[i].lower()+'_id': resource.id, 'topic_id': topics.id}, datetime__range=(init_date, end_date)).count()
... ... @@ -452,6 +469,8 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
452 469 time_delta = math.fabs(end_time - begin_time)
453 470  
454 471 hours_viewed += time_delta/3600 #so it's turned this seconds into hours
  472 +
  473 +
455 474 if count > 0:
456 475 distinct_resources += 1
457 476 total_count += count
... ... @@ -484,15 +503,66 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
484 503  
485 504 return data
486 505  
  506 + def get_messages_data(self, subject, student):
  507 + data = OrderedDict()
  508 +
  509 +
  510 +
  511 + messages_sent_to_other_students = 0
  512 +
  513 + distinct_students = 0
  514 +
  515 + for other_student in subject.students.exclude(id = student.id):
  516 + conversations_with_other = Conversation.objects.filter(Q(user_one=student) & Q(user_two = other_student) | Q(user_one = other_student) & Q(user_two = student) )
  517 + messages_sent_other = TalkMessages.objects.filter(talk__in = conversations_with_other, user = student , subject= subject)
  518 + messages_received_other = TalkMessages.objects.filter(talk__in = conversations_with_other, user = other_student, subject = subject)
  519 +
  520 +
  521 +
  522 + if data.get(_(" amount of messages sent to other students")):
  523 + data[_(" amount of messages sent to other students")] = messages_sent_other.count() + data.get(_(" amount of messages sent to other students"))
  524 + else:
  525 + data[_(" amount of messages sent to other students")] = messages_sent_other.count()
  526 +
  527 + if data.get(_("amount of messages received from other students")):
  528 + data[_("amount of messages received from other students")] = messages_received_other.count() + data.get(_("amount of messages received from other students"))
  529 + else:
  530 +
  531 + data[_("amount of messages received from other students")] = messages_received_other.count()
  532 +
  533 + #check whether the other started a conversation or not
  534 + if messages_sent_other.count() >0:
  535 + distinct_students += 1
  536 +
  537 + data[_("amount of distinct students to whom sent messages")] = distinct_students
  538 + #calculate the amount of messages sent to and received from professor
  539 + messages_sent_professors = 0
  540 + messages_received_professors = 0
  541 + for professor in subject.professor.all():
  542 + conversations_with_professor = Conversation.objects.filter(Q(user_one = student) & Q(user_two = professor) | Q(user_one = professor) & Q(user_two = student))
  543 + messages_sent_to_professors = TalkMessages.objects.filter(talk__in = conversations_with_professor, user = student, subject = subject)
  544 +
  545 + messages_received_from_professors = TalkMessages.objects.filter(talk__in = conversations_with_professor, user = professor, subject = subject)
  546 + if data.get(_("amount messages sent to professors")):
  547 + data[_("amount messages sent to professors")] = messages_sent_to_professors.count() + data.get(_("amount messages sent to professors"))
  548 + else:
  549 + data[_("amount messages sent to professors")] = messages_sent_to_professors.count()
  550 +
  551 + if data.get(_("amount of messages received from professors")):
  552 + data[_("amount of messages received from professors")] = messages_received_from_professors.count() + data.get(_("amount of messages received from professors"))
  553 + else:
  554 + data[_("amount of messages received from professors")] = messages_received_from_professors.count()
  555 +
  556 +
  557 + return data
  558 +
487 559  
488 560 """
489 561 Get all possible resource subclasses available for that topic selected
490 562 """
491 563 def get_resources(request):
492 564  
493   - #get all possible resources
494   - classes = Resource.__subclasses__()
495   - data = {}
  565 + #get all possible resources
496 566 subject = Subject.objects.get(id=request.GET['subject_id'])
497 567  
498 568 topic_choice = request.GET["topic_choice"]
... ...