From 11c5d257f2394a8a9dcfc7fe15c9e57684dfd11e Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 23 Oct 2018 09:59:43 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=8F=E3=83=83=E3=82=B7=E3=83=A5=E3=82=BF?= =?UTF-8?q?=E3=82=B0=E3=83=81=E3=83=A3=E3=83=BC=E3=83=88=E3=81=A7=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=82=AB=E3=83=AB=E3=81=A8=E3=83=AA=E3=83=A2=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=82=92=E5=88=86=E9=9B=A2=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chart/hashtag.ts | 39 ++++++++++++++----- .../views/pages/deck/deck.hashtag-column.vue | 19 ++++----- src/services/register-hashtag.ts | 2 +- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/chart/hashtag.ts b/src/chart/hashtag.ts index 976fd0c84..5b03d8ba3 100644 --- a/src/chart/hashtag.ts +++ b/src/chart/hashtag.ts @@ -1,36 +1,55 @@ import autobind from 'autobind-decorator'; -import * as mongo from 'mongodb'; -import Chart, { Partial } from './'; +import Chart, { Obj } from './'; +import { IUser, isLocalUser } from '../models/user'; +import db from '../db/mongodb'; /** * ハッシュタグに関するチャート */ type HashtagLog = { - /** - * 投稿された数 - */ - count: number; + local: { + /** + * 投稿された数 + */ + count: number; + }; + + remote: HashtagLog['local']; }; class HashtagChart extends Chart { constructor() { super('hashtag', true); + + // 後方互換性のため + db.get('chart.hashtag').findOne().then(doc => { + if (doc != null && doc.data.local == null) { + db.get('chart.hashtag').drop(); + } + }); } @autobind protected async getTemplate(init: boolean, latest?: HashtagLog): Promise { return { - count: 0 + local: { + count: 0 + }, + remote: { + count: 0 + } }; } @autobind - public async update(hashtag: string, userId: mongo.ObjectId) { - const inc: Partial = { + public async update(hashtag: string, user: IUser) { + const update: Obj = { count: 1 }; - await this.incIfUnique(inc, 'users', userId.toHexString(), hashtag); + await this.incIfUnique({ + [isLocalUser(user) ? 'local' : 'remote']: update + }, 'users', user._id.toHexString(), hashtag); } } diff --git a/src/client/app/desktop/views/pages/deck/deck.hashtag-column.vue b/src/client/app/desktop/views/pages/deck/deck.hashtag-column.vue index 600614616..2b5bf14b2 100644 --- a/src/client/app/desktop/views/pages/deck/deck.hashtag-column.vue +++ b/src/client/app/desktop/views/pages/deck/deck.hashtag-column.vue @@ -16,7 +16,6 @@ import Vue from 'vue'; import XColumn from './deck.column.vue'; import XHashtagTl from './deck.hashtag-tl.vue'; import * as ApexCharts from 'apexcharts'; -import * as tinycolor from 'tinycolor2'; export default Vue.extend({ components: { @@ -45,7 +44,8 @@ export default Vue.extend({ span: 'hour', limit: 24 }).then(stats => { - const data = []; + const local = []; + const remote = []; const now = new Date(); const y = now.getFullYear(); @@ -55,11 +55,10 @@ export default Vue.extend({ for (let i = 0; i < 24; i++) { const x = new Date(y, m, d, h - i); - data.push([x, stats.count[i]]); + local.push([x, stats.local.count[i]]); + remote.push([x, stats.remote.count[i]]); } - const color = tinycolor(getComputedStyle(document.documentElement).getPropertyValue('--primary')); - const chart = new ApexCharts(this.$refs.chart, { chart: { type: 'area', @@ -82,13 +81,15 @@ export default Vue.extend({ width: 2 }, series: [{ - name: 'count', - data: data + name: 'Local', + data: local + }, { + name: 'Remote', + data: remote }], xaxis: { type: 'datetime', - }, - colors: [`#${color.clone().toHex()}`] + } }); chart.render(); diff --git a/src/services/register-hashtag.ts b/src/services/register-hashtag.ts index 106df377b..57ba2080f 100644 --- a/src/services/register-hashtag.ts +++ b/src/services/register-hashtag.ts @@ -27,5 +27,5 @@ export default async function(user: IUser, tag: string) { }); } - hashtagChart.update(tag, user._id); + hashtagChart.update(tag, user); }