fixed it!

This commit is contained in:
Luke Berndt
2023-04-29 17:56:27 -04:00
parent 6fbf2b6e2b
commit 0e0b05acf8
3 changed files with 19 additions and 13 deletions

View File

@@ -13,6 +13,7 @@ exports.get_stats = function(req, res) {
var talkgroupStats = sysStats.talkgroupStats(short_name);
var uploadErrors = sysStats.uploadErrors(short_name);
let decodeErrorsFreq = sysStats.decodeErrorsFreq(short_name);
if (callTotals && talkgroupStats) {
res.contentType('json');
res.send(JSON.stringify({

View File

@@ -1,11 +1,16 @@
var mongoose = require('mongoose');
let decodeErrorSchema = mongoose.Schema({
totalLen: Number,
errors: Number,
spikes: Number,
errorHistory: [Number],
spikeHistory: [Number],
})
let talkgroupStatsSchema = mongoose.Schema({
calls: Number,
totalLen: Number,
callCountHistory: [Number],
callAvgLenHistory: [Number]
})

View File

@@ -34,26 +34,26 @@ 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
if (item.talkgroupStats != undefined) {
talkgroupStats[item.shortName] = obj.talkgroupStats;
if (obj.talkgroupStats !== undefined) {
talkgroupStats[obj.shortName] = Object.fromEntries(obj.talkgroupStats);
}
// Decode Errors
if (item.decodeErrorsFreq != undefined) {
decodeErrorsFreq[item.shortName] = obj.decodeErrorsFreq;
if (obj.decodeErrorsFreq !== undefined) {
decodeErrorsFreq[obj.shortName] = Object.fromEntries(obj.decodeErrorsFreq);
}
// Upload Error Totals
if (item.uploadErrors != undefined) {
uploadErrors[item.shortName] = obj.uploadErrors;
if (obj.uploadErrors !== undefined) {
uploadErrors[obj.shortName] = obj.uploadErrors;
}
if (item.callTotals != undefined) {
callTotals[item.shortName] = obj.callTotals;
if (obj.callTotals !== undefined) {
callTotals[obj.shortName] = obj.callTotals;
}
};
}
@@ -62,7 +62,7 @@ exports.initStats = async function () {
exports.addError = function (call) {
// if there is no Array associated with the system.
if (uploadErrors[call.shortName] == undefined) {
if (uploadErrors[call.shortName] === undefined) {
uploadErrors[call.shortName] = new Array();
for (var j = 0; j < spots; j++) {
uploadErrors[call.shortName][j] = 0;
@@ -76,12 +76,12 @@ exports.addError = function (call) {
// Keeps track of the number of calls for each talkgroup for a system
exports.addCall = function (call) {
// 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] = {};
}
var sysTalkgroupStats = talkgroupStats[call.shortName];
// if you haven't started keeping track of Stats for this TG yet...
if (sysTalkgroupStats[call.talkgroupNum] == undefined) {
if (sysTalkgroupStats[call.talkgroupNum] === undefined) {
sysTalkgroupStats[call.talkgroupNum] = {}
sysTalkgroupStats[call.talkgroupNum].calls = 0;
sysTalkgroupStats[call.talkgroupNum].totalLen = 0;
@@ -105,7 +105,7 @@ exports.addCall = function (call) {
var sysErrors = decodeErrorsFreq[call.shortName];
// if you haven't started keeping track of Stats for this TG yet...
if (sysErrors[call.freq] == undefined) {
if (sysErrors[call.freq] === undefined) {
sysErrors[call.freq] = {}
sysErrors[call.freq].totalLen = 0;
sysErrors[call.freq].errors = 0;