-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cubejs library all missing queries for dashboard added
- Loading branch information
Showing
10 changed files
with
401 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import commandLineArgs from 'command-line-args' | ||
import commandLineUsage from 'command-line-usage' | ||
import * as fs from 'fs' | ||
import path from 'path' | ||
import { CubeJsRepository, CubeJsService } from '@crowd/cubejs' | ||
import moment from 'moment-timezone' | ||
import { databaseInit } from '@/database/databaseConnection' | ||
import { getServiceLogger } from '@crowd/logging' | ||
|
||
/* eslint-disable no-console */ | ||
|
||
const banner = fs.readFileSync(path.join(__dirname, 'banner.txt'), 'utf8') | ||
|
||
const log = getServiceLogger() | ||
|
||
const options = [ | ||
{ | ||
name: 'help', | ||
alias: 'h', | ||
type: Boolean, | ||
description: 'Print this usage guide.', | ||
}, | ||
{ | ||
name: 'tenantId', | ||
alias: 't', | ||
type: String, | ||
description: 'Tenant ID', | ||
}, | ||
{ | ||
name: 'segmentId', | ||
alias: 's', | ||
type: String, | ||
description: 'Segment ID', | ||
}, | ||
] | ||
const sections = [ | ||
{ | ||
content: banner, | ||
raw: true, | ||
}, | ||
{ | ||
header: `Unmerge a member from another member using a snapshot db`, | ||
content: 'Unmerge a member from another member using a snapshot db', | ||
}, | ||
{ | ||
header: 'Options', | ||
optionList: options, | ||
}, | ||
] | ||
|
||
const usage = commandLineUsage(sections) | ||
const parameters = commandLineArgs(options) | ||
|
||
if (parameters.help || !parameters.tenantId || !parameters.segmentId) { | ||
console.log(usage) | ||
} else { | ||
setImmediate(async () => { | ||
const db = await databaseInit() | ||
|
||
const cubejsService = new CubeJsService() | ||
|
||
await cubejsService.init(parameters.tenantId, [parameters.segmentId], log) | ||
|
||
const start = moment().subtract(6, 'days').startOf('day') | ||
|
||
const end = moment().endOf('day') | ||
|
||
const data = await CubeJsRepository.getActiveMembersTimeseries( | ||
cubejsService, | ||
start, | ||
end, | ||
'day', | ||
null, | ||
) | ||
|
||
console.log(data) | ||
|
||
process.exit(0) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
services/libs/cubejs/src/metrics/activeOrganizationsTimeseries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import moment from 'moment' | ||
|
||
import { CubeJsService } from '../service' | ||
import CubeDimensions from '../dimensions' | ||
import CubeMeasures from '../measures' | ||
import { ICubeFilter } from 'types' | ||
import { CubeGranularity } from '../enums' | ||
|
||
/** | ||
* Gets `active organizations` timeseries data for a given date range in given granularity. | ||
* Organizations are active when they have an activity in given date range. | ||
* @param cjs cubejs service instance | ||
* @param startDate | ||
* @param endDate | ||
* @returns | ||
*/ | ||
export default async ( | ||
cjs: CubeJsService, | ||
startDate: moment.Moment, | ||
endDate: moment.Moment, | ||
granularity: CubeGranularity = CubeGranularity.DAY, | ||
platform: string = undefined, | ||
segment: string = undefined, | ||
) => { | ||
const filters: ICubeFilter[] = [ | ||
{ | ||
member: CubeDimensions.IS_TEAM_MEMBER, | ||
operator: 'equals', | ||
values: ['false'], | ||
}, | ||
{ | ||
member: CubeDimensions.IS_BOT, | ||
operator: 'equals', | ||
values: ['false'], | ||
}, | ||
] | ||
|
||
if (platform) { | ||
filters.push({ | ||
member: CubeDimensions.ACTIVITY_PLATFORM, | ||
operator: 'equals', | ||
values: [platform], | ||
}) | ||
} | ||
|
||
if (segment) { | ||
filters.push({ | ||
member: CubeDimensions.SEGMENTS_ID, | ||
operator: 'equals', | ||
values: [segment], | ||
}) | ||
} | ||
|
||
const query = { | ||
measures: [CubeMeasures.ORGANIZATION_COUNT], | ||
timeDimensions: [ | ||
{ | ||
dimension: CubeDimensions.ACTIVITY_DATE, | ||
dateRange: [startDate.format('YYYY-MM-DD'), endDate.format('YYYY-MM-DD')], | ||
granularity, | ||
}, | ||
], | ||
filters, | ||
} | ||
|
||
cjs.log.info(query) | ||
|
||
const activeOrganizationsTimeseries = await cjs.load(query) | ||
|
||
return activeOrganizationsTimeseries || [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
export { default as newActivities } from './newActivities' | ||
export { default as newActivitiesTimeseries } from './newActivitiesTimeseries' | ||
export { default as newConversations } from './newConversations' | ||
export { default as activeMembers } from './activeMembers' | ||
export { default as activeMembersTimeseries } from './activeMembersTimeseries' | ||
export { default as newMembers } from './newMembers' | ||
export { default as newMembersTimeseries } from './newMembersTimeseries' | ||
export { default as newOrganizations } from './newOrganizations' | ||
export { default as newOrganizationsTimeseries } from './newOrganizationsTimeseries' | ||
export { default as activeOrganizations } from './activeOrganizations' | ||
export { default as activeOrganizationsTimeseries } from './activeOrganizationsTimeseries' |
71 changes: 71 additions & 0 deletions
71
services/libs/cubejs/src/metrics/newActivitiesTimeseries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import moment from 'moment' | ||
|
||
import { CubeJsService } from '../service' | ||
import CubeDimensions from '../dimensions' | ||
import CubeMeasures from '../measures' | ||
import { ICubeFilter } from 'types' | ||
import { CubeGranularity } from '../enums' | ||
|
||
/** | ||
* Gets `new activities` timeseries data for a given date range in given granularity. | ||
* Activities are new when activity.timestamp is in between given date range. | ||
* @param cjs cubejs service instance | ||
* @param startDate | ||
* @param endDate | ||
* @returns | ||
*/ | ||
export default async ( | ||
cjs: CubeJsService, | ||
startDate: moment.Moment, | ||
endDate: moment.Moment, | ||
granularity: CubeGranularity = CubeGranularity.DAY, | ||
platform: string = undefined, | ||
segment: string = undefined, | ||
) => { | ||
const filters: ICubeFilter[] = [ | ||
{ | ||
member: CubeDimensions.IS_TEAM_MEMBER, | ||
operator: 'equals', | ||
values: ['false'], | ||
}, | ||
{ | ||
member: CubeDimensions.IS_BOT, | ||
operator: 'equals', | ||
values: ['false'], | ||
}, | ||
] | ||
|
||
if (platform) { | ||
filters.push({ | ||
member: CubeDimensions.ACTIVITY_PLATFORM, | ||
operator: 'equals', | ||
values: [platform], | ||
}) | ||
} | ||
|
||
if (segment) { | ||
filters.push({ | ||
member: CubeDimensions.SEGMENTS_ID, | ||
operator: 'equals', | ||
values: [segment], | ||
}) | ||
} | ||
|
||
const query = { | ||
measures: [CubeMeasures.ACTIVITY_COUNT], | ||
timeDimensions: [ | ||
{ | ||
dimension: CubeDimensions.ACTIVITY_DATE, | ||
dateRange: [startDate.format('YYYY-MM-DD'), endDate.format('YYYY-MM-DD')], | ||
granularity, | ||
}, | ||
], | ||
filters, | ||
} | ||
|
||
cjs.log.info(query) | ||
|
||
const newActivitiesTimeseries = await cjs.load(query) | ||
|
||
return newActivitiesTimeseries || [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import moment from 'moment' | ||
|
||
import { CubeJsService } from '../service' | ||
import CubeDimensions from '../dimensions' | ||
import CubeMeasures from '../measures' | ||
import { ICubeFilter } from 'types' | ||
import { CubeGranularity } from '../enums' | ||
|
||
/** | ||
* Gets `new members` timeseries data for a given date range in given granularity. | ||
* Members are new when member.joinedAt is in between given date range. | ||
* @param cjs cubejs service instance | ||
* @param startDate | ||
* @param endDate | ||
* @returns | ||
*/ | ||
export default async ( | ||
cjs: CubeJsService, | ||
startDate: moment.Moment, | ||
endDate: moment.Moment, | ||
granularity: CubeGranularity = CubeGranularity.DAY, | ||
platform: string = undefined, | ||
segment: string = undefined, | ||
) => { | ||
const filters: ICubeFilter[] = [ | ||
{ | ||
member: CubeDimensions.IS_TEAM_MEMBER, | ||
operator: 'equals', | ||
values: ['false'], | ||
}, | ||
{ | ||
member: CubeDimensions.IS_BOT, | ||
operator: 'equals', | ||
values: ['false'], | ||
}, | ||
{ | ||
member: CubeDimensions.IS_ORGANIZATION, | ||
operator: 'equals', | ||
values: ['false'], | ||
}, | ||
] | ||
|
||
if (platform) { | ||
filters.push({ | ||
member: CubeDimensions.ACTIVITY_PLATFORM, | ||
operator: 'equals', | ||
values: [platform], | ||
}) | ||
} | ||
|
||
if (segment) { | ||
filters.push({ | ||
member: CubeDimensions.SEGMENTS_ID, | ||
operator: 'equals', | ||
values: [segment], | ||
}) | ||
} | ||
|
||
const query = { | ||
measures: [CubeMeasures.MEMBER_COUNT], | ||
timeDimensions: [ | ||
{ | ||
dimension: CubeDimensions.MEMBER_JOINED_AT, | ||
dateRange: [startDate.format('YYYY-MM-DD'), endDate.format('YYYY-MM-DD')], | ||
granularity, | ||
}, | ||
], | ||
filters, | ||
} | ||
|
||
cjs.log.info(query) | ||
|
||
const newMembersTimeseries = await cjs.load(query) | ||
|
||
return newMembersTimeseries || [] | ||
} |
Oops, something went wrong.