Просмотр исходного кода

Finish dashboard historical view

production
Jack Foltz 5 лет назад
Родитель
Сommit
7f4565faf5
Подписано: foltik <jack@foltz.io> Идентификатор GPG ключа: 303F88F996E95541
3 измененных файлов: 15 добавлений и 10 удалений
  1. +0
    -1
      app/models/View.js
  2. +13
    -6
      app/public/panel/controllers/DashCtrl.js
  3. +2
    -3
      app/routes/api/stats.js

+ 0
- 1
app/models/View.js Просмотреть файл

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



+ 13
- 6
app/public/panel/controllers/DashCtrl.js Просмотреть файл

@@ -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;
});



+ 2
- 3
app/routes/api/stats.js Просмотреть файл

@@ -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);
}


Загрузка…
Отмена
Сохранить