This commit is contained in:
syuilo 2018-10-22 17:36:36 +09:00
parent e9a8090d7e
commit 3bebf82501
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
3 changed files with 87 additions and 0 deletions

View file

@ -0,0 +1,41 @@
import $ from 'cafy';
import getParams from '../../../get-params';
import { perUserReactionsStats } from '../../../../../services/stats';
import ID from '../../../../../misc/cafy-id';
export const meta = {
desc: {
'ja-JP': 'ユーザーごとの被リアクション数の統計を取得します。'
},
params: {
span: $.str.or(['day', 'hour']).note({
desc: {
'ja-JP': '集計のスパン (day または hour)'
}
}),
limit: $.num.optional.range(1, 100).note({
default: 30,
desc: {
'ja-JP': '最大数。例えば 30 を指定したとすると、スパンが"day"の場合は30日分のデータが、スパンが"hour"の場合は30時間分のデータが返ります。'
}
}),
userId: $.type(ID).note({
desc: {
'ja-JP': '対象のユーザーのID',
'en-US': 'Target user ID'
}
})
}
};
export default (params: any) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
const stats = await perUserReactionsStats.getChart(ps.span as any, ps.limit, ps.userId);
res(stats);
});

View file

@ -8,6 +8,7 @@ import watch from '../watch';
import renderLike from '../../../remote/activitypub/renderer/like'; import renderLike from '../../../remote/activitypub/renderer/like';
import { deliver } from '../../../queue'; import { deliver } from '../../../queue';
import pack from '../../../remote/activitypub/renderer'; import pack from '../../../remote/activitypub/renderer';
import { perUserReactionsStats } from '../../stats';
export default async (user: IUser, note: INote, reaction: string) => new Promise(async (res, rej) => { export default async (user: IUser, note: INote, reaction: string) => new Promise(async (res, rej) => {
// Myself // Myself
@ -43,6 +44,8 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise
$inc: inc $inc: inc
}); });
perUserReactionsStats.update(user, note);
publishNoteStream(note._id, 'reacted', { publishNoteStream(note._id, 'reacted', {
reaction: reaction, reaction: reaction,
userId: user._id userId: user._id

View file

@ -912,6 +912,49 @@ class PerUserNotesStats extends Stats<PerUserNotesLog> {
export const perUserNotesStats = new PerUserNotesStats(); export const perUserNotesStats = new PerUserNotesStats();
//#endregion //#endregion
//#region Per user reactions stats
/**
*
*/
type PerUserReactionsLog = {
local: {
/**
*
*/
count: number;
};
remote: PerUserReactionsLog['local'];
};
class PerUserReactionsStats extends Stats<PerUserReactionsLog> {
constructor() {
super('perUserReaction', true);
}
@autobind
protected async getTemplate(init: boolean, latest?: PerUserReactionsLog, group?: any): Promise<PerUserReactionsLog> {
return {
local: {
count: 0
},
remote: {
count: 0
}
};
}
@autobind
public async update(user: IUser, note: INote) {
this.inc({
[isLocalUser(user) ? 'local' : 'remote']: { count: 1 }
}, note.userId);
}
}
export const perUserReactionsStats = new PerUserReactionsStats();
//#endregion
//#region Per user drive stats //#region Per user drive stats
/** /**
* *