Skip to content

Commit

Permalink
just track call totals
Browse files Browse the repository at this point in the history
  • Loading branch information
robotastic committed Aug 26, 2024
1 parent 31644bc commit d46c8b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 0 additions & 1 deletion backend/controllers/systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ async function load_systems(systemClients) {
exports.get_systems = async function (req, res) {
if ((systemList.length == 0) || (systemListTime < (Date.now() - 60 * 1000 * 15))) {
await load_systems(req.systemClients);
console.log("System List Loaded - total: " + systemList.length);
systemListTime = Date.now();
}

Expand Down
22 changes: 12 additions & 10 deletions backend/sys_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ async function updateActiveSystems() {
for await (let item of System.find()) {
// go through all the systems
// 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.callAvg = callTotals[item.shortName][0] / timePeriod;
item.callAvg = callTotals[item.shortName] / timePeriod;
item.lastActive = new Date();
} else {
item.active = false;
item.callAvg = 0;
}
callTotals[item.shortName] = 0;
/*
let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000);
if ((item.lastActive != null) && (item.lastActive > fromDate)) {
Expand All @@ -35,7 +36,7 @@ async function updateActiveSystems() {

exports.initStats = async function () {
// get the System Stats collection

/*
for await (const item of SystemStat.find()) {
const obj = item.toObject();
// Talkgroup Stats
Expand All @@ -57,12 +58,12 @@ exports.initStats = async function () {
if (obj.callTotals !== undefined) {
callTotals[obj.shortName] = obj.callTotals;
}
};
};*/
}

// keeps track of the number of calls that get uploaded with an audio file
exports.addError = function (call) {

/*
// if there is no Array associated with the system.
if (uploadErrors[call.shortName] === undefined) {
uploadErrors[call.shortName] = new Array();
Expand All @@ -72,12 +73,13 @@ exports.addError = function (call) {
}
// 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
exports.addCall = function (call) {

callTotals[call.shortName]++;
/*
// if you haven't started keeping track of stats for the System yet
if (talkgroupStats[call.shortName] === undefined) {
talkgroupStats[call.shortName] = {};
Expand Down Expand Up @@ -123,13 +125,13 @@ exports.addCall = function (call) {
// 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].errors += call.errorCount;
sysErrors[call.freq].spikes += call.spikeCount;
sysErrors[call.freq].spikes += call.spikeCount;*/
}


// This gets called when a Time Period is up
exports.shiftStats = async function () {

/*
console.log("Started Shifting Stats at: " + new Date());
// for all the systems in Error Stats
for (var shortName in uploadErrors) {
Expand Down Expand Up @@ -225,7 +227,7 @@ exports.shiftStats = async function () {
if (bulkOps.length > 0) {
await SystemStat.bulkWrite(bulkOps);
}
console.log("Finished writing to DB at: " + new Date());
console.log("Finished writing to DB at: " + new Date());*/
updateActiveSystems();
console.log("Finished Updating Active Systems at: " + new Date());
}
Expand Down

0 comments on commit d46c8b0

Please sign in to comment.