Commit efa55063368fb8c133dde4b757bb09d48adf0d3d
1 parent
50c34f8b
Exists in
master
and in
3 other branches
added webconference hours view of log into report, correctly
Showing
1 changed file
with
32 additions
and
2 deletions
Show diff stats
reports/views.py
| @@ -20,6 +20,7 @@ from collections import OrderedDict | @@ -20,6 +20,7 @@ from collections import OrderedDict | ||
| 20 | from django.forms import formset_factory | 20 | from django.forms import formset_factory |
| 21 | from .models import ReportCSV, ReportXLS | 21 | from .models import ReportCSV, ReportXLS |
| 22 | import pandas as pd | 22 | import pandas as pd |
| 23 | +import math | ||
| 23 | from io import BytesIO | 24 | from io import BytesIO |
| 24 | 25 | ||
| 25 | class ReportView(LoginRequiredMixin, generic.FormView): | 26 | class ReportView(LoginRequiredMixin, generic.FormView): |
| @@ -333,7 +334,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -333,7 +334,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
| 333 | resources_types[i].lower()+'_id': resource.id, 'topic_id': topics.id}, datetime__range=(init_date, end_date)).count() | 334 | resources_types[i].lower()+'_id': resource.id, 'topic_id': topics.id}, datetime__range=(init_date, end_date)).count() |
| 334 | 335 | ||
| 335 | 336 | ||
| 336 | - if resources_types[i].lower() in ["ytvideo", "webconference"]: | 337 | + if resources_types[i].lower() == "ytvideo": |
| 337 | watch_times = Log.objects.filter(action="watch", resource=resources_types[i].lower(),user_id = student.id, context__contains = {'subject_id': subject.id, | 338 | watch_times = Log.objects.filter(action="watch", resource=resources_types[i].lower(),user_id = student.id, context__contains = {'subject_id': subject.id, |
| 338 | resources_types[i].lower()+'_id': resource.id}, datetime__range=(init_date, end_date)) | 339 | resources_types[i].lower()+'_id': resource.id}, datetime__range=(init_date, end_date)) |
| 339 | if watch_times.count() > 0: | 340 | if watch_times.count() > 0: |
| @@ -343,6 +344,20 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -343,6 +344,20 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
| 343 | time_delta = end_time - begin_time | 344 | time_delta = end_time - begin_time |
| 344 | hours_viewed += time_delta.microseconds/3600 #so it's turned this seconds into hours | 345 | hours_viewed += time_delta.microseconds/3600 #so it's turned this seconds into hours |
| 345 | 346 | ||
| 347 | + if resources_types[i].lower() == "webconference": | ||
| 348 | + init_times = Log.objects.filter(action="initwebconference", resource=resources_types[i].lower(), user_id = student.id, context__contains = {'subject_id': subject.id, | ||
| 349 | + resources_types[i].lower()+'_id': resource.id}, datetime__range=(init_date, end_date)) | ||
| 350 | + end_times = Log.objects.filter(action="participate", resource=resources_types[i].lower(), user_id = student.id, context__contains = {'subject_id': subject.id, | ||
| 351 | + resources_types[i].lower()+'_id': resource.id}, datetime__range=(init_date, end_date)) | ||
| 352 | + if init_times.count() > 0: | ||
| 353 | + j = 0 | ||
| 354 | + for init_time in init_times: | ||
| 355 | + begin_time = int(init_time.context['webconference_init']) | ||
| 356 | + end_time = int(end_times[j].context['webconference_finish']) | ||
| 357 | + j += 1 | ||
| 358 | + time_delta = math.fabs(end_time - begin_time) | ||
| 359 | + | ||
| 360 | + hours_viewed += time_delta/3600 #so it's turned this seconds into hours | ||
| 346 | for daynum in day_numbers: | 361 | for daynum in day_numbers: |
| 347 | count_temp = Log.objects.filter(action="view", resource=resources_types[i].lower(), | 362 | count_temp = Log.objects.filter(action="view", resource=resources_types[i].lower(), |
| 348 | user_id = student.id, context__contains = {'subject_id': subject.id, | 363 | user_id = student.id, context__contains = {'subject_id': subject.id, |
| @@ -365,7 +380,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -365,7 +380,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
| 365 | if count_temp > 0: | 380 | if count_temp > 0: |
| 366 | distinct_days += 1 | 381 | distinct_days += 1 |
| 367 | 382 | ||
| 368 | - if resources_types[i].lower() in ["ytvideo", "webconference"]: | 383 | + if resources_types[i].lower() == "ytvideo": |
| 369 | watch_times = Log.objects.filter(action="watch", resource=resources_types[i].lower(),user_id = student.id, context__contains = {'subject_id': subject.id, | 384 | watch_times = Log.objects.filter(action="watch", resource=resources_types[i].lower(),user_id = student.id, context__contains = {'subject_id': subject.id, |
| 370 | resources_types[i].lower()+'_id': resource.id}, datetime__range=(init_date, end_date)) | 385 | resources_types[i].lower()+'_id': resource.id}, datetime__range=(init_date, end_date)) |
| 371 | if watch_times.count() > 0: | 386 | if watch_times.count() > 0: |
| @@ -374,6 +389,21 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -374,6 +389,21 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
| 374 | end_time = timedelta(microseconds = int(watch_time.context['timestamp_end'])) | 389 | end_time = timedelta(microseconds = int(watch_time.context['timestamp_end'])) |
| 375 | time_delta = end_time - begin_time | 390 | time_delta = end_time - begin_time |
| 376 | hours_viewed += time_delta.microseconds/3600 #so it's turned this seconds into hours | 391 | hours_viewed += time_delta.microseconds/3600 #so it's turned this seconds into hours |
| 392 | + | ||
| 393 | + if resources_types[i].lower() == "webconference": | ||
| 394 | + init_times = Log.objects.filter(action="initwebconference", resource=resources_types[i].lower(), user_id = student.id, context__contains = {'subject_id': subject.id, | ||
| 395 | + resources_types[i].lower()+'_id': resource.id}, datetime__range=(init_date, end_date)) | ||
| 396 | + end_times = Log.objects.filter(action="participate", resource=resources_types[i].lower(), user_id = student.id, context__contains = {'subject_id': subject.id, | ||
| 397 | + resources_types[i].lower()+'_id': resource.id}, datetime__range=(init_date, end_date)) | ||
| 398 | + if init_times.count() > 0: | ||
| 399 | + j = 0 | ||
| 400 | + for init_time in init_times: | ||
| 401 | + begin_time = int(init_time.context['webconference_init']) | ||
| 402 | + end_time = int(end_times[j].context['webconference_finish']) | ||
| 403 | + j += 1 | ||
| 404 | + time_delta = math.fabs(end_time - begin_time) | ||
| 405 | + | ||
| 406 | + hours_viewed += time_delta/3600 #so it's turned this seconds into hours | ||
| 377 | if count > 0: | 407 | if count > 0: |
| 378 | distinct_resources += 1 | 408 | distinct_resources += 1 |
| 379 | total_count += count | 409 | total_count += count |