Improve type definitions
This commit is contained in:
@ -9,6 +9,7 @@ import * as mongo from 'mongodb';
|
||||
import db from '../../db/mongodb';
|
||||
import { ICollection } from 'monk';
|
||||
import Logger from '../../misc/logger';
|
||||
import { Schema } from '../../prelude/schema';
|
||||
|
||||
const logger = new Logger('chart');
|
||||
|
||||
@ -346,3 +347,18 @@ export default abstract class Chart<T extends Obj> {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
export function convertLog(logSchema: Schema): Schema {
|
||||
const v: Schema = JSON.parse(JSON.stringify(logSchema)); // copy
|
||||
if (v.type === 'number') {
|
||||
v.type = 'array';
|
||||
v.items = {
|
||||
type: 'number'
|
||||
};
|
||||
} else if (v.type === 'object') {
|
||||
for (const k of Object.keys(v.properties)) {
|
||||
v.properties[k] = convertLog(v.properties[k]);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
@ -2,48 +2,61 @@ import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj } from '.';
|
||||
import Note, { INote } from '../../models/note';
|
||||
import { isLocalUser } from '../../models/user';
|
||||
import { SchemaType } from '../../prelude/schema';
|
||||
|
||||
/**
|
||||
* 投稿に関するチャート
|
||||
*/
|
||||
type NotesLog = {
|
||||
local: {
|
||||
/**
|
||||
* 集計期間時点での、全投稿数
|
||||
*/
|
||||
total: number;
|
||||
const logSchema = {
|
||||
total: {
|
||||
type: 'number' as 'number',
|
||||
description: '集計期間時点での、全投稿数'
|
||||
},
|
||||
|
||||
/**
|
||||
* 増加した投稿数
|
||||
*/
|
||||
inc: number;
|
||||
inc: {
|
||||
type: 'number' as 'number',
|
||||
description: '増加した投稿数'
|
||||
},
|
||||
|
||||
/**
|
||||
* 減少した投稿数
|
||||
*/
|
||||
dec: number;
|
||||
dec: {
|
||||
type: 'number' as 'number',
|
||||
description: '減少した投稿数'
|
||||
},
|
||||
|
||||
diffs: {
|
||||
/**
|
||||
* 通常の投稿数の差分
|
||||
*/
|
||||
normal: number;
|
||||
diffs: {
|
||||
type: 'object' as 'object',
|
||||
properties: {
|
||||
normal: {
|
||||
type: 'number' as 'number',
|
||||
description: '通常の投稿数の差分'
|
||||
},
|
||||
|
||||
/**
|
||||
* リプライの投稿数の差分
|
||||
*/
|
||||
reply: number;
|
||||
reply: {
|
||||
type: 'number' as 'number',
|
||||
description: 'リプライの投稿数の差分'
|
||||
},
|
||||
|
||||
/**
|
||||
* Renoteの投稿数の差分
|
||||
*/
|
||||
renote: number;
|
||||
};
|
||||
};
|
||||
|
||||
remote: NotesLog['local'];
|
||||
renote: {
|
||||
type: 'number' as 'number',
|
||||
description: 'Renoteの投稿数の差分'
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const notesLogSchema = {
|
||||
type: 'object' as 'object',
|
||||
properties: {
|
||||
local: {
|
||||
type: 'object' as 'object',
|
||||
properties: logSchema
|
||||
},
|
||||
remote: {
|
||||
type: 'object' as 'object',
|
||||
properties: logSchema
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
type NotesLog = SchemaType<typeof notesLogSchema>;
|
||||
|
||||
class NotesChart extends Chart<NotesLog> {
|
||||
constructor() {
|
||||
super('notes');
|
||||
|
Reference in New Issue
Block a user