Commit 959756c8ce4f898bc55768efbca01ded7c5cda7d

Authored by fbormann
1 parent a71ff433

added hours viewed for webconference as well as youtube video

Showing 1 changed file with 30 additions and 1 deletions   Show diff stats
reports/views.py
... ... @@ -315,11 +315,15 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
315 315 resources = Resource.objects.select_related(resources_types[i].lower()).filter(tags__in = tags, topic=topics)
316 316 else:
317 317 resources = Resource.objects.select_related(resources_types[i].lower()).filter(tags__in = tags, topic__in=topics)
  318 +
318 319 distinct_resources = 0
319 320 total_count = 0
320 321  
  322 + #variables to handle distinct days report's variable
321 323 day_numbers = [0, 1, 2, 3, 4, 5, 6]
322 324 distinct_days = 0
  325 +
  326 + hours_viewed = 0 #youtube video as well as webconference
323 327 for resource in resources:
324 328  
325 329 if isinstance(topics,Topic):
... ... @@ -328,6 +332,17 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
328 332 user_id = student.id, context__contains = {'subject_id': subject.id,
329 333 resources_types[i].lower()+'_id': resource.id, 'topic_id': topics.id}, datetime__range=(init_date, end_date)).count()
330 334  
  335 +
  336 + if resources_types[i].lower() in ["ytvideo", "webconference"]:
  337 + 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 + if watch_times.count() > 0:
  340 + for watch_time in watch_times:
  341 + begin_time = timedelta(microseconds = int(watch_time.context['timestamp_start']))
  342 + end_time = timedelta(microseconds = int(watch_time.context['timestamp_end']))
  343 + time_delta = end_time - begin_time
  344 + hours_viewed += time_delta.microseconds/3600 #so it's turned this seconds into hours
  345 +
331 346 for daynum in day_numbers:
332 347 count_temp = Log.objects.filter(action="view", resource=resources_types[i].lower(),
333 348 user_id = student.id, context__contains = {'subject_id': subject.id,
... ... @@ -341,6 +356,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
341 356 user_id = student.id, context__contains = {'subject_id': subject.id,
342 357 resources_types[i].lower()+'_id': resource.id}, datetime__range=(init_date, end_date)).count()
343 358  
  359 +
344 360 for daynum in day_numbers:
345 361 count_temp = Log.objects.filter(action="view", resource=resources_types[i].lower(),
346 362 user_id = student.id, context__contains = {'subject_id': subject.id,
... ... @@ -348,6 +364,16 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
348 364 datetime__range=(init_date, end_date)).count()
349 365 if count_temp > 0:
350 366 distinct_days += 1
  367 +
  368 + if resources_types[i].lower() in ["ytvideo", "webconference"]:
  369 + 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))
  371 + if watch_times.count() > 0:
  372 + for watch_time in watch_times:
  373 + begin_time = timedelta(microseconds = int(watch_time.context['timestamp_start']))
  374 + end_time = timedelta(microseconds = int(watch_time.context['timestamp_end']))
  375 + time_delta = end_time - begin_time
  376 + hours_viewed += time_delta.microseconds/3600 #so it's turned this seconds into hours
351 377 if count > 0:
352 378 distinct_resources += 1
353 379 total_count += count
... ... @@ -355,7 +381,10 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
355 381 data[str(resources_types[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = total_count
356 382 data["distintic " + str(resources_types[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = distinct_resources
357 383 data["distintic days " + str(resources_types[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = distinct_days
358   -
  384 +
  385 + if resources_types[i].lower() in ["ytvideo", "webconference"]:
  386 + data["hours viewed of " + str(resources_types[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = hours_viewed
  387 +
359 388 """data["distinct" + str(resources[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = Log.objects.filter(action="view", resource=resources[i].lower(),
360 389 user_id = student.id, context__contains = {'subject_id': subject.id}).distinct().count()"""
361 390  
... ...