summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-08-12 18:02:28 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-08-12 18:02:28 +0900
commit0e786fbb667450b385c46a1981b6f9b630dc0b65 (patch)
treeace36302a4ab3bc421a1bc0e89efbcd2dea16391 /src
parentv2364 (diff)
downloadsharkey-0e786fbb667450b385c46a1981b6f9b630dc0b65.tar.gz
sharkey-0e786fbb667450b385c46a1981b6f9b630dc0b65.tar.bz2
sharkey-0e786fbb667450b385c46a1981b6f9b630dc0b65.zip
その日ごとの「アカウントが作成された回数」もグラフにするようにした
Diffstat (limited to 'src')
-rw-r--r--src/api/endpoints/aggregation/users.ts41
-rw-r--r--src/web/app/stats/tags/index.tag13
2 files changed, 30 insertions, 24 deletions
diff --git a/src/api/endpoints/aggregation/users.ts b/src/api/endpoints/aggregation/users.ts
index 9be4ca12a1..9eb2d035ec 100644
--- a/src/api/endpoints/aggregation/users.ts
+++ b/src/api/endpoints/aggregation/users.ts
@@ -15,15 +15,8 @@ module.exports = params => new Promise(async (res, rej) => {
const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).$;
if (limitErr) return rej('invalid limit param');
- const startTime = new Date(new Date().setMonth(new Date().getMonth() - 1));
-
const users = await User
- .find({
- $or: [
- { deleted_at: { $exists: false } },
- { deleted_at: { $gt: startTime } }
- ]
- }, {
+ .find({}, {
_id: false,
created_at: true,
deleted_at: true
@@ -34,24 +27,30 @@ module.exports = params => new Promise(async (res, rej) => {
const graph = [];
for (let i = 0; i < limit; i++) {
- let day = new Date(new Date().setDate(new Date().getDate() - i));
- day = new Date(day.setMilliseconds(999));
- day = new Date(day.setSeconds(59));
- day = new Date(day.setMinutes(59));
- day = new Date(day.setHours(23));
+ let dayStart = new Date(new Date().setDate(new Date().getDate() - i));
+ dayStart = new Date(dayStart.setMilliseconds(0));
+ dayStart = new Date(dayStart.setSeconds(0));
+ dayStart = new Date(dayStart.setMinutes(0));
+ dayStart = new Date(dayStart.setHours(0));
+
+ let dayEnd = new Date(new Date().setDate(new Date().getDate() - i));
+ dayEnd = new Date(dayEnd.setMilliseconds(999));
+ dayEnd = new Date(dayEnd.setSeconds(59));
+ dayEnd = new Date(dayEnd.setMinutes(59));
+ dayEnd = new Date(dayEnd.setHours(23));
// day = day.getTime();
- const count = users.filter(f =>
- f.created_at < day && (f.deleted_at == null || f.deleted_at > day)
+ const total = users.filter(u =>
+ u.created_at < dayEnd && (u.deleted_at == null || u.deleted_at > dayEnd)
+ ).length;
+
+ const created = users.filter(u =>
+ u.created_at < dayEnd && u.created_at > dayStart
).length;
graph.push({
- date: {
- year: day.getFullYear(),
- month: day.getMonth() + 1, // In JavaScript, month is zero-based.
- day: day.getDate()
- },
- count: count
+ total: total,
+ created: created
});
}
diff --git a/src/web/app/stats/tags/index.tag b/src/web/app/stats/tags/index.tag
index 0adf58b0bd..134fad3c0c 100644
--- a/src/web/app/stats/tags/index.tag
+++ b/src/web/app/stats/tags/index.tag
@@ -168,7 +168,12 @@
<mk-users-chart>
<svg riot-viewBox="0 0 { viewBoxX } { viewBoxY }" preserveAspectRatio="none">
<polyline
- riot-points={ points }
+ riot-points={ createdPoints }
+ fill="none"
+ stroke-width="1"
+ stroke="#1cde84"/>
+ <polyline
+ riot-points={ totalPoints }
fill="none"
stroke-width="1"
stroke="#555"/>
@@ -187,7 +192,8 @@
this.viewBoxY = 80;
this.data = this.opts.data.reverse();
- const peak = Math.max.apply(null, this.data.map(d => d.count));
+ const totalPeak = Math.max.apply(null, this.data.map(d => d.total));
+ const createdPeak = Math.max.apply(null, this.data.map(d => d.created));
this.on('mount', () => {
this.render();
@@ -195,7 +201,8 @@
this.render = () => {
this.update({
- points: this.data.map((d, i) => `${i},${(1 - (d.count / peak)) * this.viewBoxY}`).join(' ')
+ totalPoints: this.data.map((d, i) => `${i},${(1 - (d.total / totalPeak)) * this.viewBoxY}`).join(' '),
+ createdPoints: this.data.map((d, i) => `${i},${(1 - (d.created / createdPeak)) * this.viewBoxY}`).join(' ')
});
};
</script>