40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
const express = require('express');
|
|
const mongoose = require('mongoose');
|
|
|
|
async function testSummary() {
|
|
await mongoose.connect('mongodb://backone_inspect:backone_inspect@mongodb.prod.proit.id:27017/backone_inspect_0');
|
|
|
|
const { Summary } = require('./models/Schemas');
|
|
|
|
const siteIds = await Summary.distinct('site_uuid', { agent_uuid: null });
|
|
|
|
const now = new Date();
|
|
const delta = 24 * 3600000;
|
|
const timeFilter = { $gte: new Date(now.getTime() - delta) };
|
|
|
|
console.log('Querying with timeFilter:', timeFilter);
|
|
|
|
const siteSummaries = await Summary.find({
|
|
site_uuid: { $in: siteIds },
|
|
agent_uuid: null,
|
|
timestamp: timeFilter
|
|
}).lean();
|
|
|
|
let bandwidthDown = 0;
|
|
let bandwidthUp = 0;
|
|
|
|
const validSite = siteSummaries.filter(x => x.bandwidth_down > 0 || x.bandwidth_up > 0);
|
|
if (validSite.length > 0) {
|
|
validSite.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp));
|
|
bandwidthDown = validSite[0].bandwidth_down || 0;
|
|
bandwidthUp = validSite[0].bandwidth_up || 0;
|
|
}
|
|
|
|
console.log('Test validSite length:', validSite.length);
|
|
console.log('Resulting Bandwidth:', bandwidthDown, bandwidthUp);
|
|
|
|
mongoose.disconnect();
|
|
}
|
|
|
|
testSummary();
|