From 8fc1e07136d5ee203cbd1a1bc2ec00dfeb0e8cf0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 23 Aug 2018 15:40:24 +0900 Subject: 1時間単位での集計を追加 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/endpoints/admin/chart.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/server/api/endpoints/admin/chart.ts') diff --git a/src/server/api/endpoints/admin/chart.ts b/src/server/api/endpoints/admin/chart.ts index a0566b11f5..c351c7167d 100644 --- a/src/server/api/endpoints/admin/chart.ts +++ b/src/server/api/endpoints/admin/chart.ts @@ -14,6 +14,7 @@ export default (params: any) => new Promise(async (res, rej) => { const d = now.getDate(); const stats = await Stats.find({ + span: 'day', date: { $gt: new Date(y - 1, m, d) } @@ -44,6 +45,7 @@ export default (params: any) => new Promise(async (res, rej) => { } else { chart.unshift({ date: day, + span: 'day', users: { local: { total: 0, -- cgit v1.2.3-freya From 71a5662195b4b6a8d4d2c2fc357752b9da350b6f Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 23 Aug 2018 16:36:23 +0900 Subject: 一時間ごとのグラフも見れるように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/pages/admin/admin.drive-chart.chart.vue | 57 +++++-- .../views/pages/admin/admin.notes-chart.chart.vue | 101 +++++++----- .../views/pages/admin/admin.users-chart.chart.vue | 57 +++++-- src/server/api/endpoints/admin/chart.ts | 182 ++++++++++++--------- 4 files changed, 250 insertions(+), 147 deletions(-) (limited to 'src/server/api/endpoints/admin/chart.ts') diff --git a/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue b/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue index 3c537d8d6d..97f05571c3 100644 --- a/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue +++ b/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue @@ -1,11 +1,14 @@ + + diff --git a/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue b/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue deleted file mode 100644 index 97f05571c3..0000000000 --- a/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue +++ /dev/null @@ -1,74 +0,0 @@ - - - - - diff --git a/src/client/app/desktop/views/pages/admin/admin.drive-chart.vue b/src/client/app/desktop/views/pages/admin/admin.drive-chart.vue deleted file mode 100644 index 4f94fd2372..0000000000 --- a/src/client/app/desktop/views/pages/admin/admin.drive-chart.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - - - diff --git a/src/client/app/desktop/views/pages/admin/admin.notes-chart.chart.vue b/src/client/app/desktop/views/pages/admin/admin.notes-chart.chart.vue deleted file mode 100644 index fabb3f1bd1..0000000000 --- a/src/client/app/desktop/views/pages/admin/admin.notes-chart.chart.vue +++ /dev/null @@ -1,99 +0,0 @@ - - - - - diff --git a/src/client/app/desktop/views/pages/admin/admin.notes-chart.vue b/src/client/app/desktop/views/pages/admin/admin.notes-chart.vue deleted file mode 100644 index e4d396d9c6..0000000000 --- a/src/client/app/desktop/views/pages/admin/admin.notes-chart.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - - - diff --git a/src/client/app/desktop/views/pages/admin/admin.users-chart.chart.vue b/src/client/app/desktop/views/pages/admin/admin.users-chart.chart.vue deleted file mode 100644 index 45ecc13929..0000000000 --- a/src/client/app/desktop/views/pages/admin/admin.users-chart.chart.vue +++ /dev/null @@ -1,74 +0,0 @@ - - - - - diff --git a/src/client/app/desktop/views/pages/admin/admin.users-chart.vue b/src/client/app/desktop/views/pages/admin/admin.users-chart.vue deleted file mode 100644 index e620012702..0000000000 --- a/src/client/app/desktop/views/pages/admin/admin.users-chart.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - - - diff --git a/src/client/app/desktop/views/pages/admin/admin.vue b/src/client/app/desktop/views/pages/admin/admin.vue index cbb1890cc3..066c1a4f4f 100644 --- a/src/client/app/desktop/views/pages/admin/admin.vue +++ b/src/client/app/desktop/views/pages/admin/admin.vue @@ -11,9 +11,7 @@
- - - +
@@ -34,9 +32,7 @@ import XSuspendUser from "./admin.suspend-user.vue"; import XUnsuspendUser from "./admin.unsuspend-user.vue"; import XVerifyUser from "./admin.verify-user.vue"; import XUnverifyUser from "./admin.unverify-user.vue"; -import XUsersChart from "./admin.users-chart.vue"; -import XNotesChart from "./admin.notes-chart.vue"; -import XDriveChart from "./admin.drive-chart.vue"; +import XChart from "./admin.chart.vue"; export default Vue.extend({ components: { @@ -45,9 +41,7 @@ export default Vue.extend({ XUnsuspendUser, XVerifyUser, XUnverifyUser, - XUsersChart, - XNotesChart, - XDriveChart + XChart }, data() { return { diff --git a/src/server/api/endpoints/admin/chart.ts b/src/server/api/endpoints/admin/chart.ts index 1897879d65..1b88af00bd 100644 --- a/src/server/api/endpoints/admin/chart.ts +++ b/src/server/api/endpoints/admin/chart.ts @@ -8,7 +8,7 @@ export const meta = { }; export default (params: any) => new Promise(async (res, rej) => { - const daysRange = 365; + const daysRange = 90; const hoursRange = 24; const now = new Date(); @@ -123,7 +123,6 @@ export default (params: any) => new Promise(async (res, rej) => { } chart.forEach(x => { - delete x.date; delete (x as any).span; }); -- cgit v1.2.3-freya From b21287262e85e3e09e19217ba4168b83e4fdf4a7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 24 Aug 2018 07:23:04 +0900 Subject: チャート取得APIを誰でも利用できるようにするなど MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/desktop/views/pages/admin/admin.chart.vue | 11 +- src/client/app/desktop/views/pages/admin/admin.vue | 7 +- src/server/api/endpoints/admin/chart.ts | 136 --------------------- src/server/api/endpoints/chart.ts | 134 ++++++++++++++++++++ 4 files changed, 141 insertions(+), 147 deletions(-) delete mode 100644 src/server/api/endpoints/admin/chart.ts create mode 100644 src/server/api/endpoints/chart.ts (limited to 'src/server/api/endpoints/admin/chart.ts') diff --git a/src/client/app/desktop/views/pages/admin/admin.chart.vue b/src/client/app/desktop/views/pages/admin/admin.chart.vue index f40f89b2e0..b02f6c31b7 100644 --- a/src/client/app/desktop/views/pages/admin/admin.chart.vue +++ b/src/client/app/desktop/views/pages/admin/admin.chart.vue @@ -44,13 +44,9 @@ export default Vue.extend({ components: { XChart }, - props: { - chart: { - required: true - } - }, data() { return { + chart: null, chartType: 'local-notes', span: 'hour' }; @@ -85,6 +81,11 @@ export default Vue.extend({ ); } }, + created() { + (this as any).api('chart').then(chart => { + this.chart = chart; + }); + }, methods: { notesChart(local: boolean): any { const data = this.stats.slice().reverse().map(x => ({ diff --git a/src/client/app/desktop/views/pages/admin/admin.vue b/src/client/app/desktop/views/pages/admin/admin.vue index 066c1a4f4f..0bb5ed0a0f 100644 --- a/src/client/app/desktop/views/pages/admin/admin.vue +++ b/src/client/app/desktop/views/pages/admin/admin.vue @@ -11,7 +11,7 @@
- +
@@ -49,11 +49,6 @@ export default Vue.extend({ chart: null }; }, - created() { - (this as any).api('admin/chart').then(chart => { - this.chart = chart; - }); - }, methods: { nav(page: string) { this.page = page; diff --git a/src/server/api/endpoints/admin/chart.ts b/src/server/api/endpoints/admin/chart.ts deleted file mode 100644 index 1b88af00bd..0000000000 --- a/src/server/api/endpoints/admin/chart.ts +++ /dev/null @@ -1,136 +0,0 @@ -import Stats, { IStats } from '../../../../models/stats'; - -type Omit = Pick>; - -export const meta = { - requireCredential: true, - requireAdmin: true -}; - -export default (params: any) => new Promise(async (res, rej) => { - const daysRange = 90; - const hoursRange = 24; - - const now = new Date(); - const y = now.getFullYear(); - const m = now.getMonth(); - const d = now.getDate(); - const h = now.getHours(); - - const [statsPerDay, statsPerHour] = await Promise.all([ - Stats.find({ - span: 'day', - date: { - $gt: new Date(y, m, d - daysRange) - } - }, { - sort: { - date: -1 - }, - fields: { - _id: 0 - } - }), - Stats.find({ - span: 'hour', - date: { - $gt: new Date(y, m, d, h - hoursRange) - } - }, { - sort: { - date: -1 - }, - fields: { - _id: 0 - } - }), - ]); - - const format = (src: IStats[], span: 'day' | 'hour') => { - const chart: Array, 'span'>> = []; - - const range = - span == 'day' ? daysRange : - span == 'hour' ? hoursRange : - null; - - for (let i = (range - 1); i >= 0; i--) { - const current = - span == 'day' ? new Date(y, m, d - i) : - span == 'hour' ? new Date(y, m, d, h - i) : - null; - - const stat = src.find(s => s.date.getTime() == current.getTime()); - - if (stat) { - chart.unshift(stat); - } else { // 隙間埋め - const mostRecent = src.find(s => s.date.getTime() < current.getTime()); - if (mostRecent) { - chart.unshift(Object.assign({}, mostRecent, { - date: current - })); - } else { - chart.unshift({ - date: current, - users: { - local: { - total: 0, - diff: 0 - }, - remote: { - total: 0, - diff: 0 - } - }, - notes: { - local: { - total: 0, - diff: 0, - diffs: { - normal: 0, - reply: 0, - renote: 0 - } - }, - remote: { - total: 0, - diff: 0, - diffs: { - normal: 0, - reply: 0, - renote: 0 - } - } - }, - drive: { - local: { - totalCount: 0, - totalSize: 0, - diffCount: 0, - diffSize: 0 - }, - remote: { - totalCount: 0, - totalSize: 0, - diffCount: 0, - diffSize: 0 - } - } - }); - } - } - } - - chart.forEach(x => { - delete (x as any).span; - }); - - return chart; - }; - - res({ - perDay: format(statsPerDay, 'day'), - perHour: format(statsPerHour, 'hour') - }); -}); diff --git a/src/server/api/endpoints/chart.ts b/src/server/api/endpoints/chart.ts new file mode 100644 index 0000000000..a58f0b163e --- /dev/null +++ b/src/server/api/endpoints/chart.ts @@ -0,0 +1,134 @@ +import Stats, { IStats } from '../../../models/stats'; + +type Omit = Pick>; + +export const meta = { +}; + +export default (params: any) => new Promise(async (res, rej) => { + const daysRange = 90; + const hoursRange = 24; + + const now = new Date(); + const y = now.getFullYear(); + const m = now.getMonth(); + const d = now.getDate(); + const h = now.getHours(); + + const [statsPerDay, statsPerHour] = await Promise.all([ + Stats.find({ + span: 'day', + date: { + $gt: new Date(y, m, d - daysRange) + } + }, { + sort: { + date: -1 + }, + fields: { + _id: 0 + } + }), + Stats.find({ + span: 'hour', + date: { + $gt: new Date(y, m, d, h - hoursRange) + } + }, { + sort: { + date: -1 + }, + fields: { + _id: 0 + } + }), + ]); + + const format = (src: IStats[], span: 'day' | 'hour') => { + const chart: Array, 'span'>> = []; + + const range = + span == 'day' ? daysRange : + span == 'hour' ? hoursRange : + null; + + for (let i = (range - 1); i >= 0; i--) { + const current = + span == 'day' ? new Date(y, m, d - i) : + span == 'hour' ? new Date(y, m, d, h - i) : + null; + + const stat = src.find(s => s.date.getTime() == current.getTime()); + + if (stat) { + chart.unshift(stat); + } else { // 隙間埋め + const mostRecent = src.find(s => s.date.getTime() < current.getTime()); + if (mostRecent) { + chart.unshift(Object.assign({}, mostRecent, { + date: current + })); + } else { + chart.unshift({ + date: current, + users: { + local: { + total: 0, + diff: 0 + }, + remote: { + total: 0, + diff: 0 + } + }, + notes: { + local: { + total: 0, + diff: 0, + diffs: { + normal: 0, + reply: 0, + renote: 0 + } + }, + remote: { + total: 0, + diff: 0, + diffs: { + normal: 0, + reply: 0, + renote: 0 + } + } + }, + drive: { + local: { + totalCount: 0, + totalSize: 0, + diffCount: 0, + diffSize: 0 + }, + remote: { + totalCount: 0, + totalSize: 0, + diffCount: 0, + diffSize: 0 + } + } + }); + } + } + } + + chart.forEach(x => { + delete (x as any).span; + }); + + return chart; + }; + + res({ + perDay: format(statsPerDay, 'day'), + perHour: format(statsPerHour, 'hour') + }); +}); -- cgit v1.2.3-freya