This commit is contained in:
syuilo 2018-10-21 10:24:56 +09:00
parent fed04ef5ae
commit 17263fb459
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
2 changed files with 124 additions and 87 deletions

View file

@ -56,6 +56,8 @@ const rgba = (color: string): string => {
return color.replace('rgb', 'rgba').replace(')', ', 0.1)'); return color.replace('rgb', 'rgba').replace(')', ', 0.1)');
}; };
const limit = 35;
export default Vue.extend({ export default Vue.extend({
components: { components: {
XChart XChart
@ -63,6 +65,7 @@ export default Vue.extend({
data() { data() {
return { return {
now: null,
chart: null, chart: null,
chartType: 'notes', chartType: 'notes',
span: 'hour' span: 'hour'
@ -90,30 +93,17 @@ export default Vue.extend({
}, },
stats(): any[] { stats(): any[] {
const now = new Date();
const y = now.getFullYear();
const m = now.getMonth();
const d = now.getDate();
const h = now.getHours();
const stats = const stats =
this.span == 'day' ? this.chart.perDay : this.span == 'day' ? this.chart.perDay :
this.span == 'hour' ? this.chart.perHour : this.span == 'hour' ? this.chart.perHour :
null; null;
stats.forEach((s, i) => {
s.date =
this.span == 'day' ? new Date(y, m, d - i) :
this.span == 'hour' ? new Date(y, m, d, h - i) :
null;
});
return stats; return stats;
} }
}, },
async created() { async created() {
const limit = 35; this.now = new Date();
const [perHour, perDay] = await Promise.all([Promise.all([ const [perHour, perDay] = await Promise.all([Promise.all([
(this as any).api('charts/users', { limit: limit, span: 'hour' }), (this as any).api('charts/users', { limit: limit, span: 'hour' }),
@ -128,37 +118,49 @@ export default Vue.extend({
])]); ])]);
const chart = { const chart = {
perHour: [], perHour: {
perDay: [] users: perHour[0],
}; notes: perHour[1],
drive: perHour[2],
for (let i = 0; i < limit; i++) { network: perHour[3]
chart.perHour.push({ },
users: perHour[0][i], perDay: {
notes: perHour[1][i], users: perDay[0],
drive: perHour[2][i], notes: perDay[1],
network: perHour[3][i] drive: perDay[2],
}); network: perDay[3]
chart.perDay.push({
users: perDay[0][i],
notes: perDay[1][i],
drive: perDay[2][i],
network: perDay[3][i]
});
} }
};
this.chart = chart; this.chart = chart;
}, },
methods: { methods: {
getDate(i: number) {
const y = this.now.getFullYear();
const m = this.now.getMonth();
const d = this.now.getDate();
const h = this.now.getHours();
return (
this.span == 'day' ? new Date(y, m, d - i) :
this.span == 'hour' ? new Date(y, m, d, h - i) :
null
);
},
notesChart(type: string): any { notesChart(type: string): any {
const data = this.stats.slice().reverse().map(x => ({ const data = [];
date: new Date(x.date),
normal: type == 'local' ? x.notes.local.diffs.normal : type == 'remote' ? x.notes.remote.diffs.normal : x.notes.local.diffs.normal + x.notes.remote.diffs.normal, for (let i = 0; i < limit; i++) {
reply: type == 'local' ? x.notes.local.diffs.reply : type == 'remote' ? x.notes.remote.diffs.reply : x.notes.local.diffs.reply + x.notes.remote.diffs.reply, data.push({
renote: type == 'local' ? x.notes.local.diffs.renote : type == 'remote' ? x.notes.remote.diffs.renote : x.notes.local.diffs.renote + x.notes.remote.diffs.renote, date: this.getDate(i),
all: type == 'local' ? (x.notes.local.inc + -x.notes.local.dec) : type == 'remote' ? (x.notes.remote.inc + -x.notes.remote.dec) : (x.notes.local.inc + -x.notes.local.dec) + (x.notes.remote.inc + -x.notes.remote.dec) normal: type == 'local' ? this.stats.notes.local.diffs.normal[i] : type == 'remote' ? this.stats.notes.remote.diffs.normal[i] : this.stats.notes.local.diffs.normal[i] + this.stats.notes.remote.diffs.normal[i],
})); reply: type == 'local' ? this.stats.notes.local.diffs.reply[i] : type == 'remote' ? this.stats.notes.remote.diffs.reply[i] : this.stats.notes.local.diffs.reply[i] + this.stats.notes.remote.diffs.reply[i],
renote: type == 'local' ? this.stats.notes.local.diffs.renote[i] : type == 'remote' ? this.stats.notes.remote.diffs.renote[i] : this.stats.notes.local.diffs.renote[i] + this.stats.notes.remote.diffs.renote[i],
all: type == 'local' ? (this.stats.notes.local.inc[i] + -this.stats.notes.local.dec[i]) : type == 'remote' ? (this.stats.notes.remote.inc[i] + -this.stats.notes.remote.dec[i]) : (this.stats.notes.local.inc[i] + -this.stats.notes.local.dec[i]) + (this.stats.notes.remote.inc[i] + -this.stats.notes.remote.dec[i])
});
}
return [{ return [{
datasets: [{ datasets: [{
@ -220,11 +222,15 @@ export default Vue.extend({
}, },
notesTotalChart(): any { notesTotalChart(): any {
const data = this.stats.slice().reverse().map(x => ({ const data = [];
date: new Date(x.date),
localCount: x.notes.local.total, for (let i = 0; i < limit; i++) {
remoteCount: x.notes.remote.total data.push({
})); date: this.getDate(i),
localCount: this.stats.notes.local.total[i],
remoteCount: this.stats.notes.remote.total[i]
});
}
return [{ return [{
datasets: [{ datasets: [{
@ -277,11 +283,15 @@ export default Vue.extend({
}, },
usersChart(total: boolean): any { usersChart(total: boolean): any {
const data = this.stats.slice().reverse().map(x => ({ const data = [];
date: new Date(x.date),
localCount: total ? x.users.local.total : (x.users.local.inc + -x.users.local.dec), for (let i = 0; i < limit; i++) {
remoteCount: total ? x.users.remote.total : (x.users.remote.inc + -x.users.remote.dec) data.push({
})); date: this.getDate(i),
localCount: total ? this.stats.users.local.total[i] : (this.stats.users.local.inc[i] + -this.stats.users.local.dec[i]),
remoteCount: total ? this.stats.users.remote.total[i] : (this.stats.users.remote.inc[i] + -this.stats.users.remote.dec[i])
});
}
return [{ return [{
datasets: [{ datasets: [{
@ -334,13 +344,17 @@ export default Vue.extend({
}, },
driveChart(): any { driveChart(): any {
const data = this.stats.slice().reverse().map(x => ({ const data = [];
date: new Date(x.date),
localInc: x.drive.local.incSize, for (let i = 0; i < limit; i++) {
localDec: -x.drive.local.decSize, data.push({
remoteInc: x.drive.remote.incSize, date: this.getDate(i),
remoteDec: -x.drive.remote.decSize, localInc: this.stats.drive.local.incSize[i],
})); localDec: -this.stats.drive.local.decSize[i],
remoteInc: this.stats.drive.remote.incSize[i],
remoteDec: -this.stats.drive.remote.decSize[i],
});
}
return [{ return [{
datasets: [{ datasets: [{
@ -411,11 +425,15 @@ export default Vue.extend({
}, },
driveTotalChart(): any { driveTotalChart(): any {
const data = this.stats.slice().reverse().map(x => ({ const data = [];
date: new Date(x.date),
localSize: x.drive.local.totalSize, for (let i = 0; i < limit; i++) {
remoteSize: x.drive.remote.totalSize data.push({
})); date: this.getDate(i),
localSize: this.stats.drive.local.totalSize[i],
remoteSize: this.stats.drive.remote.totalSize[i]
});
}
return [{ return [{
datasets: [{ datasets: [{
@ -468,13 +486,17 @@ export default Vue.extend({
}, },
driveFilesChart(): any { driveFilesChart(): any {
const data = this.stats.slice().reverse().map(x => ({ const data = [];
date: new Date(x.date),
localInc: x.drive.local.incCount, for (let i = 0; i < limit; i++) {
localDec: -x.drive.local.decCount, data.push({
remoteInc: x.drive.remote.incCount, date: this.getDate(i),
remoteDec: -x.drive.remote.decCount localInc: this.stats.drive.local.incCount[i],
})); localDec: -this.stats.drive.local.decCount[i],
remoteInc: this.stats.drive.remote.incCount[i],
remoteDec: -this.stats.drive.remote.decCount[i]
});
}
return [{ return [{
datasets: [{ datasets: [{
@ -545,11 +567,15 @@ export default Vue.extend({
}, },
driveFilesTotalChart(): any { driveFilesTotalChart(): any {
const data = this.stats.slice().reverse().map(x => ({ const data = [];
date: new Date(x.date),
localCount: x.drive.local.totalCount, for (let i = 0; i < limit; i++) {
remoteCount: x.drive.remote.totalCount, data.push({
})); date: this.getDate(i),
localCount: this.stats.drive.local.totalCount[i],
remoteCount: this.stats.drive.remote.totalCount[i],
});
}
return [{ return [{
datasets: [{ datasets: [{
@ -602,10 +628,14 @@ export default Vue.extend({
}, },
networkRequestsChart(): any { networkRequestsChart(): any {
const data = this.stats.slice().reverse().map(x => ({ const data = [];
date: new Date(x.date),
incoming: x.network.incomingRequests for (let i = 0; i < limit; i++) {
})); data.push({
date: this.getDate(i),
incoming: this.stats.network.incomingRequests[i]
});
}
return [{ return [{
datasets: [{ datasets: [{
@ -622,10 +652,14 @@ export default Vue.extend({
}, },
networkTimeChart(): any { networkTimeChart(): any {
const data = this.stats.slice().reverse().map(x => ({ const data = [];
date: new Date(x.date),
time: x.network.incomingRequests != 0 ? (x.network.totalTime / x.network.incomingRequests) : 0, for (let i = 0; i < limit; i++) {
})); data.push({
date: this.getDate(i),
time: this.stats.network.incomingRequests[i] != 0 ? (this.stats.network.totalTime[i] / this.stats.network.incomingRequests[i]) : 0,
});
}
return [{ return [{
datasets: [{ datasets: [{
@ -642,11 +676,15 @@ export default Vue.extend({
}, },
networkUsageChart(): any { networkUsageChart(): any {
const data = this.stats.slice().reverse().map(x => ({ const data = [];
date: new Date(x.date),
incoming: x.network.incomingBytes, for (let i = 0; i < limit; i++) {
outgoing: x.network.outgoingBytes data.push({
})); date: this.getDate(i),
incoming: this.stats.network.incomingBytes[i],
outgoing: this.stats.network.outgoingBytes[i]
});
}
return [{ return [{
datasets: [{ datasets: [{
@ -693,8 +731,6 @@ export default Vue.extend({
</script> </script>
<style lang="stylus" scoped> <style lang="stylus" scoped>
.gkgckalzgidaygcxnugepioremxvxvpt .gkgckalzgidaygcxnugepioremxvxvpt
padding 32px padding 32px
background #fff background #fff

View file

@ -228,6 +228,7 @@ abstract class Chart<T> {
*/ */
const dive = (x: Obj, path?: string) => { const dive = (x: Obj, path?: string) => {
Object.entries(x).forEach(([k, v]) => { Object.entries(x).forEach(([k, v]) => {
const p = path ? `${path}.${k}` : k;
if (typeof v == 'object') { if (typeof v == 'object') {
dive(v, p); dive(v, p);
} else { } else {