|
| 1 | +from django_email_learning.ports.metric_recorder_protocol import MetricRecorderProtocol |
| 2 | +from django_email_learning.models import DeactivationReason |
| 3 | +import logging |
| 4 | + |
| 5 | +logger = logging.getLogger(__name__) |
| 6 | + |
| 7 | + |
| 8 | +class LogBasedMetricRecorder(MetricRecorderProtocol): |
| 9 | + def user_enrolled_in_course(self, course_slug: str, organization_id: int) -> None: |
| 10 | + logger.info( |
| 11 | + "User enrolled", |
| 12 | + extra={"course_slug": course_slug, "organization_id": organization_id}, |
| 13 | + ) |
| 14 | + |
| 15 | + def quiz_sent(self, course_slug: str, organization_id: int, quiz_id: int) -> None: |
| 16 | + logger.info( |
| 17 | + "Quiz sent", |
| 18 | + extra={ |
| 19 | + "course_slug": course_slug, |
| 20 | + "organization_id": organization_id, |
| 21 | + "quiz_id": quiz_id, |
| 22 | + }, |
| 23 | + ) |
| 24 | + |
| 25 | + def lesson_sent( |
| 26 | + self, course_slug: str, organization_id: int, lesson_id: int |
| 27 | + ) -> None: |
| 28 | + logger.info( |
| 29 | + "Lesson sent", |
| 30 | + extra={ |
| 31 | + "course_slug": course_slug, |
| 32 | + "organization_id": organization_id, |
| 33 | + "lesson_id": lesson_id, |
| 34 | + }, |
| 35 | + ) |
| 36 | + |
| 37 | + def user_enrollment_activated(self, course_slug: str, organization_id: int) -> None: |
| 38 | + logger.info( |
| 39 | + "User enrollment activated", |
| 40 | + extra={"course_slug": course_slug, "organization_id": organization_id}, |
| 41 | + ) |
| 42 | + |
| 43 | + def user_enrollment_deactivated( |
| 44 | + self, course_slug: str, organization_id: int, reason: DeactivationReason |
| 45 | + ) -> None: |
| 46 | + logger.info( |
| 47 | + "User enrollment deactivated", |
| 48 | + extra={ |
| 49 | + "course_slug": course_slug, |
| 50 | + "organization_id": organization_id, |
| 51 | + "reason": reason, |
| 52 | + }, |
| 53 | + ) |
| 54 | + |
| 55 | + def user_completed_course(self, course_slug: str, organization_id: int) -> None: |
| 56 | + logger.info( |
| 57 | + "User completed course", |
| 58 | + extra={"course_slug": course_slug, "organization_id": organization_id}, |
| 59 | + ) |
| 60 | + |
| 61 | + def quiz_submitted( |
| 62 | + self, course_slug: str, organization_id: int, quiz_id: int, is_passed: bool |
| 63 | + ) -> None: |
| 64 | + logger.info( |
| 65 | + "Quiz submitted", |
| 66 | + extra={ |
| 67 | + "course_slug": course_slug, |
| 68 | + "organization_id": organization_id, |
| 69 | + "quiz_id": quiz_id, |
| 70 | + "is_passed": is_passed, |
| 71 | + }, |
| 72 | + ) |
| 73 | + |
| 74 | + def method_executed(self, method_name: str, execution_time: int) -> None: |
| 75 | + logger.info( |
| 76 | + "Method executed", |
| 77 | + extra={"method_name": method_name, "execution_time": execution_time}, |
| 78 | + ) |
0 commit comments