mirror of
https://github.com/Foltik/Shimapan
synced 2025-01-06 00:08:25 -05:00
Finish dashboard historical view
This commit is contained in:
parent
2783c10259
commit
7f4565faf5
@ -3,7 +3,6 @@ const mongoose = require('mongoose');
|
|||||||
const ViewSchema = mongoose.Schema({
|
const ViewSchema = mongoose.Schema({
|
||||||
uid: {
|
uid: {
|
||||||
type: String,
|
type: String,
|
||||||
unique: true,
|
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -8,20 +8,27 @@ angular.module('DashCtrl', ['chart.js', 'StatSvc']).controller('DashController',
|
|||||||
let labels = Array.from({length: 7}, (date, i) =>
|
let labels = Array.from({length: 7}, (date, i) =>
|
||||||
(new Date(currentDate - oneDay * (6 - i))).toISOString().substr(5, 5));
|
(new Date(currentDate - oneDay * (6 - i))).toISOString().substr(5, 5));
|
||||||
|
|
||||||
|
const toHumanReadable = bytes => {
|
||||||
|
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||||
|
let index = 0;
|
||||||
|
for (; bytes >= 1024 && index < units.length - 1; index++, bytes /= 1024) {}
|
||||||
|
return bytes.toFixed(3) + ' ' + units[index];
|
||||||
|
};
|
||||||
|
|
||||||
StatService.getWeek((err, stats) => {
|
StatService.getWeek((err, stats) => {
|
||||||
$scope.uploadData = [Array.from({length: 7}, (val, i) => stats[labels[i]] ? stats[labels[i]].uploads : 0)];
|
$scope.uploadData = [Array.from({length: 7}, (val, i) => stats[labels[i]] && stats[labels[i]].uploads ? stats[labels[i]].uploads : 0)];
|
||||||
$scope.viewData = [Array.from({length: 7}, (val, i) => stats[labels[i]] ? stats[labels[i]].views : 0)];
|
$scope.viewData = [Array.from({length: 7}, (val, i) => stats[labels[i]] && stats[labels[i]].views ? stats[labels[i]].views : 0)];
|
||||||
|
|
||||||
$scope.stats = stats;
|
$scope.stats = stats;
|
||||||
|
|
||||||
$scope.statUploads = Object.keys(stats).reduce((acc, key) => acc + stats[key].uploads);
|
$scope.statUploads = Object.keys(stats).reduce((acc, key) => acc + (stats[key].uploads ? stats[key].uploads : 0), 0);
|
||||||
$scope.statUploadSize = Object.keys(stats).reduce((acc, key) => acc + stats[key].size);
|
$scope.statUploadSize = toHumanReadable(Object.keys(stats).reduce((acc, key) => acc + (stats[key].size ? stats[key].size : 0), 0));
|
||||||
$scope.statViews = Object.keys(stats).reduce((acc, key) => acc + stats[key].views);
|
$scope.statViews = Object.keys(stats).reduce((acc, key) => acc + (stats[key].views ? stats[key].views : 0), 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
StatService.getAll((err, stats) => {
|
StatService.getAll((err, stats) => {
|
||||||
$scope.statTotalUploads = stats.count;
|
$scope.statTotalUploads = stats.count;
|
||||||
$scope.statTotalUploadSize = stats.size;
|
$scope.statTotalUploadSize = toHumanReadable(stats.size);
|
||||||
$scope.statTotalViews = stats.views;
|
$scope.statTotalViews = stats.views;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,14 +28,13 @@ function mergeAggregateStats(obj1, obj2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mergeAggregations(res1, res2) {
|
function mergeAggregations(res1, res2) {
|
||||||
const arr = res1;
|
const arr = res1.concat(res2);
|
||||||
arr.concat(res2);
|
|
||||||
|
|
||||||
let res = {};
|
let res = {};
|
||||||
|
|
||||||
for (let obj of arr) {
|
for (let obj of arr) {
|
||||||
if (res[obj._id])
|
if (res[obj._id])
|
||||||
mergeAggregateStats(res[obj._id], obj);
|
res[obj._id] = mergeAggregateStats(res[obj._id], obj);
|
||||||
else
|
else
|
||||||
res[obj._id] = filterAggregateStats(obj);
|
res[obj._id] = filterAggregateStats(obj);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user