1
0
mirror of https://github.com/Foltik/Shimapan synced 2025-01-03 15:16:52 -05:00

Finish dashboard historical view

This commit is contained in:
Jack Foltz 2018-09-15 22:25:49 -04:00
parent 2783c10259
commit 7f4565faf5
Signed by: foltik
GPG Key ID: 303F88F996E95541
3 changed files with 15 additions and 10 deletions

View File

@ -3,7 +3,6 @@ const mongoose = require('mongoose');
const ViewSchema = mongoose.Schema({
uid: {
type: String,
unique: true,
required: true
},

View File

@ -8,20 +8,27 @@ angular.module('DashCtrl', ['chart.js', 'StatSvc']).controller('DashController',
let labels = Array.from({length: 7}, (date, i) =>
(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) => {
$scope.uploadData = [Array.from({length: 7}, (val, i) => stats[labels[i]] ? stats[labels[i]].uploads : 0)];
$scope.viewData = [Array.from({length: 7}, (val, i) => stats[labels[i]] ? stats[labels[i]].views : 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 ? stats[labels[i]].views : 0)];
$scope.stats = stats;
$scope.statUploads = Object.keys(stats).reduce((acc, key) => acc + stats[key].uploads);
$scope.statUploadSize = Object.keys(stats).reduce((acc, key) => acc + stats[key].size);
$scope.statViews = Object.keys(stats).reduce((acc, key) => acc + stats[key].views);
$scope.statUploads = Object.keys(stats).reduce((acc, key) => acc + (stats[key].uploads ? stats[key].uploads : 0), 0);
$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 ? stats[key].views : 0), 0);
});
StatService.getAll((err, stats) => {
$scope.statTotalUploads = stats.count;
$scope.statTotalUploadSize = stats.size;
$scope.statTotalUploadSize = toHumanReadable(stats.size);
$scope.statTotalViews = stats.views;
});

View File

@ -28,14 +28,13 @@ function mergeAggregateStats(obj1, obj2) {
}
function mergeAggregations(res1, res2) {
const arr = res1;
arr.concat(res2);
const arr = res1.concat(res2);
let res = {};
for (let obj of arr) {
if (res[obj._id])
mergeAggregateStats(res[obj._id], obj);
res[obj._id] = mergeAggregateStats(res[obj._id], obj);
else
res[obj._id] = filterAggregateStats(obj);
}