-
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.
- Loading branch information
Showing
6 changed files
with
186 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import commandLineArgs from 'command-line-args' | ||
import commandLineUsage from 'command-line-usage' | ||
import { QueryTypes } from 'sequelize' | ||
import * as fs from 'fs' | ||
import path from 'path' | ||
import SequelizeRepository from '../../database/repositories/sequelizeRepository' | ||
import TenantService from '@/services/tenantService' | ||
import OrganizationService from '@/services/organizationService' | ||
import getUserContext from '@/database/utils/getUserContext' | ||
import { IRepositoryOptions } from '@/database/repositories/IRepositoryOptions' | ||
import { | ||
MergeActionState, | ||
MergeActionType, | ||
MergeActionsRepository, | ||
} from '@/database/repositories/mergeActionsRepository' | ||
import { CubeJsService } from '@crowd/cubejs' | ||
|
||
/* eslint-disable no-console */ | ||
|
||
const banner = fs.readFileSync(path.join(__dirname, 'banner.txt'), 'utf8') | ||
|
||
const options = [ | ||
{ | ||
name: 'tenant', | ||
alias: 't', | ||
type: String, | ||
description: 'The unique ID of tenant', | ||
}, | ||
{ | ||
name: 'allTenants', | ||
alias: 'a', | ||
type: Boolean, | ||
defaultValue: false, | ||
description: 'Set this flag to merge similar organizations for all tenants.', | ||
}, | ||
{ | ||
name: 'help', | ||
alias: 'h', | ||
type: Boolean, | ||
description: 'Print this usage guide.', | ||
}, | ||
] | ||
const sections = [ | ||
{ | ||
content: banner, | ||
raw: true, | ||
}, | ||
{ | ||
header: 'Merge organizations with similarity higher than given threshold.', | ||
content: 'Merge organizations with similarity higher than given threshold.', | ||
}, | ||
{ | ||
header: 'Options', | ||
optionList: options, | ||
}, | ||
] | ||
|
||
const usage = commandLineUsage(sections) | ||
const parameters = commandLineArgs(options) | ||
|
||
if (parameters.help || (!parameters.tenant && !parameters.allTenants)) { | ||
console.log(usage) | ||
} else { | ||
setImmediate(async () => { | ||
const options = await SequelizeRepository.getDefaultIRepositoryOptions() | ||
|
||
let tenantIds | ||
|
||
if (parameters.allTenants) { | ||
tenantIds = (await TenantService._findAndCountAllForEveryUser({})).rows.map((t) => t.id) | ||
} else if (parameters.tenant) { | ||
tenantIds = parameters.tenant.split(',') | ||
} else { | ||
tenantIds = [] | ||
} | ||
|
||
for (const tenantId of tenantIds) { | ||
const cjs = new CubeJsService() | ||
await cjs.init(tenantId, []) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
FROM cubejs/cube:v0.33.55 | ||
|
||
COPY ./ /cube/conf/ | ||
COPY ./ /cube/conf/ | ||
COPY ./src /cube/conf/ |
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,10 @@ | ||
export enum CubeGranularity { | ||
SECOND = 'second', | ||
MINUTE = 'minute', | ||
HOUR = 'hour', | ||
DAY = 'day', | ||
WEEK = 'week', | ||
MONTH = 'month', | ||
QUARTER = 'quarter', | ||
YEAR = 'year', | ||
} |
75 changes: 75 additions & 0 deletions
75
services/libs/cubejs/src/metrics/activeMembersTimeseries.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,75 @@ | ||
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 members` timeseries data for a given date range in given granularity. | ||
* Members 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'], | ||
}, | ||
{ | ||
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 activeMembersTimeseries = await cjs.load({ | ||
measures: [CubeMeasures.MEMBER_COUNT], | ||
timeDimensions: [ | ||
{ | ||
dimension: CubeDimensions.ACTIVITY_DATE, | ||
dateRange: [startDate.format('YYYY-MM-DD'), endDate.format('YYYY-MM-DD')], | ||
granularity, | ||
}, | ||
], | ||
// order: { [CubeDimensions.MEMBER_JOINED_AT]: 'asc' }, | ||
filters, | ||
}) // [0][CubeMeasures.MEMBER_COUNT] ?? 0 | ||
|
||
console.log(activeMembersTimeseries) | ||
|
||
// return parseInt(activeMembers, 10) | ||
} |
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,7 @@ | ||
import CubeDimensions from 'dimensions' | ||
|
||
export interface ICubeFilter { | ||
member: CubeDimensions | ||
operator: string | ||
values: string[] | ||
} |