Skip to content

scores

Gamification scoring events. Each row is an event that awarded points to a user. Append-only.

  • ETL strategy: append
  • PK: id

Columns

ColumnTypeDescription
idBIGINTPK.
id_tenantBIGINTFK → tenants.id.
id_userBIGINTFK → users.id.
id_productBIGINTFK → products.id. Resolves to products.id_origin when replicated.
id_itemBIGINTFree-form id of the item that produced the score (lesson, comment, …).
typeTEXTEvent category. Enum — see below.
keyTEXTFree-form identifier (key of the rule that produced the score, when applicable).
scoreINTEGERPoints awarded.
created_atTIMESTAMPTZ

Enum · type

ValueMeaning
lesson_completedLesson marked as completed.
course_startedCourse started by the learner.
course_progress_50Reached 50% of the course.
course_progress_75Reached 75% of the course.
course_progress_90Reached 90% of the course.
course_completedCourse completed (100%).
certificate_issuedCertificate issued.
question_askedQuestion / inquiry posted.
comment_postedComment posted.
exam_passedExam passed.
manualPoints awarded manually by an admin.

The same names appear in tenants.meta.gamification.events — match scores.type against that map to know how many points each event awards.

The key column complements type with a free-form identifier when the admin defines the rule (custom campaigns).

Patterns

sql
-- Top 10 learners this month
SELECT id_user, sum(score) AS month_points
FROM lms.scores
WHERE created_at >= date_trunc('month', now())
GROUP BY id_user
ORDER BY 2 DESC
LIMIT 10;

-- Event distribution
SELECT type, count(*), sum(score)
FROM lms.scores
WHERE created_at >= now() - interval '7 days'
GROUP BY type
ORDER BY 2 DESC;

OpenDB · Cademi LMS Data Warehouse