mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-10 16:05:32 -04:00
[pl][census] graphs
This commit is contained in:
parent
6024f2a668
commit
d00de414a1
@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
|
<p v-if="header" class="h6 d-inline-block me-3"><strong>{{header}}</strong></p>
|
||||||
<div class="form-check form-check-inline"
|
<div class="form-check form-check-inline"
|
||||||
v-for="(desc, m) in {'': 'Hide chart', 'daily': 'Daily change chart', 'cumulative': 'Cumulative chart'}">
|
v-for="(desc, m) in {'': 'Hide chart', 'daily': 'Daily change chart', 'cumulative': 'Cumulative chart'}">
|
||||||
<label class="form-check-label">
|
<label class="form-check-label">
|
||||||
@ -22,6 +23,7 @@
|
|||||||
name: { required: true },
|
name: { required: true },
|
||||||
data: { required: true },
|
data: { required: true },
|
||||||
init: { 'default': '' },
|
init: { 'default': '' },
|
||||||
|
header: {},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -20,6 +20,11 @@
|
|||||||
<li>{{countResponses.usable}} <T>census.repliesUsable</T></li>
|
<li>{{countResponses.usable}} <T>census.repliesUsable</T></li>
|
||||||
<li><nuxt-link :to="`/${config.census.route}/admin`">{{countResponses.awaiting}} <T>census.repliesAwaiting</T></nuxt-link></li>
|
<li><nuxt-link :to="`/${config.census.route}/admin`">{{countResponses.awaiting}} <T>census.repliesAwaiting</T></nuxt-link></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<hr/>
|
||||||
|
<ChartSet v-for="(editionGraph, edition) in countResponses.graphs"
|
||||||
|
:header="edition" :name="`useful responses (${edition})`" :data="editionGraph"
|
||||||
|
class="mb-3"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
@ -3,8 +3,9 @@ import SQL from 'sql-template-strings';
|
|||||||
import sha1 from 'sha1';
|
import sha1 from 'sha1';
|
||||||
import {ulid} from "ulid";
|
import {ulid} from "ulid";
|
||||||
import Papa from 'papaparse';
|
import Papa from 'papaparse';
|
||||||
import {handleErrorAsync} from "../../src/helpers";
|
import {groupBy, handleErrorAsync, ImmutableArray} from "../../src/helpers";
|
||||||
import {intersection, difference} from "../../src/sets";
|
import {intersection, difference} from "../../src/sets";
|
||||||
|
import {buildChart} from "../../src/stats";
|
||||||
|
|
||||||
const getIp = req => {
|
const getIp = req => {
|
||||||
try {
|
try {
|
||||||
@ -101,6 +102,7 @@ router.get('/census/count', handleErrorAsync(async (req, res) => {
|
|||||||
nonbinary: 0,
|
nonbinary: 0,
|
||||||
usable: 0,
|
usable: 0,
|
||||||
awaiting: 0,
|
awaiting: 0,
|
||||||
|
graphs: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +133,22 @@ router.get('/census/count', handleErrorAsync(async (req, res) => {
|
|||||||
AND edition = ${global.config.census.edition}
|
AND edition = ${global.config.census.edition}
|
||||||
AND troll IS NULL
|
AND troll IS NULL
|
||||||
`)).c,
|
`)).c,
|
||||||
|
graphs: Object.fromEntries(
|
||||||
|
Object.entries(
|
||||||
|
groupBy(
|
||||||
|
await req.db.all(SQL`
|
||||||
|
SELECT edition, id
|
||||||
|
FROM census
|
||||||
|
WHERE locale = ${global.config.locale}
|
||||||
|
AND relevant = 1
|
||||||
|
AND troll = 0
|
||||||
|
`),
|
||||||
|
r => r.edition
|
||||||
|
)
|
||||||
|
).map(([edition, rows]) => {
|
||||||
|
return [edition, buildChart(rows, false)];
|
||||||
|
})
|
||||||
|
),
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ const deepGet = (obj, path) => {
|
|||||||
|
|
||||||
const formatDate = d => `${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')}`;
|
const formatDate = d => `${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')}`;
|
||||||
|
|
||||||
module.exports.buildChart = (rows) => {
|
module.exports.buildChart = (rows, cumulative = true) => {
|
||||||
const dates = rows.map(row => new Date(decodeTime(row.id)));
|
const dates = rows.map(row => new Date(decodeTime(row.id)));
|
||||||
|
|
||||||
const chart = {};
|
const chart = {};
|
||||||
@ -71,6 +71,10 @@ module.exports.buildChart = (rows) => {
|
|||||||
chart[formatDate(date)]++;
|
chart[formatDate(date)]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cumulative) {
|
||||||
|
return chart;
|
||||||
|
}
|
||||||
|
|
||||||
const cumChart = {};
|
const cumChart = {};
|
||||||
let cum = 0;
|
let cum = 0;
|
||||||
for (let [date, count] of Object.entries(chart)) {
|
for (let [date, count] of Object.entries(chart)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user