diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-01-17 17:16:08 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-01-17 17:16:08 +0900 |
| commit | 8d42e94e57b9426f122cee4ded52d9e640116502 (patch) | |
| tree | 4304bff191272d816f1ee5f591ac9d05cba57ed2 /src/chart/active-users.ts | |
| parent | [Client] Add information (diff) | |
| download | sharkey-8d42e94e57b9426f122cee4ded52d9e640116502.tar.gz sharkey-8d42e94e57b9426f122cee4ded52d9e640116502.tar.bz2 sharkey-8d42e94e57b9426f122cee4ded52d9e640116502.zip | |
Implement active users chart
Resolve #3904
Diffstat (limited to 'src/chart/active-users.ts')
| -rw-r--r-- | src/chart/active-users.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/chart/active-users.ts b/src/chart/active-users.ts new file mode 100644 index 0000000000..06d9b8aa90 --- /dev/null +++ b/src/chart/active-users.ts @@ -0,0 +1,48 @@ +import autobind from 'autobind-decorator'; +import Chart, { Obj } from '.'; +import { IUser, isLocalUser } from '../models/user'; + +/** + * アクティブユーザーに関するチャート + */ +type ActiveUsersLog = { + local: { + /** + * アクティブユーザー数 + */ + count: number; + }; + + remote: ActiveUsersLog['local']; +}; + +class ActiveUsersChart extends Chart<ActiveUsersLog> { + constructor() { + super('activeUsers'); + } + + @autobind + protected async getTemplate(init: boolean, latest?: ActiveUsersLog): Promise<ActiveUsersLog> { + return { + local: { + count: 0 + }, + remote: { + count: 0 + } + }; + } + + @autobind + public async update(user: IUser) { + const update: Obj = { + count: 1 + }; + + await this.incIfUnique({ + [isLocalUser(user) ? 'local' : 'remote']: update + }, 'users', user._id.toHexString()); + } +} + +export default new ActiveUsersChart(); |