Path: blob/master/src/packages/util/db-schema/retention.ts
1447 views
import { Table } from "./types";12export const retentionModels = {3file_access_log: {4title: "File Access Log - Retention",5description:6"Number of accounts in the cohort with an entry in the file_access_log during each period.",7},8"file_access_log:all": {9title: "File Access Log - Active Users",10description:11"Number of accounts with an entry in the file_access_log during each period.",12},13openai_chatgpt_log: {14title: "ChatGPT - Retention",15description:16"Number of accounts in the cohort that used chatgpt during period.",17},18"openai_chatgpt_log:all": {19title: "ChatGPT - Active Users",20description:21"Number of accounts with an entry in the openai_chatgpt_log during each period.",22},23project_log: {24title: "Project Log - Retention",25description:26"Number of accounts in the cohort with an entry in the project log during each period.",27},28"project_log:all": {29title: "Project Log - Active Users",30description:31"Number of accounts with an entry in the project log during each period.",32},33user_tracking: {34title: "User Tracking - Retention",35description:36"Number of accounts in the cohort with an entry in the user tracking table during each period.",37},38"user_tracking:all": {39title: "User Tracking - Active Users",40description:41"Number of accounts with an entry in the user tracking table during each period.",42},43"client_error_log:all": {44title: "Client Error Log - Active Users",45description:46"Number of accounts with an entry in the client error log during each period.",47},48"webapp_errors:all": {49title: "Webapp Errors - Active Users",50description:51"Number of accounts with an entry in the webapp_errors log during each period.",52},53};5455export type RetentionModel = keyof typeof retentionModels;5657Table({58name: "crm_retention",59fields: {60start: {61title: "Cohort Start",62desc: "The cohort consists of accounts created >= start and < end, unless otherwise stated by the model definition. E.g., if the model name ends in :all, then the cohort is simply all accounts ever created.",63type: "timestamp",64},65stop: {66title: "Cohort Stop",67desc: "Defines the stoping timestamp of this cohort",68type: "timestamp",69},70model: {71desc: "The model that defines active users, e.g., 'file_access_log', 'file_access_log:all'. This determines the cohort and how active is measured, via code that is hardcoded in cocalc's source code. E.g., 'project_log:paid' might mean that we use entries in the project_log to define activity and restrict to paying customers only to define the cohort.",72type: "string",73},74period: {75title: "Active Period",76desc: "We measure activity of the cohort for the intervals [start,start+period), [start+period, start+2*period), [start+2*period, start+3*period), ..., [last_start_time, last_start_time+period), where last_start_time is defined below.",77pg_type: "interval",78type: "string",79},80last_start_time: {81title: "Start of last data",82desc: "The start time of the last interval that's in the active array. We can use this to easily tell if there is missing data or not.",83type: "timestamp",84},85active: {86title: "Active Accounts",87desc: "The number of distinct accounts in the cohort that were active during each period. This is an array of integers.",88pg_type: "integer[]",89type: "array",90},91size: {92title: "Cohort Size",93desc: "The number of accounts in this cohort. In case of ':all' models, this is total number of users that were active during all periods considered.",94type: "integer",95},96},97rules: {98desc: "CRM Retention Table",99primary_key: ["start", "stop", "model", "period"],100user_query: {101get: {102pg_where: [],103admin: true,104fields: {105start: null,106stop: null,107model: null,108period: null,109last_start_time: null,110active: null,111size: null,112},113async check_hook(db, obj, _account_id, _project_id, cb) {114// The check hook ensures the data that is being requested exists115// and is up to date. It's not really "checking" for validity, but116// that it is up to date.117try {118await db.updateRetentionData(obj);119cb();120} catch (err) {121cb(err);122}123},124},125},126},127});128129130