diff --git a/.gitignore b/.gitignore index 2a8388d..c1153e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store node_modules /dist +dist/ # local env files .env.local diff --git a/schema/Session.js b/schema/Session.js index 2091cd0..64aade9 100644 --- a/schema/Session.js +++ b/schema/Session.js @@ -73,7 +73,7 @@ cube(`GroupedSession`, { sql: ` WITH summary AS ( SELECT - session.id, + session.id AS session_id, session.plio_id, session.user_id, session.watch_time, @@ -97,6 +97,11 @@ cube(`GroupedSession`, { sql: `${CUBE}.user_id = ${User}.id`, relationship: `belongsTo`, }, + + Session: { + sql: `${CUBE}.session_id = ${Session}.id`, + relationship: `belongsTo`, + }, }, measures: { @@ -111,7 +116,7 @@ cube(`GroupedSession`, { }, dimensions: { id: { - sql: `id`, + sql: `session_id`, type: `number`, primaryKey: true, }, @@ -122,6 +127,7 @@ cube(`GroupedSessionRetention`, { sql: ` SELECT ROW_NUMBER() OVER (ORDER BY user_id, plio_id) as id, + session_id, plio_id, user_id, SUM(retention_array) as postOneMinuteRetentionSum @@ -131,6 +137,7 @@ cube(`GroupedSessionRetention`, { * FROM ( SELECT + session_id, plio_id, user_id, UNNEST(string_to_array(retention, ','))::int AS retention_array @@ -139,7 +146,7 @@ cube(`GroupedSessionRetention`, { ) AS B ) AS C WHERE index >= 60 - GROUP BY plio_id, user_id + GROUP BY plio_id, user_id, session_id `, joins: { @@ -152,6 +159,16 @@ cube(`GroupedSessionRetention`, { sql: `${CUBE}.user_id = ${User}.id`, relationship: `belongsTo`, }, + + Session: { + sql: `${CUBE}.session_id = ${Session}.id`, + relationship: `belongsTo`, + }, + + GroupedSession: { + sql: `${CUBE}.session_id = ${GroupedSession}.session_id`, + relationship: `belongsTo`, + }, }, measures: { diff --git a/schema/SessionAnswer.js b/schema/SessionAnswer.js index 2c8b2c9..8d61fda 100644 --- a/schema/SessionAnswer.js +++ b/schema/SessionAnswer.js @@ -51,7 +51,7 @@ cube(`SessionAnswer`, { cube(`GroupedSessionAnswer`, { sql: ` SELECT - session.id AS session_id, + session.session_id, session.plio_id, session.user_id, sessionAnswer.id, @@ -61,7 +61,7 @@ cube(`GroupedSessionAnswer`, { question.correct_answer AS question_correct_answer FROM ${GroupedSession.sql()} AS session INNER JOIN ${SessionAnswer.sql()} as sessionAnswer - ON session.id=sessionAnswer.session_id + ON session.session_id=sessionAnswer.session_id INNER JOIN ${Item.sql()} as item ON item.id=sessionAnswer.item_id INNER JOIN ${Question.sql()} as question ON question.item_id = item.id`,