@ -0,0 +1,47 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { Users } from '@/models/index';
|
||||
import { name, schema } from '../schemas/active-users';
|
||||
|
||||
type ActiveUsersLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class ActiveUsersChart extends Chart<ActiveUsersLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: ActiveUsersLog): DeepPartial<ActiveUsersLog> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: ActiveUsersLog[]): ActiveUsersLog {
|
||||
return {
|
||||
local: {
|
||||
users: logs.reduce((a, b) => a.concat(b.local.users), [] as ActiveUsersLog['local']['users']),
|
||||
},
|
||||
remote: {
|
||||
users: logs.reduce((a, b) => a.concat(b.remote.users), [] as ActiveUsersLog['remote']['users']),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<ActiveUsersLog>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: { id: User['id'], host: User['host'] }) {
|
||||
const update: Obj = {
|
||||
users: [user.id]
|
||||
};
|
||||
|
||||
await this.inc({
|
||||
[Users.isLocalUser(user) ? 'local' : 'remote']: update
|
||||
});
|
||||
}
|
||||
}
|
91
packages/backend/src/services/chart/charts/classes/drive.ts
Normal file
91
packages/backend/src/services/chart/charts/classes/drive.ts
Normal file
@ -0,0 +1,91 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { DriveFiles } from '@/models/index';
|
||||
import { Not, IsNull } from 'typeorm';
|
||||
import { DriveFile } from '@/models/entities/drive-file';
|
||||
import { name, schema } from '../schemas/drive';
|
||||
|
||||
type DriveLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class DriveChart extends Chart<DriveLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: DriveLog): DeepPartial<DriveLog> {
|
||||
return {
|
||||
local: {
|
||||
totalCount: latest.local.totalCount,
|
||||
totalSize: latest.local.totalSize,
|
||||
},
|
||||
remote: {
|
||||
totalCount: latest.remote.totalCount,
|
||||
totalSize: latest.remote.totalSize,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: DriveLog[]): DriveLog {
|
||||
return {
|
||||
local: {
|
||||
totalCount: logs[0].local.totalCount,
|
||||
totalSize: logs[0].local.totalSize,
|
||||
incCount: logs.reduce((a, b) => a + b.local.incCount, 0),
|
||||
incSize: logs.reduce((a, b) => a + b.local.incSize, 0),
|
||||
decCount: logs.reduce((a, b) => a + b.local.decCount, 0),
|
||||
decSize: logs.reduce((a, b) => a + b.local.decSize, 0),
|
||||
},
|
||||
remote: {
|
||||
totalCount: logs[0].remote.totalCount,
|
||||
totalSize: logs[0].remote.totalSize,
|
||||
incCount: logs.reduce((a, b) => a + b.remote.incCount, 0),
|
||||
incSize: logs.reduce((a, b) => a + b.remote.incSize, 0),
|
||||
decCount: logs.reduce((a, b) => a + b.remote.decCount, 0),
|
||||
decSize: logs.reduce((a, b) => a + b.remote.decSize, 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<DriveLog>> {
|
||||
const [localCount, remoteCount, localSize, remoteSize] = await Promise.all([
|
||||
DriveFiles.count({ userHost: null }),
|
||||
DriveFiles.count({ userHost: Not(IsNull()) }),
|
||||
DriveFiles.calcDriveUsageOfLocal(),
|
||||
DriveFiles.calcDriveUsageOfRemote()
|
||||
]);
|
||||
|
||||
return {
|
||||
local: {
|
||||
totalCount: localCount,
|
||||
totalSize: localSize,
|
||||
},
|
||||
remote: {
|
||||
totalCount: remoteCount,
|
||||
totalSize: remoteSize,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(file: DriveFile, isAdditional: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.totalCount = isAdditional ? 1 : -1;
|
||||
update.totalSize = isAdditional ? file.size : -file.size;
|
||||
if (isAdditional) {
|
||||
update.incCount = 1;
|
||||
update.incSize = file.size;
|
||||
} else {
|
||||
update.decCount = 1;
|
||||
update.decSize = file.size;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
[file.userHost === null ? 'local' : 'remote']: update
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { Instances } from '@/models/index';
|
||||
import { name, schema } from '../schemas/federation';
|
||||
|
||||
type FederationLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class FederationChart extends Chart<FederationLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: FederationLog): DeepPartial<FederationLog> {
|
||||
return {
|
||||
instance: {
|
||||
total: latest.instance.total,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: FederationLog[]): FederationLog {
|
||||
return {
|
||||
instance: {
|
||||
total: logs[0].instance.total,
|
||||
inc: logs.reduce((a, b) => a + b.instance.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.instance.dec, 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<FederationLog>> {
|
||||
const [total] = await Promise.all([
|
||||
Instances.count({})
|
||||
]);
|
||||
|
||||
return {
|
||||
instance: {
|
||||
total: total,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(isAdditional: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = isAdditional ? 1 : -1;
|
||||
if (isAdditional) {
|
||||
update.inc = 1;
|
||||
} else {
|
||||
update.dec = 1;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
instance: update
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { Users } from '@/models/index';
|
||||
import { name, schema } from '../schemas/hashtag';
|
||||
|
||||
type HashtagLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class HashtagChart extends Chart<HashtagLog> {
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: HashtagLog): DeepPartial<HashtagLog> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: HashtagLog[]): HashtagLog {
|
||||
return {
|
||||
local: {
|
||||
users: logs.reduce((a, b) => a.concat(b.local.users), [] as HashtagLog['local']['users']),
|
||||
},
|
||||
remote: {
|
||||
users: logs.reduce((a, b) => a.concat(b.remote.users), [] as HashtagLog['remote']['users']),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<HashtagLog>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(hashtag: string, user: { id: User['id'], host: User['host'] }) {
|
||||
const update: Obj = {
|
||||
users: [user.id]
|
||||
};
|
||||
|
||||
await this.inc({
|
||||
[Users.isLocalUser(user) ? 'local' : 'remote']: update
|
||||
}, hashtag);
|
||||
}
|
||||
}
|
217
packages/backend/src/services/chart/charts/classes/instance.ts
Normal file
217
packages/backend/src/services/chart/charts/classes/instance.ts
Normal file
@ -0,0 +1,217 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { DriveFiles, Followings, Users, Notes } from '@/models/index';
|
||||
import { DriveFile } from '@/models/entities/drive-file';
|
||||
import { name, schema } from '../schemas/instance';
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { toPuny } from '@/misc/convert-host';
|
||||
|
||||
type InstanceLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class InstanceChart extends Chart<InstanceLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: InstanceLog): DeepPartial<InstanceLog> {
|
||||
return {
|
||||
notes: {
|
||||
total: latest.notes.total,
|
||||
},
|
||||
users: {
|
||||
total: latest.users.total,
|
||||
},
|
||||
following: {
|
||||
total: latest.following.total,
|
||||
},
|
||||
followers: {
|
||||
total: latest.followers.total,
|
||||
},
|
||||
drive: {
|
||||
totalFiles: latest.drive.totalFiles,
|
||||
totalUsage: latest.drive.totalUsage,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: InstanceLog[]): InstanceLog {
|
||||
return {
|
||||
requests: {
|
||||
failed: logs.reduce((a, b) => a + b.requests.failed, 0),
|
||||
succeeded: logs.reduce((a, b) => a + b.requests.succeeded, 0),
|
||||
received: logs.reduce((a, b) => a + b.requests.received, 0),
|
||||
},
|
||||
notes: {
|
||||
total: logs[0].notes.total,
|
||||
inc: logs.reduce((a, b) => a + b.notes.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.notes.dec, 0),
|
||||
diffs: {
|
||||
reply: logs.reduce((a, b) => a + b.notes.diffs.reply, 0),
|
||||
renote: logs.reduce((a, b) => a + b.notes.diffs.renote, 0),
|
||||
normal: logs.reduce((a, b) => a + b.notes.diffs.normal, 0),
|
||||
},
|
||||
},
|
||||
users: {
|
||||
total: logs[0].users.total,
|
||||
inc: logs.reduce((a, b) => a + b.users.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.users.dec, 0),
|
||||
},
|
||||
following: {
|
||||
total: logs[0].following.total,
|
||||
inc: logs.reduce((a, b) => a + b.following.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.following.dec, 0),
|
||||
},
|
||||
followers: {
|
||||
total: logs[0].followers.total,
|
||||
inc: logs.reduce((a, b) => a + b.followers.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.followers.dec, 0),
|
||||
},
|
||||
drive: {
|
||||
totalFiles: logs[0].drive.totalFiles,
|
||||
totalUsage: logs[0].drive.totalUsage,
|
||||
incFiles: logs.reduce((a, b) => a + b.drive.incFiles, 0),
|
||||
incUsage: logs.reduce((a, b) => a + b.drive.incUsage, 0),
|
||||
decFiles: logs.reduce((a, b) => a + b.drive.decFiles, 0),
|
||||
decUsage: logs.reduce((a, b) => a + b.drive.decUsage, 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<InstanceLog>> {
|
||||
const [
|
||||
notesCount,
|
||||
usersCount,
|
||||
followingCount,
|
||||
followersCount,
|
||||
driveFiles,
|
||||
driveUsage,
|
||||
] = await Promise.all([
|
||||
Notes.count({ userHost: group }),
|
||||
Users.count({ host: group }),
|
||||
Followings.count({ followerHost: group }),
|
||||
Followings.count({ followeeHost: group }),
|
||||
DriveFiles.count({ userHost: group }),
|
||||
DriveFiles.calcDriveUsageOfHost(group),
|
||||
]);
|
||||
|
||||
return {
|
||||
notes: {
|
||||
total: notesCount,
|
||||
},
|
||||
users: {
|
||||
total: usersCount,
|
||||
},
|
||||
following: {
|
||||
total: followingCount,
|
||||
},
|
||||
followers: {
|
||||
total: followersCount,
|
||||
},
|
||||
drive: {
|
||||
totalFiles: driveFiles,
|
||||
totalUsage: driveUsage,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async requestReceived(host: string) {
|
||||
await this.inc({
|
||||
requests: {
|
||||
received: 1
|
||||
}
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async requestSent(host: string, isSucceeded: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
if (isSucceeded) {
|
||||
update.succeeded = 1;
|
||||
} else {
|
||||
update.failed = 1;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
requests: update
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async newUser(host: string) {
|
||||
await this.inc({
|
||||
users: {
|
||||
total: 1,
|
||||
inc: 1
|
||||
}
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateNote(host: string, note: Note, isAdditional: boolean) {
|
||||
const diffs = {} as any;
|
||||
|
||||
if (note.replyId != null) {
|
||||
diffs.reply = isAdditional ? 1 : -1;
|
||||
} else if (note.renoteId != null) {
|
||||
diffs.renote = isAdditional ? 1 : -1;
|
||||
} else {
|
||||
diffs.normal = isAdditional ? 1 : -1;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
notes: {
|
||||
total: isAdditional ? 1 : -1,
|
||||
inc: isAdditional ? 1 : 0,
|
||||
dec: isAdditional ? 0 : 1,
|
||||
diffs: diffs
|
||||
}
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateFollowing(host: string, isAdditional: boolean) {
|
||||
await this.inc({
|
||||
following: {
|
||||
total: isAdditional ? 1 : -1,
|
||||
inc: isAdditional ? 1 : 0,
|
||||
dec: isAdditional ? 0 : 1,
|
||||
}
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateFollowers(host: string, isAdditional: boolean) {
|
||||
await this.inc({
|
||||
followers: {
|
||||
total: isAdditional ? 1 : -1,
|
||||
inc: isAdditional ? 1 : 0,
|
||||
dec: isAdditional ? 0 : 1,
|
||||
}
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateDrive(file: DriveFile, isAdditional: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.totalFiles = isAdditional ? 1 : -1;
|
||||
update.totalUsage = isAdditional ? file.size : -file.size;
|
||||
if (isAdditional) {
|
||||
update.incFiles = 1;
|
||||
update.incUsage = file.size;
|
||||
} else {
|
||||
update.decFiles = 1;
|
||||
update.decUsage = file.size;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
drive: update
|
||||
}, file.userHost);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { name, schema } from '../schemas/network';
|
||||
|
||||
type NetworkLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class NetworkChart extends Chart<NetworkLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: NetworkLog): DeepPartial<NetworkLog> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: NetworkLog[]): NetworkLog {
|
||||
return {
|
||||
incomingRequests: logs.reduce((a, b) => a + b.incomingRequests, 0),
|
||||
outgoingRequests: logs.reduce((a, b) => a + b.outgoingRequests, 0),
|
||||
totalTime: logs.reduce((a, b) => a + b.totalTime, 0),
|
||||
incomingBytes: logs.reduce((a, b) => a + b.incomingBytes, 0),
|
||||
outgoingBytes: logs.reduce((a, b) => a + b.outgoingBytes, 0),
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<NetworkLog>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(incomingRequests: number, time: number, incomingBytes: number, outgoingBytes: number) {
|
||||
const inc: DeepPartial<NetworkLog> = {
|
||||
incomingRequests: incomingRequests,
|
||||
totalTime: time,
|
||||
incomingBytes: incomingBytes,
|
||||
outgoingBytes: outgoingBytes
|
||||
};
|
||||
|
||||
await this.inc(inc);
|
||||
}
|
||||
}
|
97
packages/backend/src/services/chart/charts/classes/notes.ts
Normal file
97
packages/backend/src/services/chart/charts/classes/notes.ts
Normal file
@ -0,0 +1,97 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { Notes } from '@/models/index';
|
||||
import { Not, IsNull } from 'typeorm';
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { name, schema } from '../schemas/notes';
|
||||
|
||||
type NotesLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class NotesChart extends Chart<NotesLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: NotesLog): DeepPartial<NotesLog> {
|
||||
return {
|
||||
local: {
|
||||
total: latest.local.total,
|
||||
},
|
||||
remote: {
|
||||
total: latest.remote.total,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: NotesLog[]): NotesLog {
|
||||
return {
|
||||
local: {
|
||||
total: logs[0].local.total,
|
||||
inc: logs.reduce((a, b) => a + b.local.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.local.dec, 0),
|
||||
diffs: {
|
||||
reply: logs.reduce((a, b) => a + b.local.diffs.reply, 0),
|
||||
renote: logs.reduce((a, b) => a + b.local.diffs.renote, 0),
|
||||
normal: logs.reduce((a, b) => a + b.local.diffs.normal, 0),
|
||||
},
|
||||
},
|
||||
remote: {
|
||||
total: logs[0].remote.total,
|
||||
inc: logs.reduce((a, b) => a + b.remote.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.remote.dec, 0),
|
||||
diffs: {
|
||||
reply: logs.reduce((a, b) => a + b.remote.diffs.reply, 0),
|
||||
renote: logs.reduce((a, b) => a + b.remote.diffs.renote, 0),
|
||||
normal: logs.reduce((a, b) => a + b.remote.diffs.normal, 0),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<NotesLog>> {
|
||||
const [localCount, remoteCount] = await Promise.all([
|
||||
Notes.count({ userHost: null }),
|
||||
Notes.count({ userHost: Not(IsNull()) })
|
||||
]);
|
||||
|
||||
return {
|
||||
local: {
|
||||
total: localCount,
|
||||
},
|
||||
remote: {
|
||||
total: remoteCount,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(note: Note, isAdditional: boolean) {
|
||||
const update: Obj = {
|
||||
diffs: {}
|
||||
};
|
||||
|
||||
update.total = isAdditional ? 1 : -1;
|
||||
|
||||
if (isAdditional) {
|
||||
update.inc = 1;
|
||||
} else {
|
||||
update.dec = 1;
|
||||
}
|
||||
|
||||
if (note.replyId != null) {
|
||||
update.diffs.reply = isAdditional ? 1 : -1;
|
||||
} else if (note.renoteId != null) {
|
||||
update.diffs.renote = isAdditional ? 1 : -1;
|
||||
} else {
|
||||
update.diffs.normal = isAdditional ? 1 : -1;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
[note.userHost === null ? 'local' : 'remote']: update
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { DriveFiles } from '@/models/index';
|
||||
import { DriveFile } from '@/models/entities/drive-file';
|
||||
import { name, schema } from '../schemas/per-user-drive';
|
||||
|
||||
type PerUserDriveLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class PerUserDriveChart extends Chart<PerUserDriveLog> {
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: PerUserDriveLog): DeepPartial<PerUserDriveLog> {
|
||||
return {
|
||||
totalCount: latest.totalCount,
|
||||
totalSize: latest.totalSize,
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: PerUserDriveLog[]): PerUserDriveLog {
|
||||
return {
|
||||
totalCount: logs[0].totalCount,
|
||||
totalSize: logs[0].totalSize,
|
||||
incCount: logs.reduce((a, b) => a + b.incCount, 0),
|
||||
incSize: logs.reduce((a, b) => a + b.incSize, 0),
|
||||
decCount: logs.reduce((a, b) => a + b.decCount, 0),
|
||||
decSize: logs.reduce((a, b) => a + b.decSize, 0),
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<PerUserDriveLog>> {
|
||||
const [count, size] = await Promise.all([
|
||||
DriveFiles.count({ userId: group }),
|
||||
DriveFiles.calcDriveUsageOf(group)
|
||||
]);
|
||||
|
||||
return {
|
||||
totalCount: count,
|
||||
totalSize: size,
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(file: DriveFile, isAdditional: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.totalCount = isAdditional ? 1 : -1;
|
||||
update.totalSize = isAdditional ? file.size : -file.size;
|
||||
if (isAdditional) {
|
||||
update.incCount = 1;
|
||||
update.incSize = file.size;
|
||||
} else {
|
||||
update.decCount = 1;
|
||||
update.decSize = file.size;
|
||||
}
|
||||
|
||||
await this.inc(update, file.userId);
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { Followings, Users } from '@/models/index';
|
||||
import { Not, IsNull } from 'typeorm';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { name, schema } from '../schemas/per-user-following';
|
||||
|
||||
type PerUserFollowingLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class PerUserFollowingChart extends Chart<PerUserFollowingLog> {
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: PerUserFollowingLog): DeepPartial<PerUserFollowingLog> {
|
||||
return {
|
||||
local: {
|
||||
followings: {
|
||||
total: latest.local.followings.total,
|
||||
},
|
||||
followers: {
|
||||
total: latest.local.followers.total,
|
||||
}
|
||||
},
|
||||
remote: {
|
||||
followings: {
|
||||
total: latest.remote.followings.total,
|
||||
},
|
||||
followers: {
|
||||
total: latest.remote.followers.total,
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: PerUserFollowingLog[]): PerUserFollowingLog {
|
||||
return {
|
||||
local: {
|
||||
followings: {
|
||||
total: logs[0].local.followings.total,
|
||||
inc: logs.reduce((a, b) => a + b.local.followings.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.local.followings.dec, 0),
|
||||
},
|
||||
followers: {
|
||||
total: logs[0].local.followers.total,
|
||||
inc: logs.reduce((a, b) => a + b.local.followers.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.local.followers.dec, 0),
|
||||
},
|
||||
},
|
||||
remote: {
|
||||
followings: {
|
||||
total: logs[0].remote.followings.total,
|
||||
inc: logs.reduce((a, b) => a + b.remote.followings.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.remote.followings.dec, 0),
|
||||
},
|
||||
followers: {
|
||||
total: logs[0].remote.followers.total,
|
||||
inc: logs.reduce((a, b) => a + b.remote.followers.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.remote.followers.dec, 0),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<PerUserFollowingLog>> {
|
||||
const [
|
||||
localFollowingsCount,
|
||||
localFollowersCount,
|
||||
remoteFollowingsCount,
|
||||
remoteFollowersCount
|
||||
] = await Promise.all([
|
||||
Followings.count({ followerId: group, followeeHost: null }),
|
||||
Followings.count({ followeeId: group, followerHost: null }),
|
||||
Followings.count({ followerId: group, followeeHost: Not(IsNull()) }),
|
||||
Followings.count({ followeeId: group, followerHost: Not(IsNull()) })
|
||||
]);
|
||||
|
||||
return {
|
||||
local: {
|
||||
followings: {
|
||||
total: localFollowingsCount,
|
||||
},
|
||||
followers: {
|
||||
total: localFollowersCount,
|
||||
}
|
||||
},
|
||||
remote: {
|
||||
followings: {
|
||||
total: remoteFollowingsCount,
|
||||
},
|
||||
followers: {
|
||||
total: remoteFollowersCount,
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(follower: { id: User['id']; host: User['host']; }, followee: { id: User['id']; host: User['host']; }, isFollow: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = isFollow ? 1 : -1;
|
||||
|
||||
if (isFollow) {
|
||||
update.inc = 1;
|
||||
} else {
|
||||
update.dec = 1;
|
||||
}
|
||||
|
||||
this.inc({
|
||||
[Users.isLocalUser(follower) ? 'local' : 'remote']: { followings: update }
|
||||
}, follower.id);
|
||||
this.inc({
|
||||
[Users.isLocalUser(followee) ? 'local' : 'remote']: { followers: update }
|
||||
}, followee.id);
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { Notes } from '@/models/index';
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { name, schema } from '../schemas/per-user-notes';
|
||||
|
||||
type PerUserNotesLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class PerUserNotesChart extends Chart<PerUserNotesLog> {
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: PerUserNotesLog): DeepPartial<PerUserNotesLog> {
|
||||
return {
|
||||
total: latest.total,
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: PerUserNotesLog[]): PerUserNotesLog {
|
||||
return {
|
||||
total: logs[0].total,
|
||||
inc: logs.reduce((a, b) => a + b.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.dec, 0),
|
||||
diffs: {
|
||||
reply: logs.reduce((a, b) => a + b.diffs.reply, 0),
|
||||
renote: logs.reduce((a, b) => a + b.diffs.renote, 0),
|
||||
normal: logs.reduce((a, b) => a + b.diffs.normal, 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<PerUserNotesLog>> {
|
||||
const [count] = await Promise.all([
|
||||
Notes.count({ userId: group }),
|
||||
]);
|
||||
|
||||
return {
|
||||
total: count,
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: { id: User['id'] }, note: Note, isAdditional: boolean) {
|
||||
const update: Obj = {
|
||||
diffs: {}
|
||||
};
|
||||
|
||||
update.total = isAdditional ? 1 : -1;
|
||||
|
||||
if (isAdditional) {
|
||||
update.inc = 1;
|
||||
} else {
|
||||
update.dec = 1;
|
||||
}
|
||||
|
||||
if (note.replyId != null) {
|
||||
update.diffs.reply = isAdditional ? 1 : -1;
|
||||
} else if (note.renoteId != null) {
|
||||
update.diffs.renote = isAdditional ? 1 : -1;
|
||||
} else {
|
||||
update.diffs.normal = isAdditional ? 1 : -1;
|
||||
}
|
||||
|
||||
await this.inc(update, user.id);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { DeepPartial } from '../../core';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { Users } from '@/models/index';
|
||||
import { name, schema } from '../schemas/per-user-reactions';
|
||||
|
||||
type PerUserReactionsLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class PerUserReactionsChart extends Chart<PerUserReactionsLog> {
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: PerUserReactionsLog): DeepPartial<PerUserReactionsLog> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: PerUserReactionsLog[]): PerUserReactionsLog {
|
||||
return {
|
||||
local: {
|
||||
count: logs.reduce((a, b) => a + b.local.count, 0),
|
||||
},
|
||||
remote: {
|
||||
count: logs.reduce((a, b) => a + b.remote.count, 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<PerUserReactionsLog>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: { id: User['id'], host: User['host'] }, note: Note) {
|
||||
this.inc({
|
||||
[Users.isLocalUser(user) ? 'local' : 'remote']: { count: 1 }
|
||||
}, note.userId);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { name, schema } from '../schemas/test-grouped';
|
||||
|
||||
type TestGroupedLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class TestGroupedChart extends Chart<TestGroupedLog> {
|
||||
private total = {} as Record<string, number>;
|
||||
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: TestGroupedLog): DeepPartial<TestGroupedLog> {
|
||||
return {
|
||||
foo: {
|
||||
total: latest.foo.total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: TestGroupedLog[]): TestGroupedLog {
|
||||
return {
|
||||
foo: {
|
||||
total: logs[0].foo.total,
|
||||
inc: logs.reduce((a, b) => a + b.foo.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.foo.dec, 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<TestGroupedLog>> {
|
||||
return {
|
||||
foo: {
|
||||
total: this.total[group],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async increment(group: string) {
|
||||
if (this.total[group] == null) this.total[group] = 0;
|
||||
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = 1;
|
||||
update.inc = 1;
|
||||
this.total[group]++;
|
||||
|
||||
await this.inc({
|
||||
foo: update
|
||||
}, group);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { name, schema } from '../schemas/test-unique';
|
||||
|
||||
type TestUniqueLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class TestUniqueChart extends Chart<TestUniqueLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: TestUniqueLog): DeepPartial<TestUniqueLog> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: TestUniqueLog[]): TestUniqueLog {
|
||||
return {
|
||||
foo: logs.reduce((a, b) => a.concat(b.foo), [] as TestUniqueLog['foo']),
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<TestUniqueLog>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async uniqueIncrement(key: string) {
|
||||
await this.inc({
|
||||
foo: [key]
|
||||
});
|
||||
}
|
||||
}
|
69
packages/backend/src/services/chart/charts/classes/test.ts
Normal file
69
packages/backend/src/services/chart/charts/classes/test.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { name, schema } from '../schemas/test';
|
||||
|
||||
type TestLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class TestChart extends Chart<TestLog> {
|
||||
public total = 0; // publicにするのはテストのため
|
||||
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: TestLog): DeepPartial<TestLog> {
|
||||
return {
|
||||
foo: {
|
||||
total: latest.foo.total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: TestLog[]): TestLog {
|
||||
return {
|
||||
foo: {
|
||||
total: logs[0].foo.total,
|
||||
inc: logs.reduce((a, b) => a + b.foo.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.foo.dec, 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<TestLog>> {
|
||||
return {
|
||||
foo: {
|
||||
total: this.total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async increment() {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = 1;
|
||||
update.inc = 1;
|
||||
this.total++;
|
||||
|
||||
await this.inc({
|
||||
foo: update
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async decrement() {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = -1;
|
||||
update.dec = 1;
|
||||
this.total--;
|
||||
|
||||
await this.inc({
|
||||
foo: update
|
||||
});
|
||||
}
|
||||
}
|
76
packages/backend/src/services/chart/charts/classes/users.ts
Normal file
76
packages/backend/src/services/chart/charts/classes/users.ts
Normal file
@ -0,0 +1,76 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { Users } from '@/models/index';
|
||||
import { Not, IsNull } from 'typeorm';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { name, schema } from '../schemas/users';
|
||||
|
||||
type UsersLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class UsersChart extends Chart<UsersLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: UsersLog): DeepPartial<UsersLog> {
|
||||
return {
|
||||
local: {
|
||||
total: latest.local.total,
|
||||
},
|
||||
remote: {
|
||||
total: latest.remote.total,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: UsersLog[]): UsersLog {
|
||||
return {
|
||||
local: {
|
||||
total: logs[0].local.total,
|
||||
inc: logs.reduce((a, b) => a + b.local.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.local.dec, 0),
|
||||
},
|
||||
remote: {
|
||||
total: logs[0].remote.total,
|
||||
inc: logs.reduce((a, b) => a + b.remote.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.remote.dec, 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<UsersLog>> {
|
||||
const [localCount, remoteCount] = await Promise.all([
|
||||
Users.count({ host: null }),
|
||||
Users.count({ host: Not(IsNull()) })
|
||||
]);
|
||||
|
||||
return {
|
||||
local: {
|
||||
total: localCount,
|
||||
},
|
||||
remote: {
|
||||
total: remoteCount,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: { id: User['id'], host: User['host'] }, isAdditional: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = isAdditional ? 1 : -1;
|
||||
if (isAdditional) {
|
||||
update.inc = 1;
|
||||
} else {
|
||||
update.dec = 1;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
[Users.isLocalUser(user) ? 'local' : 'remote']: update
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
export const logSchema = {
|
||||
/**
|
||||
* アクティブユーザー
|
||||
*/
|
||||
users: {
|
||||
type: 'array' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
items: {
|
||||
type: 'string' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* アクティブユーザーに関するチャート
|
||||
*/
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
local: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
remote: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'activeUsers';
|
68
packages/backend/src/services/chart/charts/schemas/drive.ts
Normal file
68
packages/backend/src/services/chart/charts/schemas/drive.ts
Normal file
@ -0,0 +1,68 @@
|
||||
const logSchema = {
|
||||
/**
|
||||
* 集計期間時点での、全ドライブファイル数
|
||||
*/
|
||||
totalCount: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 集計期間時点での、全ドライブファイルの合計サイズ
|
||||
*/
|
||||
totalSize: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 増加したドライブファイル数
|
||||
*/
|
||||
incCount: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 増加したドライブ使用量
|
||||
*/
|
||||
incSize: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 減少したドライブファイル数
|
||||
*/
|
||||
decCount: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 減少したドライブ使用量
|
||||
*/
|
||||
decSize: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
};
|
||||
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
local: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
remote: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'drive';
|
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* フェデレーションに関するチャート
|
||||
*/
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
instance: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'federation';
|
@ -0,0 +1,35 @@
|
||||
export const logSchema = {
|
||||
/**
|
||||
* 投稿したユーザー
|
||||
*/
|
||||
users: {
|
||||
type: 'array' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
items: {
|
||||
type: 'string' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* ハッシュタグに関するチャート
|
||||
*/
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
local: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
remote: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'hashtag';
|
157
packages/backend/src/services/chart/charts/schemas/instance.ts
Normal file
157
packages/backend/src/services/chart/charts/schemas/instance.ts
Normal file
@ -0,0 +1,157 @@
|
||||
/**
|
||||
* インスタンスごとのチャート
|
||||
*/
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
requests: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
failed: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
succeeded: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
received: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
notes: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
diffs: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
normal: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
reply: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
renote: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
users: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
following: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
followers: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
drive: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
totalFiles: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
totalUsage: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
incFiles: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
incUsage: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
decFiles: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
decUsage: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'instance';
|
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* ネットワークに関するチャート
|
||||
*/
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
incomingRequests: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
outgoingRequests: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
totalTime: { // TIP: (totalTime / incomingRequests) でひとつのリクエストに平均でどれくらいの時間がかかったか知れる
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
incomingBytes: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
outgoingBytes: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'network';
|
56
packages/backend/src/services/chart/charts/schemas/notes.ts
Normal file
56
packages/backend/src/services/chart/charts/schemas/notes.ts
Normal file
@ -0,0 +1,56 @@
|
||||
const logSchema = {
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
diffs: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
normal: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
reply: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
renote: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
local: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
remote: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'notes';
|
@ -0,0 +1,55 @@
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
/**
|
||||
* 集計期間時点での、全ドライブファイル数
|
||||
*/
|
||||
totalCount: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 集計期間時点での、全ドライブファイルの合計サイズ
|
||||
*/
|
||||
totalSize: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 増加したドライブファイル数
|
||||
*/
|
||||
incCount: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 増加したドライブ使用量
|
||||
*/
|
||||
incSize: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 減少したドライブファイル数
|
||||
*/
|
||||
decCount: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 減少したドライブ使用量
|
||||
*/
|
||||
decSize: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'perUserDrive';
|
@ -0,0 +1,86 @@
|
||||
export const logSchema = {
|
||||
/**
|
||||
* フォローしている
|
||||
*/
|
||||
followings: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
/**
|
||||
* フォローしている合計
|
||||
*/
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* フォローした数
|
||||
*/
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* フォロー解除した数
|
||||
*/
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* フォローされている
|
||||
*/
|
||||
followers: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
/**
|
||||
* フォローされている合計
|
||||
*/
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* フォローされた数
|
||||
*/
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* フォロー解除された数
|
||||
*/
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
local: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
remote: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'perUserFollowing';
|
@ -0,0 +1,43 @@
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
diffs: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
normal: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
reply: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
renote: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'perUserNotes';
|
@ -0,0 +1,31 @@
|
||||
export const logSchema = {
|
||||
/**
|
||||
* フォローしている合計
|
||||
*/
|
||||
count: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* ユーザーごとのリアクションに関するチャート
|
||||
*/
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
local: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
remote: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'perUserReaction';
|
@ -0,0 +1,28 @@
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'testGrouped';
|
@ -0,0 +1,16 @@
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'array' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
items: {
|
||||
type: 'string' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'testUnique';
|
28
packages/backend/src/services/chart/charts/schemas/test.ts
Normal file
28
packages/backend/src/services/chart/charts/schemas/test.ts
Normal file
@ -0,0 +1,28 @@
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'test';
|
44
packages/backend/src/services/chart/charts/schemas/users.ts
Normal file
44
packages/backend/src/services/chart/charts/schemas/users.ts
Normal file
@ -0,0 +1,44 @@
|
||||
const logSchema = {
|
||||
/**
|
||||
* 集計期間時点での、全ユーザー数
|
||||
*/
|
||||
total: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 増加したユーザー数
|
||||
*/
|
||||
inc: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
|
||||
/**
|
||||
* 減少したユーザー数
|
||||
*/
|
||||
dec: {
|
||||
type: 'number' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
},
|
||||
};
|
||||
|
||||
export const schema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
local: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
remote: {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: logSchema
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const name = 'users';
|
Reference in New Issue
Block a user