14
14
from website .flask_helpers import render_template
15
15
from website import querylog
16
16
from website .auth import is_admin , is_teacher , requires_admin , requires_login
17
-
17
+ from timeit import default_timer as timer
18
18
from .database import Database
19
19
from .website_module import WebsiteModule , route
20
20
from bs4 import BeautifulSoup
21
21
22
+ import logging
23
+ from logging_config import LOGGING_CONFIG
24
+ from logging .config import dictConfig as logConfig
25
+
26
+ logConfig (LOGGING_CONFIG )
27
+ logger = logging .getLogger (__name__ )
28
+
22
29
"""The Key tuple is used to aggregate the raw data by level, time or username."""
23
30
Key = namedtuple ("Key" , ["name" , "class_" ])
24
31
level_key = Key ("level" , int )
@@ -335,8 +342,11 @@ def __init__(self, db: Database):
335
342
self .MAX_FEED_SIZE = 4
336
343
337
344
def __selected_levels (self , class_id ):
345
+ start = timer ()
338
346
class_customization = get_customizations (self .db , class_id )
339
347
class_overview = class_customization .get ('dashboard_customization' )
348
+ end = timer ()
349
+ logger .debug (f'Time taken by __selected_levels { end - start } ' )
340
350
if class_overview :
341
351
return class_overview .get ('selected_levels' , [1 ])
342
352
return [1 ]
@@ -349,6 +359,7 @@ def __common_errors(self, class_id):
349
359
350
360
def __all_students (self , class_ ):
351
361
"""Returns a list of all students in a class along with some info."""
362
+ start = timer ()
352
363
students = []
353
364
for student_username in class_ .get ("students" , []):
354
365
programs = self .db .programs_for_user (student_username )
@@ -365,6 +376,8 @@ def __all_students(self, class_):
365
376
"current_level" : programs [0 ]['level' ] if programs else '0'
366
377
}
367
378
)
379
+ end = timer ()
380
+ logger .debug (f'Time taken by __all_students { end - start } ' )
368
381
return students
369
382
370
383
def __get_adventures_for_overview (self , user , class_id ):
@@ -440,6 +453,7 @@ def render_live_stats(self, user, class_id):
440
453
)
441
454
442
455
def get_class_live_stats (self , user , class_ ):
456
+ start = timer ()
443
457
# Retrieve common errors and selected levels in class overview from the database for class
444
458
selected_levels = self .__selected_levels (class_ ['id' ])
445
459
if selected_levels :
@@ -476,7 +490,8 @@ def get_class_live_stats(self, user, class_):
476
490
programs_for_student [_student ] = adventures_for_student
477
491
if programs_for_student != []:
478
492
attempted_adventures [level ] = programs_for_student
479
-
493
+ end = timer ()
494
+ logger .debug (f'Time taken by get_class_live_stats { end - start } ' )
480
495
return students , common_errors , selected_levels , quiz_info , attempted_adventures , adventures
481
496
482
497
@route ("/live_stats/class/<class_id>/select_level" , methods = ["GET" ])
@@ -810,6 +825,7 @@ def retrieve_exceptions_per_student(self, class_id):
810
825
:param class_id: class id
811
826
:return: exceptions_per_user
812
827
"""
828
+ start = timer ()
813
829
class_ = self .db .get_class (class_id )
814
830
exceptions_per_user = {}
815
831
students = sorted (class_ .get ("students" , []))
@@ -820,7 +836,8 @@ def retrieve_exceptions_per_student(self, class_id):
820
836
program_stats = program_stats [- 1 ]
821
837
exceptions = {k : v for k , v in program_stats .items () if k .lower ().endswith ("exception" )}
822
838
exceptions_per_user [student_username ] = exceptions
823
-
839
+ end = timer ()
840
+ logger .debug (f'Tike taken by retrieve_exceptions_per_student { end - start } ' )
824
841
return exceptions_per_user
825
842
826
843
def new_id_calc (self , common_errors , class_id ):
@@ -856,6 +873,7 @@ def common_exception_detection(self, class_id, user):
856
873
"""
857
874
Detects misconceptions of students in the class based on errors they are making.
858
875
"""
876
+ start = timer ()
859
877
common_errors = self .__common_errors (class_id )
860
878
# Group the error messages by session and count their occurrences
861
879
exceptions_per_user = self .retrieve_exceptions_per_student (class_id ) # retrieves relevant data from db
@@ -913,7 +931,8 @@ def common_exception_detection(self, class_id, user):
913
931
'active' : 1 ,
914
932
"students" : users_only
915
933
})
916
-
934
+ end = timer ()
935
+ logger .debug (f'Time taken by common_exception_detection { end - start } ' )
917
936
return self .db .update_class_errors (common_errors )
918
937
919
938
@route ("/live_stats/class/<class_id>" , methods = ["POST" ])
0 commit comments