Module-centric analytics view providing comprehensive completion rates, performance metrics, and assignment statistics.
Calculates completion rates, pass rates, average scores, and timing analytics per learning module.
Optimized for reporting and dashboard use cases. Uses userid+moduleid relationships for accurate cross-table joins.
CREATE VIEW vwlearningmodulecompletionanalytics AS (
SELECT lm.id AS module_id,
lm.name AS module_name,
lm.description AS module_description,
lm.type AS module_type,
lm.state AS module_state,
count(DISTINCT lma.userid) AS total_assigned_users,
count(DISTINCT
CASE
WHEN (lma.isoverdue = true) THEN lma.userid
ELSE NULL::character varying
END) AS overdue_users,
count(DISTINCT
CASE
WHEN ((lma.state)::text = 'Assigned'::text) THEN lma.userid
ELSE NULL::character varying
END) AS active_assignments,
count(DISTINCT lar.userid) AS completed_users,
round((((count(DISTINCT lar.userid))::numeric / (NULLIF(count(DISTINCT lma.userid), 0))::numeric) * (100)::numeric), 2) AS completion_rate_percentage,
round(avg(lar.assessmentpercentagescore), 2) AS avg_assessment_score,
round(avg(lar.completionpercentage), 2) AS avg_completion_percentage,
round(avg(lar.lengthinminutes), 2) AS avg_duration_minutes,
count(DISTINCT
CASE
WHEN ((lar.assessmentpercentagescore IS NOT NULL) AND (lar.passpercent IS NOT NULL) AND (lar.assessmentpercentagescore >= lar.passpercent)) THEN lar.userid
ELSE NULL::character varying
END) AS passed_users,
count(DISTINCT
CASE
WHEN ((lar.assessmentpercentagescore IS NOT NULL) AND (lar.passpercent IS NOT NULL) AND (lar.assessmentpercentagescore < lar.passpercent)) THEN lar.userid
ELSE NULL::character varying
END) AS failed_users,
round((((count(DISTINCT
CASE
WHEN ((lar.assessmentpercentagescore IS NOT NULL) AND (lar.passpercent IS NOT NULL) AND (lar.assessmentpercentagescore >= lar.passpercent)) THEN lar.userid
ELSE NULL::character varying
END))::numeric / (NULLIF(count(DISTINCT
CASE
WHEN ((lar.assessmentpercentagescore IS NOT NULL) AND (lar.passpercent IS NOT NULL)) THEN lar.userid
ELSE NULL::character varying
END), 0))::numeric) * (100)::numeric), 2) AS pass_rate_percentage,
min(lma.dateassigned) AS earliest_assignment_date,
max(lma.dateassigned) AS latest_assignment_date,
min(lar.datecreated) AS earliest_completion_date,
max(lar.datemodified) AS latest_completion_date
FROM ((learningmodules lm
LEFT JOIN learningmoduleassignments lma ON (((lm.id)::text = (lma.moduleid)::text)))
LEFT JOIN learningassignmentresults lar ON ((((lma.userid)::text = (lar.userid)::text) AND ((lma.moduleid)::text = (lar.moduleid)::text))))
WHERE ((lm.state)::text <> 'deleted'::text)
GROUP BY lm.id, lm.name, lm.description, lm.type, lm.state
ORDER BY (round((((count(DISTINCT lar.userid))::numeric / (NULLIF(count(DISTINCT lma.userid), 0))::numeric) * (100)::numeric), 2)) DESC, lm.name
)
Name | Type | Default | Nullable | Children | Parents | Comment |
---|---|---|---|---|---|---|
module_id | varchar(50) | true | ||||
module_name | varchar(100) | true | ||||
module_description | varchar(100) | true | ||||
module_type | varchar(50) | true | ||||
module_state | varchar(50) | true | ||||
total_assigned_users | bigint | true | ||||
overdue_users | bigint | true | ||||
active_assignments | bigint | true | ||||
completed_users | bigint | true | ||||
completion_rate_percentage | numeric | true | ||||
avg_assessment_score | numeric | true | ||||
avg_completion_percentage | numeric | true | ||||
avg_duration_minutes | numeric | true | ||||
passed_users | bigint | true | ||||
failed_users | bigint | true | ||||
pass_rate_percentage | numeric | true | ||||
earliest_assignment_date | timestamp without time zone | true | ||||
latest_assignment_date | timestamp without time zone | true | ||||
earliest_completion_date | timestamp without time zone | true | ||||
latest_completion_date | timestamp without time zone | true |
Name | Columns | Comment | Type |
---|---|---|---|
public.learningmodules | 16 | BASE TABLE | |
public.learningmoduleassignments | 23 | Learning Module Assignments Table - Stores assignment data for learning modules assigned to users. This table tracks the complete lifecycle of learning module assignments from initial assignment through completion. It serves as the primary source for assignment tracking and correlates with learningassignmentresults via userid+moduleid for comprehensive learning analytics. Key Performance Optimizations: - Data retrieved using module-based API iteration (O(modules) vs O(users)) for better performance - User IDs extracted from assignment response data rather than query parameters - Enables efficient user-module assignment and completion analytics Cross-table Relationships: - userid: Links to userdetails.id for user identification and demographics - moduleid: Links to learningmodules.id for module details and metadata - Correlates with learningassignmentresults on userid+moduleid for assignment-to-completion tracking Analytics Capabilities: - Supports user assignment summaries and module completion rate analysis - Enables performance metrics and learning analytics across user-module relationships - Provides foundation for learning dashboard and reporting functionality |
BASE TABLE |
public.learningassignmentresults | 13 | Learning Assignment Results Table - Stores detailed results and completion data for learning module assignments. This table captures the outcome and performance metrics when users complete learning module assignments. It serves as the results repository that correlates with learningmoduleassignments to provide complete assignment lifecycle tracking from assignment through completion and assessment. Key Performance Optimizations: - Data retrieved using module-based API iteration (O(modules) vs O(users)) for better performance - User IDs extracted from assignment result response data rather than query parameters - Enables efficient user-module assignment and completion analytics Cross-table Relationships: - userid: Links to userdetails.id for user identification and demographics - moduleid: Links to learningmodules.id for module details and metadata - Correlates with learningmoduleassignments on userid+moduleid for assignment-to-completion tracking Analytics Capabilities: - Supports user assignment summaries and module completion rate analysis - Enables performance metrics and learning analytics across user-module relationships - Provides foundation for learning dashboard, reporting, and performance tracking - Tracks assessment scores, completion percentages, and timing metrics |
BASE TABLE |