This commit is contained in:
syuilo 2018-08-25 08:35:41 +09:00
parent 9d85d0bb08
commit 7b6e55047f
4 changed files with 374 additions and 103 deletions

View File

@ -55,10 +55,10 @@ export default Vue.extend({
case 'local-notes': return this.notesChart('local'); case 'local-notes': return this.notesChart('local');
case 'remote-notes': return this.notesChart('remote'); case 'remote-notes': return this.notesChart('remote');
case 'notes-total': return this.notesTotalChart(); case 'notes-total': return this.notesTotalChart();
case 'drive': return this.driveChart(false); case 'drive': return this.driveChart();
case 'drive-total': return this.driveChart(true); case 'drive-total': return this.driveTotalChart();
case 'drive-files': return this.driveFilesChart(false); case 'drive-files': return this.driveFilesChart();
case 'drive-files-total': return this.driveFilesChart(true); case 'drive-files-total': return this.driveFilesTotalChart();
} }
}, },
stats(): any[] { stats(): any[] {
@ -81,7 +81,7 @@ export default Vue.extend({
normal: type == 'local' ? x.notes.local.diffs.normal : type == 'remote' ? x.notes.remote.diffs.normal : x.notes.local.diffs.normal + x.notes.remote.diffs.normal, normal: type == 'local' ? x.notes.local.diffs.normal : type == 'remote' ? x.notes.remote.diffs.normal : x.notes.local.diffs.normal + x.notes.remote.diffs.normal,
reply: type == 'local' ? x.notes.local.diffs.reply : type == 'remote' ? x.notes.remote.diffs.reply : x.notes.local.diffs.reply + x.notes.remote.diffs.reply, reply: type == 'local' ? x.notes.local.diffs.reply : type == 'remote' ? x.notes.remote.diffs.reply : x.notes.local.diffs.reply + x.notes.remote.diffs.reply,
renote: type == 'local' ? x.notes.local.diffs.renote : type == 'remote' ? x.notes.remote.diffs.renote : x.notes.local.diffs.renote + x.notes.remote.diffs.renote, renote: type == 'local' ? x.notes.local.diffs.renote : type == 'remote' ? x.notes.remote.diffs.renote : x.notes.local.diffs.renote + x.notes.remote.diffs.renote,
all: type == 'local' ? x.notes.local.diff : type == 'remote' ? x.notes.remote.diff : x.notes.local.diff + x.notes.remote.diff all: type == 'local' ? (x.notes.local.inc + -x.notes.local.dec) : type == 'remote' ? (x.notes.remote.inc + -x.notes.remote.dec) : (x.notes.local.inc + -x.notes.local.dec) + (x.notes.remote.inc + -x.notes.remote.dec)
})); }));
return [{ return [{
@ -152,7 +152,7 @@ export default Vue.extend({
return [{ return [{
datasets: [{ datasets: [{
label: 'Notes', label: 'Combined',
fill: false, fill: false,
borderColor: '#555', borderColor: '#555',
borderWidth: 2, borderWidth: 2,
@ -161,7 +161,7 @@ export default Vue.extend({
lineTension: 0, lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteCount + x.localCount })) data: data.map(x => ({ t: x.date, y: x.remoteCount + x.localCount }))
}, { }, {
label: 'Remote Notes', label: 'Remote',
fill: true, fill: true,
backgroundColor: 'rgba(65, 221, 222, 0.1)', backgroundColor: 'rgba(65, 221, 222, 0.1)',
borderColor: '#41ddde', borderColor: '#41ddde',
@ -170,7 +170,7 @@ export default Vue.extend({
lineTension: 0, lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteCount })) data: data.map(x => ({ t: x.date, y: x.remoteCount }))
}, { }, {
label: 'Local Notes', label: 'Local',
fill: true, fill: true,
backgroundColor: 'rgba(246, 88, 79, 0.1)', backgroundColor: 'rgba(246, 88, 79, 0.1)',
borderColor: '#f6584f', borderColor: '#f6584f',
@ -203,13 +203,13 @@ export default Vue.extend({
usersChart(total: boolean): any { usersChart(total: boolean): any {
const data = this.stats.slice().reverse().map(x => ({ const data = this.stats.slice().reverse().map(x => ({
date: new Date(x.date), date: new Date(x.date),
localCount: total ? x.users.local.total : x.users.local.diff, localCount: total ? x.users.local.total : (x.users.local.inc + -x.users.local.dec),
remoteCount: total ? x.users.remote.total : x.users.remote.diff remoteCount: total ? x.users.remote.total : (x.users.remote.inc + -x.users.remote.dec)
})); }));
return [{ return [{
datasets: [{ datasets: [{
label: 'Users', label: 'Combined',
fill: false, fill: false,
borderColor: '#555', borderColor: '#555',
borderWidth: 2, borderWidth: 2,
@ -218,7 +218,7 @@ export default Vue.extend({
lineTension: 0, lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteCount + x.localCount })) data: data.map(x => ({ t: x.date, y: x.remoteCount + x.localCount }))
}, { }, {
label: 'Remote Users', label: 'Remote',
fill: true, fill: true,
backgroundColor: 'rgba(65, 221, 222, 0.1)', backgroundColor: 'rgba(65, 221, 222, 0.1)',
borderColor: '#41ddde', borderColor: '#41ddde',
@ -227,7 +227,7 @@ export default Vue.extend({
lineTension: 0, lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteCount })) data: data.map(x => ({ t: x.date, y: x.remoteCount }))
}, { }, {
label: 'Local Users', label: 'Local',
fill: true, fill: true,
backgroundColor: 'rgba(246, 88, 79, 0.1)', backgroundColor: 'rgba(246, 88, 79, 0.1)',
borderColor: '#f6584f', borderColor: '#f6584f',
@ -257,16 +257,93 @@ export default Vue.extend({
}]; }];
}, },
driveChart(total: boolean): any { driveChart(): any {
const data = this.stats.slice().reverse().map(x => ({ const data = this.stats.slice().reverse().map(x => ({
date: new Date(x.date), date: new Date(x.date),
localSize: total ? x.drive.local.totalSize : x.drive.local.diffSize, localInc: x.drive.local.incSize,
remoteSize: total ? x.drive.remote.totalSize : x.drive.remote.diffSize localDec: -x.drive.local.decSize,
remoteInc: x.drive.remote.incSize,
remoteDec: -x.drive.remote.decSize,
})); }));
return [{ return [{
datasets: [{ datasets: [{
label: 'Drive Usage', label: 'All',
fill: false,
borderColor: '#555',
borderWidth: 2,
borderDash: [4, 4],
pointBackgroundColor: '#fff',
lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.localInc + x.localDec + x.remoteInc + x.remoteDec }))
}, {
label: 'Remote +',
fill: true,
backgroundColor: 'rgba(65, 221, 222, 0.1)',
borderColor: '#41ddde',
borderWidth: 2,
pointBackgroundColor: '#fff',
lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteInc }))
}, {
label: 'Remote -',
fill: true,
backgroundColor: 'rgba(65, 221, 222, 0.1)',
borderColor: '#41ddde',
borderWidth: 2,
pointBackgroundColor: '#fff',
lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteDec }))
}, {
label: 'Local +',
fill: true,
backgroundColor: 'rgba(246, 88, 79, 0.1)',
borderColor: '#f6584f',
borderWidth: 2,
pointBackgroundColor: '#fff',
lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.localInc }))
}, {
label: 'Local -',
fill: true,
backgroundColor: 'rgba(246, 88, 79, 0.1)',
borderColor: '#f6584f',
borderWidth: 2,
pointBackgroundColor: '#fff',
lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.localDec }))
}]
}, {
scales: {
yAxes: [{
ticks: {
callback: value => {
return Vue.filter('bytes')(value);
}
}
}]
},
tooltips: {
callbacks: {
label: (tooltipItem, data) => {
const label = data.datasets[tooltipItem.datasetIndex].label || '';
return `${label}: ${Vue.filter('bytes')(tooltipItem.yLabel)}`;
}
}
}
}];
},
driveTotalChart(): any {
const data = this.stats.slice().reverse().map(x => ({
date: new Date(x.date),
localSize: x.drive.local.totalSize,
remoteSize: x.drive.remote.totalSize
}));
return [{
datasets: [{
label: 'Combined',
fill: false, fill: false,
borderColor: '#555', borderColor: '#555',
borderWidth: 2, borderWidth: 2,
@ -275,7 +352,7 @@ export default Vue.extend({
lineTension: 0, lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteSize + x.localSize })) data: data.map(x => ({ t: x.date, y: x.remoteSize + x.localSize }))
}, { }, {
label: 'Remote Drive Usage', label: 'Remote',
fill: true, fill: true,
backgroundColor: 'rgba(65, 221, 222, 0.1)', backgroundColor: 'rgba(65, 221, 222, 0.1)',
borderColor: '#41ddde', borderColor: '#41ddde',
@ -284,7 +361,7 @@ export default Vue.extend({
lineTension: 0, lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteSize })) data: data.map(x => ({ t: x.date, y: x.remoteSize }))
}, { }, {
label: 'Local Drive Usage', label: 'Local',
fill: true, fill: true,
backgroundColor: 'rgba(246, 88, 79, 0.1)', backgroundColor: 'rgba(246, 88, 79, 0.1)',
borderColor: '#f6584f', borderColor: '#f6584f',
@ -314,25 +391,102 @@ export default Vue.extend({
}]; }];
}, },
driveFilesChart(total: boolean): any { driveFilesChart(): any {
const data = this.stats.slice().reverse().map(x => ({ const data = this.stats.slice().reverse().map(x => ({
date: new Date(x.date), date: new Date(x.date),
localCount: total ? x.drive.local.totalCount : x.drive.local.diffCount, localInc: x.drive.local.incCount,
remoteCount: total ? x.drive.remote.totalCount : x.drive.remote.diffCount localDec: -x.drive.local.decCount,
remoteInc: x.drive.remote.incCount,
remoteDec: -x.drive.remote.decCount
})); }));
return [{ return [{
datasets: [{ datasets: [{
label: 'Drive Files', label: 'All',
fill: false, fill: false,
borderColor: '#555', borderColor: '#555',
borderWidth: 2, borderWidth: 2,
borderDash: [4, 4], borderDash: [4, 4],
pointBackgroundColor: '#fff', pointBackgroundColor: '#fff',
lineTension: 0, lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteCount + x.localCount })) data: data.map(x => ({ t: x.date, y: x.localInc + x.localDec + x.remoteInc + x.remoteDec }))
}, { }, {
label: 'Remote Drive Files', label: 'Remote +',
fill: true,
backgroundColor: 'rgba(65, 221, 222, 0.1)',
borderColor: '#41ddde',
borderWidth: 2,
pointBackgroundColor: '#fff',
lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteInc }))
}, {
label: 'Remote -',
fill: true,
backgroundColor: 'rgba(65, 221, 222, 0.1)',
borderColor: '#41ddde',
borderWidth: 2,
pointBackgroundColor: '#fff',
lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteDec }))
}, {
label: 'Local +',
fill: true,
backgroundColor: 'rgba(246, 88, 79, 0.1)',
borderColor: '#f6584f',
borderWidth: 2,
pointBackgroundColor: '#fff',
lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.localInc }))
}, {
label: 'Local -',
fill: true,
backgroundColor: 'rgba(246, 88, 79, 0.1)',
borderColor: '#f6584f',
borderWidth: 2,
pointBackgroundColor: '#fff',
lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.localDec }))
}]
}, {
scales: {
yAxes: [{
ticks: {
callback: value => {
return Vue.filter('number')(value);
}
}
}]
},
tooltips: {
callbacks: {
label: (tooltipItem, data) => {
const label = data.datasets[tooltipItem.datasetIndex].label || '';
return `${label}: ${Vue.filter('number')(tooltipItem.yLabel)}`;
}
}
}
}];
},
driveFilesTotalChart(): any {
const data = this.stats.slice().reverse().map(x => ({
date: new Date(x.date),
localCount: x.drive.local.totalCount,
remoteCount: x.drive.remote.totalCount,
}));
return [{
datasets: [{
label: 'Combined',
fill: false,
borderColor: '#555',
borderWidth: 2,
borderDash: [4, 4],
pointBackgroundColor: '#fff',
lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.localCount + x.remoteCount }))
}, {
label: 'Remote',
fill: true, fill: true,
backgroundColor: 'rgba(65, 221, 222, 0.1)', backgroundColor: 'rgba(65, 221, 222, 0.1)',
borderColor: '#41ddde', borderColor: '#41ddde',
@ -341,7 +495,7 @@ export default Vue.extend({
lineTension: 0, lineTension: 0,
data: data.map(x => ({ t: x.date, y: x.remoteCount })) data: data.map(x => ({ t: x.date, y: x.remoteCount }))
}, { }, {
label: 'Local Drive Files', label: 'Local',
fill: true, fill: true,
backgroundColor: 'rgba(246, 88, 79, 0.1)', backgroundColor: 'rgba(246, 88, 79, 0.1)',
borderColor: '#f6584f', borderColor: '#f6584f',

View File

@ -8,8 +8,14 @@ export default Stats;
export interface IStats { export interface IStats {
_id: mongo.ObjectID; _id: mongo.ObjectID;
/**
*
*/
date: Date; date: Date;
/**
*
*/
span: 'day' | 'hour'; span: 'day' | 'hour';
/** /**
@ -18,26 +24,36 @@ export interface IStats {
users: { users: {
local: { local: {
/** /**
* * ()
*/ */
total: number; total: number;
/** /**
* * ()
*/ */
diff: number; inc: number;
/**
* ()
*/
dec: number;
}; };
remote: { remote: {
/** /**
* * ()
*/ */
total: number; total: number;
/** /**
* * ()
*/ */
diff: number; inc: number;
/**
* ()
*/
dec: number;
}; };
}; };
@ -47,28 +63,33 @@ export interface IStats {
notes: { notes: {
local: { local: {
/** /**
* 稿 * 稿 ()
*/ */
total: number; total: number;
/** /**
* 稿 * 稿 ()
*/ */
diff: number; inc: number;
/**
* 稿 ()
*/
dec: number;
diffs: { diffs: {
/** /**
* 稿 * 稿 ()
*/ */
normal: number; normal: number;
/** /**
* 稿 * 稿 ()
*/ */
reply: number; reply: number;
/** /**
* Renoteの投稿数の前日比 * Renoteの投稿数の差分 ()
*/ */
renote: number; renote: number;
}; };
@ -76,28 +97,33 @@ export interface IStats {
remote: { remote: {
/** /**
* 稿 * 稿 ()
*/ */
total: number; total: number;
/** /**
* 稿 * 稿 ()
*/ */
diff: number; inc: number;
/**
* 稿 ()
*/
dec: number;
diffs: { diffs: {
/** /**
* 稿 * 稿 ()
*/ */
normal: number; normal: number;
/** /**
* 稿 * 稿 ()
*/ */
reply: number; reply: number;
/** /**
* Renoteの投稿数の前日比 * Renoteの投稿数の差分 ()
*/ */
renote: number; renote: number;
}; };
@ -110,46 +136,66 @@ export interface IStats {
drive: { drive: {
local: { local: {
/** /**
* * ()
*/ */
totalCount: number; totalCount: number;
/** /**
* * ()
*/ */
totalSize: number; totalSize: number;
/** /**
* * ()
*/ */
diffCount: number; incCount: number;
/** /**
* * 使 ()
*/ */
diffSize: number; incSize: number;
/**
* ()
*/
decCount: number;
/**
* 使 ()
*/
decSize: number;
}; };
remote: { remote: {
/** /**
* * ()
*/ */
totalCount: number; totalCount: number;
/** /**
* * ()
*/ */
totalSize: number; totalSize: number;
/** /**
* * ()
*/ */
diffCount: number; incCount: number;
/** /**
* * 使 ()
*/ */
diffSize: number; incSize: number;
/**
* ()
*/
decCount: number;
/**
* 使 ()
*/
decSize: number;
}; };
}; };
} }

View File

@ -2,6 +2,31 @@ import Stats, { IStats } from '../../../models/stats';
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
function migrateStats(stats: IStats[]) {
stats.forEach(stat => {
const isOldData = stat.users.local.inc == null;
if (!isOldData) return;
stat.users.local.inc = (stat as any).users.local.diff;
stat.users.local.dec = 0;
stat.users.remote.inc = (stat as any).users.remote.diff;
stat.users.remote.dec = 0;
stat.notes.local.inc = (stat as any).notes.local.diff;
stat.notes.local.dec = 0;
stat.notes.remote.inc = (stat as any).notes.remote.diff;
stat.notes.remote.dec = 0;
stat.drive.local.incCount = (stat as any).drive.local.diffCount;
stat.drive.local.decCount = 0;
stat.drive.local.incSize = (stat as any).drive.local.diffSize;
stat.drive.local.decSize = 0;
stat.drive.remote.incCount = (stat as any).drive.remote.diffCount;
stat.drive.remote.decCount = 0;
stat.drive.remote.incSize = (stat as any).drive.remote.diffSize;
stat.drive.remote.decSize = 0;
});
}
export const meta = { export const meta = {
}; };
@ -44,6 +69,10 @@ export default (params: any) => new Promise(async (res, rej) => {
}), }),
]); ]);
// 後方互換性のため
migrateStats(statsPerDay);
migrateStats(statsPerHour);
const format = (src: IStats[], span: 'day' | 'hour') => { const format = (src: IStats[], span: 'day' | 'hour') => {
const chart: Array<Omit<Omit<IStats, '_id'>, 'span'>> = []; const chart: Array<Omit<Omit<IStats, '_id'>, 'span'>> = [];
@ -70,17 +99,20 @@ export default (params: any) => new Promise(async (res, rej) => {
users: { users: {
local: { local: {
total: mostRecent.users.local.total, total: mostRecent.users.local.total,
diff: 0 inc: 0,
dec: 0
}, },
remote: { remote: {
total: mostRecent.users.remote.total, total: mostRecent.users.remote.total,
diff: 0 inc: 0,
dec: 0
} }
}, },
notes: { notes: {
local: { local: {
total: mostRecent.notes.local.total, total: mostRecent.notes.local.total,
diff: 0, inc: 0,
dec: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -89,7 +121,8 @@ export default (params: any) => new Promise(async (res, rej) => {
}, },
remote: { remote: {
total: mostRecent.notes.remote.total, total: mostRecent.notes.remote.total,
diff: 0, inc: 0,
dec: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -101,14 +134,18 @@ export default (params: any) => new Promise(async (res, rej) => {
local: { local: {
totalCount: mostRecent.drive.local.totalCount, totalCount: mostRecent.drive.local.totalCount,
totalSize: mostRecent.drive.local.totalSize, totalSize: mostRecent.drive.local.totalSize,
diffCount: 0, incCount: 0,
diffSize: 0 incSize: 0,
decCount: 0,
decSize: 0
}, },
remote: { remote: {
totalCount: mostRecent.drive.remote.totalCount, totalCount: mostRecent.drive.remote.totalCount,
totalSize: mostRecent.drive.remote.totalSize, totalSize: mostRecent.drive.remote.totalSize,
diffCount: 0, incCount: 0,
diffSize: 0 incSize: 0,
decCount: 0,
decSize: 0
} }
} }
}); });
@ -118,17 +155,20 @@ export default (params: any) => new Promise(async (res, rej) => {
users: { users: {
local: { local: {
total: 0, total: 0,
diff: 0 inc: 0,
dec: 0
}, },
remote: { remote: {
total: 0, total: 0,
diff: 0 inc: 0,
dec: 0
} }
}, },
notes: { notes: {
local: { local: {
total: 0, total: 0,
diff: 0, inc: 0,
dec: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -137,7 +177,8 @@ export default (params: any) => new Promise(async (res, rej) => {
}, },
remote: { remote: {
total: 0, total: 0,
diff: 0, inc: 0,
dec: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -149,14 +190,18 @@ export default (params: any) => new Promise(async (res, rej) => {
local: { local: {
totalCount: 0, totalCount: 0,
totalSize: 0, totalSize: 0,
diffCount: 0, incCount: 0,
diffSize: 0 incSize: 0,
decCount: 0,
decSize: 0
}, },
remote: { remote: {
totalCount: 0, totalCount: 0,
totalSize: 0, totalSize: 0,
diffCount: 0, incCount: 0,
diffSize: 0 incSize: 0,
decCount: 0,
decSize: 0
} }
} }
}); });

View File

@ -48,17 +48,20 @@ async function getCurrentStats(span: 'day' | 'hour'): Promise<IStats> {
users: { users: {
local: { local: {
total: mostRecentStats.users.local.total, total: mostRecentStats.users.local.total,
diff: 0 inc: 0,
dec: 0
}, },
remote: { remote: {
total: mostRecentStats.users.remote.total, total: mostRecentStats.users.remote.total,
diff: 0 inc: 0,
dec: 0
} }
}, },
notes: { notes: {
local: { local: {
total: mostRecentStats.notes.local.total, total: mostRecentStats.notes.local.total,
diff: 0, inc: 0,
dec: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -67,7 +70,8 @@ async function getCurrentStats(span: 'day' | 'hour'): Promise<IStats> {
}, },
remote: { remote: {
total: mostRecentStats.notes.remote.total, total: mostRecentStats.notes.remote.total,
diff: 0, inc: 0,
dec: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -79,14 +83,18 @@ async function getCurrentStats(span: 'day' | 'hour'): Promise<IStats> {
local: { local: {
totalCount: mostRecentStats.drive.local.totalCount, totalCount: mostRecentStats.drive.local.totalCount,
totalSize: mostRecentStats.drive.local.totalSize, totalSize: mostRecentStats.drive.local.totalSize,
diffCount: 0, incCount: 0,
diffSize: 0 incSize: 0,
decCount: 0,
decSize: 0
}, },
remote: { remote: {
totalCount: mostRecentStats.drive.remote.totalCount, totalCount: mostRecentStats.drive.remote.totalCount,
totalSize: mostRecentStats.drive.remote.totalSize, totalSize: mostRecentStats.drive.remote.totalSize,
diffCount: 0, incCount: 0,
diffSize: 0 incSize: 0,
decCount: 0,
decSize: 0
} }
} }
}; };
@ -105,17 +113,20 @@ async function getCurrentStats(span: 'day' | 'hour'): Promise<IStats> {
users: { users: {
local: { local: {
total: 0, total: 0,
diff: 0 inc: 0,
dec: 0
}, },
remote: { remote: {
total: 0, total: 0,
diff: 0 inc: 0,
dec: 0
} }
}, },
notes: { notes: {
local: { local: {
total: 0, total: 0,
diff: 0, inc: 0,
dec: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -124,7 +135,8 @@ async function getCurrentStats(span: 'day' | 'hour'): Promise<IStats> {
}, },
remote: { remote: {
total: 0, total: 0,
diff: 0, inc: 0,
dec: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -136,14 +148,18 @@ async function getCurrentStats(span: 'day' | 'hour'): Promise<IStats> {
local: { local: {
totalCount: 0, totalCount: 0,
totalSize: 0, totalSize: 0,
diffCount: 0, incCount: 0,
diffSize: 0 incSize: 0,
decCount: 0,
decSize: 0
}, },
remote: { remote: {
totalCount: 0, totalCount: 0,
totalSize: 0, totalSize: 0,
diffCount: 0, incCount: 0,
diffSize: 0 incSize: 0,
decCount: 0,
decSize: 0
} }
} }
}; };
@ -174,46 +190,56 @@ function update(inc: any) {
} }
export async function updateUserStats(user: IUser, isAdditional: boolean) { export async function updateUserStats(user: IUser, isAdditional: boolean) {
const amount = isAdditional ? 1 : -1;
const origin = isLocalUser(user) ? 'local' : 'remote'; const origin = isLocalUser(user) ? 'local' : 'remote';
const inc = {} as any; const inc = {} as any;
inc[`users.${origin}.total`] = amount; inc[`users.${origin}.total`] = isAdditional ? 1 : -1;
inc[`users.${origin}.diff`] = amount; if (isAdditional) {
inc[`users.${origin}.inc`] = 1;
} else {
inc[`users.${origin}.dec`] = 1;
}
await update(inc); await update(inc);
} }
export async function updateNoteStats(note: INote, isAdditional: boolean) { export async function updateNoteStats(note: INote, isAdditional: boolean) {
const amount = isAdditional ? 1 : -1;
const origin = isLocalUser(note._user) ? 'local' : 'remote'; const origin = isLocalUser(note._user) ? 'local' : 'remote';
const inc = {} as any; const inc = {} as any;
inc[`notes.${origin}.total`] = amount; inc[`notes.${origin}.total`] = isAdditional ? 1 : -1;
inc[`notes.${origin}.diff`] = amount;
if (isAdditional) {
inc[`notes.${origin}.inc`] = 1;
} else {
inc[`notes.${origin}.dec`] = 1;
}
if (note.replyId != null) { if (note.replyId != null) {
inc[`notes.${origin}.diffs.reply`] = amount; inc[`notes.${origin}.diffs.reply`] = isAdditional ? 1 : -1;
} else if (note.renoteId != null) { } else if (note.renoteId != null) {
inc[`notes.${origin}.diffs.renote`] = amount; inc[`notes.${origin}.diffs.renote`] = isAdditional ? 1 : -1;
} else { } else {
inc[`notes.${origin}.diffs.normal`] = amount; inc[`notes.${origin}.diffs.normal`] = isAdditional ? 1 : -1;
} }
await update(inc); await update(inc);
} }
export async function updateDriveStats(file: IDriveFile, isAdditional: boolean) { export async function updateDriveStats(file: IDriveFile, isAdditional: boolean) {
const amount = isAdditional ? 1 : -1;
const size = isAdditional ? file.length : -file.length;
const origin = isLocalUser(file.metadata._user) ? 'local' : 'remote'; const origin = isLocalUser(file.metadata._user) ? 'local' : 'remote';
const inc = {} as any; const inc = {} as any;
inc[`drive.${origin}.totalCount`] = amount; inc[`drive.${origin}.totalCount`] = isAdditional ? 1 : -1;
inc[`drive.${origin}.diffCount`] = amount; inc[`drive.${origin}.totalSize`] = isAdditional ? file.length : -file.length;
inc[`drive.${origin}.totalSize`] = size; if (isAdditional) {
inc[`drive.${origin}.diffSize`] = size; inc[`drive.${origin}.incCount`] = 1;
inc[`drive.${origin}.incSize`] = file.length;
} else {
inc[`drive.${origin}.decCount`] = 1;
inc[`drive.${origin}.decSize`] = file.length;
}
await update(inc); await update(inc);
} }