just track call totals

This commit is contained in:
Luke Berndt
2024-08-25 22:10:10 -04:00
parent 31644bcc40
commit d46c8b0baa
2 changed files with 12 additions and 11 deletions

View File

@@ -146,7 +146,6 @@ async function load_systems(systemClients) {
exports.get_systems = async function (req, res) { exports.get_systems = async function (req, res) {
if ((systemList.length == 0) || (systemListTime < (Date.now() - 60 * 1000 * 15))) { if ((systemList.length == 0) || (systemListTime < (Date.now() - 60 * 1000 * 15))) {
await load_systems(req.systemClients); await load_systems(req.systemClients);
console.log("System List Loaded - total: " + systemList.length);
systemListTime = Date.now(); systemListTime = Date.now();
} }

View File

@@ -14,14 +14,15 @@ async function updateActiveSystems() {
for await (let item of System.find()) { for await (let item of System.find()) {
// go through all the systems // go through all the systems
// if you have received some calls during that last period, make the system active // if you have received some calls during that last period, make the system active
if ((callTotals[item.shortName] != undefined) && (callTotals[item.shortName][0] > 0)) { if ((callTotals[item.shortName] != undefined) && (callTotals[item.shortName] > 0)) {
item.active = true; item.active = true;
item.callAvg = callTotals[item.shortName][0] / timePeriod; item.callAvg = callTotals[item.shortName] / timePeriod;
item.lastActive = new Date(); item.lastActive = new Date();
} else { } else {
item.active = false; item.active = false;
item.callAvg = 0; item.callAvg = 0;
} }
callTotals[item.shortName] = 0;
/* /*
let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000); let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000);
if ((item.lastActive != null) && (item.lastActive > fromDate)) { if ((item.lastActive != null) && (item.lastActive > fromDate)) {
@@ -35,7 +36,7 @@ async function updateActiveSystems() {
exports.initStats = async function () { exports.initStats = async function () {
// get the System Stats collection // get the System Stats collection
/*
for await (const item of SystemStat.find()) { for await (const item of SystemStat.find()) {
const obj = item.toObject(); const obj = item.toObject();
// Talkgroup Stats // Talkgroup Stats
@@ -57,12 +58,12 @@ exports.initStats = async function () {
if (obj.callTotals !== undefined) { if (obj.callTotals !== undefined) {
callTotals[obj.shortName] = obj.callTotals; callTotals[obj.shortName] = obj.callTotals;
} }
}; };*/
} }
// keeps track of the number of calls that get uploaded with an audio file // keeps track of the number of calls that get uploaded with an audio file
exports.addError = function (call) { exports.addError = function (call) {
/*
// if there is no Array associated with the system. // if there is no Array associated with the system.
if (uploadErrors[call.shortName] === undefined) { if (uploadErrors[call.shortName] === undefined) {
uploadErrors[call.shortName] = new Array(); uploadErrors[call.shortName] = new Array();
@@ -72,12 +73,13 @@ exports.addError = function (call) {
} }
// Add an error to the count for the current period. // Add an error to the count for the current period.
uploadErrors[call.shortName][0]++; uploadErrors[call.shortName][0]++;*/
} }
// Keeps track of the number of calls for each talkgroup for a system // Keeps track of the number of calls for each talkgroup for a system
exports.addCall = function (call) { exports.addCall = function (call) {
callTotals[call.shortName]++;
/*
// if you haven't started keeping track of stats for the System yet // if you haven't started keeping track of stats for the System yet
if (talkgroupStats[call.shortName] === undefined) { if (talkgroupStats[call.shortName] === undefined) {
talkgroupStats[call.shortName] = {}; talkgroupStats[call.shortName] = {};
@@ -123,13 +125,13 @@ exports.addCall = function (call) {
// add to the call count and total length, Call Average is calc by dividing the two... // add to the call count and total length, Call Average is calc by dividing the two...
sysErrors[call.freq].totalLen += call.len; sysErrors[call.freq].totalLen += call.len;
sysErrors[call.freq].errors += call.errorCount; sysErrors[call.freq].errors += call.errorCount;
sysErrors[call.freq].spikes += call.spikeCount; sysErrors[call.freq].spikes += call.spikeCount;*/
} }
// This gets called when a Time Period is up // This gets called when a Time Period is up
exports.shiftStats = async function () { exports.shiftStats = async function () {
/*
console.log("Started Shifting Stats at: " + new Date()); console.log("Started Shifting Stats at: " + new Date());
// for all the systems in Error Stats // for all the systems in Error Stats
for (var shortName in uploadErrors) { for (var shortName in uploadErrors) {
@@ -225,7 +227,7 @@ exports.shiftStats = async function () {
if (bulkOps.length > 0) { if (bulkOps.length > 0) {
await SystemStat.bulkWrite(bulkOps); await SystemStat.bulkWrite(bulkOps);
} }
console.log("Finished writing to DB at: " + new Date()); console.log("Finished writing to DB at: " + new Date());*/
updateActiveSystems(); updateActiveSystems();
console.log("Finished Updating Active Systems at: " + new Date()); console.log("Finished Updating Active Systems at: " + new Date());
} }