From 3c43c565bebdd634b4de155550b8de07d1021d03 Mon Sep 17 00:00:00 2001 From: Diego Millan Date: Fri, 15 Nov 2019 12:19:17 -0500 Subject: [PATCH] Adding metric total of sessions --- .../reports/learning_tracker_report.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/openedx_proversity_reports/reports/learning_tracker_report.py b/openedx_proversity_reports/reports/learning_tracker_report.py index 1d05a07..64a34ff 100644 --- a/openedx_proversity_reports/reports/learning_tracker_report.py +++ b/openedx_proversity_reports/reports/learning_tracker_report.py @@ -76,6 +76,7 @@ def generate_report(self): 'cumulative_grade': self._get_cumulative_grade(user), 'has_verified_certificate': self._has_verified_certificate(user), 'time_between_sessions': self._get_time_bewteen_sessions(user), + 'total_sessions': self._get_total_sessions(user), 'weekly_clicks': self._get_weekly_clicks(user), 'number_of_graded_assessment': self._get_number_of_graded_assessment(user), 'timeliness_of_submissions': self._get_timeliness_of_submissions(user), @@ -154,6 +155,22 @@ def _get_time_bewteen_sessions(self, user): except ValueError: return 0 + def _get_total_sessions(self, user): + """ + Calculate learner metrics for "Total of sessions". + Args: + user: User Model. + Returns: + int (Total of sessions). + """ + user_profile = get_user_profile().objects.get(user_id=user.id) + + try: + meta = json.loads(user_profile.meta) + return int(meta.get('session_number', 0)) + except ValueError: + return 0 + def _get_timeliness_of_submissions(self, user): """ The number of days that user submits assignments before the posted due date.