Skip to content

Commit

Permalink
Merge pull request #168 from openmhz/system-test
Browse files Browse the repository at this point in the history
System test
  • Loading branch information
robotastic authored Aug 20, 2024
2 parents bc88f4e + 32af2ca commit d45907a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
31 changes: 19 additions & 12 deletions backend/controllers/systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const mailjet = new Mailjet({
apiSecret: process.env['MAILJET_SECRET']
});

var systemList = [];
var systemListTime = Date.now();

exports.contact_system = async function(req, res) {
var system = await System.findOne({
shortName: req.params.shortName.toLowerCase()
Expand Down Expand Up @@ -97,25 +100,19 @@ exports.contact_system = async function(req, res) {

}

exports.get_systems = async function (req, res) {
async function load_systems(systemClients) {
let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000);
//const results = await System.find({lastActive: {$gte: fromDate}}).populate('userId', "screenName").catch( err => {
const results = await System.find({lastActive: {$gte: fromDate}}).populate('userId', "screenName").catch( err => {
//const results = await System.find({active: true}).populate('userId', "screenName").catch( err => {
const results = await System.find({active: true}).catch( err => {
//const results = await System.find({active: true}).catch( err => { // super simple query
console.error("Error - get_systems: " + err.message);
res.status(500);
res.json({
success: false,
message: err
});
return;
});
var systemList = [];
systemList = [];
for (var result in results) {

var clientCount = 0;
if (req.systemClients.hasOwnProperty(results[result].shortName)) {
clientCount = req.systemClients[results[result].shortName];
if (systemClients.hasOwnProperty(results[result].shortName)) {
clientCount = systemClients[results[result].shortName];
}
var system = {
name: results[result].name,
Expand All @@ -142,6 +139,16 @@ exports.get_systems = async function (req, res) {
system.screenName = null;
systemList.push(system);
}

}


exports.get_systems = async function (req, res) {
if ((systemList.length == 0) || (systemListTime < (Date.now() - 60 * 1000 * 15))) {
await load_systems(req.systemClients);
systemListTime = Date.now();
}

res.contentType('json');
res.send(JSON.stringify({
success: true,
Expand Down
6 changes: 3 additions & 3 deletions backend/controllers/uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ const { NodeHttpHandler } = require('@smithy/node-http-handler');
const https = require('https');

const agent = new https.Agent({
maxSockets: 150
maxSockets: 250
});


var s3_endpoint = process.env['S3_ENDPOINT'] != null ? process.env['S3_ENDPOINT'] : 'https://s3.us-west-1.wasabisys.com';
var s3_region = process.env['S3_REGION'] != null ? process.env['S3_REGION'] : 'us-west-1';
var s3_bucket = process.env['S3_BUCKET'] != null ? process.env['S3_BUCKET'] : 'openmhz-west';
var s3_profile = process.env['S3_PROFILE'] != null ? process.env['S3_PROFILE'] : 'wasabi-account';

var s3_public_url = process.env['S3_PUBLIC_URL'] != null ? process.env['S3_PUBLIC_URL'] : s3_endpoint + "/" + s3_bucket;

const client = new S3Client({
requestHandler: new NodeHttpHandler({
Expand Down Expand Up @@ -165,7 +165,7 @@ exports.upload = async function (req, res, next) {

var endpoint = s3_endpoint;
var bucket = s3_bucket;
var url = s3_endpoint + "/" + s3_bucket + "/" + object_key;
var url = s3_public_url + "/" + object_key;

var call = new Call({
shortName: shortName,
Expand Down
2 changes: 1 addition & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ io.sockets.on('connection', function (client) {

if (typeof clients[client.id] === "undefined") {
console.error("How can it be undefined here!!");
console.error(clients[client.id]);
console.error(client.id);
return;
}
if (group) {
Expand Down
20 changes: 12 additions & 8 deletions backend/sys_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ async function updateActiveSystems() {
// 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)) {
//item.active = true;
item.active = true;
item.callAvg = callTotals[item.shortName][0] / timePeriod;
item.lastActive = new Date();
} else {
//item.active = false;
item.active = false;
item.callAvg = 0;
}
/*
let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000);
if ((item.lastActive != null) && (item.lastActive > fromDate)) {
item.active = true;
} else {
item.active = false;
}
}*/
await item.save();
};
}
Expand Down Expand Up @@ -76,6 +77,7 @@ 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) {
talkgroupStats[call.shortName] = {};
Expand Down Expand Up @@ -121,14 +123,14 @@ 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) {
if (uploadErrors.hasOwnProperty(shortName)) {
Expand All @@ -147,8 +149,8 @@ exports.shiftStats = async function () {
uploadErrors[shortName][0] = 0;
}
}


console.log("Finished Shifting Upload Errors at: " + new Date());
/*
// for each system in decodeErrorsFreq
for (let shortName in decodeErrorsFreq) {
Expand Down Expand Up @@ -195,7 +197,7 @@ exports.shiftStats = async function () {
}
}

console.log("Finished Shifting Decode Errors at: " + new Date());
// for each system in talkgroupStats
for (let shortName in talkgroupStats) {
Expand Down Expand Up @@ -265,7 +267,9 @@ exports.shiftStats = async function () {
await SystemStat.updateOne(query, update, options);
}
}
console.log("Finished Shifting Talkgroup Stats at: " + new Date());*/
updateActiveSystems();
console.log("Finished Updating Active Systems at: " + new Date());
}
exports.callTotals = function (shortName) {
return callTotals[shortName];
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ services:
- S3_BUCKET
- S3_PROFILE
- S3_REGION
- S3_PUBLIC_URL
- OTEL_SERVICE_NAME
- HONEYCOMB_API_KEY
volumes:
Expand Down

0 comments on commit d45907a

Please sign in to comment.