Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function processForNetworkStats(nodesDetails) {
- // Filter the nodesDetails array to get only joiningNodes, joinedNodes and activeNodes
- const joiningNodesCount = nodesDetails.filter(node => node.status === "/joining").length;
- const joinedNodesCount = nodesDetails.filter(node => node.status === "/joined").length;
- const activeNodesData = nodesDetails.filter(node => node.status === "/active" || node.status === "/heartbeat");
- // If there are no active nodes, return
- if (activeNodesData.length <= 0) {
- return;
- }
- // Initialize variables for computing and storing data for the network and charts table
- let lastCycleTxsProcessed = 0;
- let lastCycleTxsRejected = 0;
- let lastCycleTxsExpired = 0;
- let modeDesiredNodes = 0;
- let totalQlen = 0;
- let totalQtime = 0;
- let networkLoadTotal = 0;
- let intLoadTotal = 0;
- let extLoadTotal = 0;
- let cycleDurationAcquired = activeNodesData[0].data.duration;
- let reportInterval = activeNodesData[0].data.reportInterval;
- // Get the response for this cycle or closet from the network table
- const response_thisCycleOrCloset = await get_NetworkByCycleOrCloset(activeNodesData[0].data.cycleCounter);
- // Initialize variables for storing last known values
- let lastTotalTxProcessed = 0;
- let lastTotalTxRejected = 0;
- let lastTotalTxExpired = 0;
- let lastAvgTps = 0;
- let lastMaxTps = 0;
- let lastRejTps = 0;
- // If rowCount > 0, assign values from response to respective variables
- if (response_thisCycleOrCloset.rowCount > 0) {
- const { txsProcessed, txsRejected, txsExpired, avgTps, maxTps, rejTps } = response_thisCycleOrCloset.rows[0];
- lastTotalTxProcessed = txsProcessed;
- lastTotalTxRejected = txsRejected;
- lastTotalTxExpired = txsExpired;
- lastAvgTps = avgTps;
- lastMaxTps = maxTps;
- lastRejTps = rejTps;
- }
- // Iterate over the activeNodesData array and perform certain operations for each element
- for (const node of activeNodesData) {
- if (node.data.duration !== 0) {
- lastCycleTxsProcessed += node.data.txProcessed;
- lastCycleTxsRejected += node.data.txRejected;
- lastCycleTxsExpired += node.data.txExpired;
- modeDesiredNodes = Math.max(modeDesiredNodes, node.data.mode);
- totalQlen += node.data.qlen;
- totalQtime += node.data.qtime;
- networkLoadTotal += node.data.netLoad;
- intLoadTotal += node.data.intLoad;
- extLoadTotal += node.data.extLoad;
- }
- }
- // Do further processing with the data as required
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement