Advertisement
tk4vr

processForNetworkStats

Mar 2nd, 2023
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function processForNetworkStats(nodesDetails) {
  2.   // Filter the nodesDetails array to get only joiningNodes, joinedNodes and activeNodes
  3.   const joiningNodesCount = nodesDetails.filter(node => node.status === "/joining").length;
  4.   const joinedNodesCount = nodesDetails.filter(node => node.status === "/joined").length;
  5.   const activeNodesData = nodesDetails.filter(node => node.status === "/active" || node.status === "/heartbeat");
  6.  
  7.   // If there are no active nodes, return
  8.   if (activeNodesData.length <= 0) {
  9.     return;
  10.   }
  11.  
  12.   // Initialize variables for computing and storing data for the network and charts table
  13.   let lastCycleTxsProcessed = 0;
  14.   let lastCycleTxsRejected = 0;
  15.   let lastCycleTxsExpired = 0;
  16.   let modeDesiredNodes = 0;
  17.   let totalQlen = 0;
  18.   let totalQtime = 0;
  19.   let networkLoadTotal = 0;
  20.   let intLoadTotal = 0;
  21.   let extLoadTotal = 0;
  22.   let cycleDurationAcquired = activeNodesData[0].data.duration;
  23.   let reportInterval = activeNodesData[0].data.reportInterval;
  24.  
  25.   // Get the response for this cycle or closet from the network table
  26.   const response_thisCycleOrCloset = await get_NetworkByCycleOrCloset(activeNodesData[0].data.cycleCounter);
  27.  
  28.   // Initialize variables for storing last known values
  29.   let lastTotalTxProcessed = 0;
  30.   let lastTotalTxRejected = 0;
  31.   let lastTotalTxExpired = 0;
  32.   let lastAvgTps = 0;
  33.   let lastMaxTps = 0;
  34.   let lastRejTps = 0;
  35.  
  36.   // If rowCount > 0, assign values from response to respective variables
  37.   if (response_thisCycleOrCloset.rowCount > 0) {
  38.     const { txsProcessed, txsRejected, txsExpired, avgTps, maxTps, rejTps } = response_thisCycleOrCloset.rows[0];
  39.     lastTotalTxProcessed = txsProcessed;
  40.     lastTotalTxRejected = txsRejected;
  41.     lastTotalTxExpired = txsExpired;
  42.     lastAvgTps = avgTps;
  43.     lastMaxTps = maxTps;
  44.     lastRejTps = rejTps;
  45.   }
  46.  
  47.   // Iterate over the activeNodesData array and perform certain operations for each element
  48.   for (const node of activeNodesData) {
  49.     if (node.data.duration !== 0) {
  50.       lastCycleTxsProcessed += node.data.txProcessed;
  51.       lastCycleTxsRejected += node.data.txRejected;
  52.       lastCycleTxsExpired += node.data.txExpired;
  53.       modeDesiredNodes = Math.max(modeDesiredNodes, node.data.mode);
  54.       totalQlen += node.data.qlen;
  55.       totalQtime += node.data.qtime;
  56.       networkLoadTotal += node.data.netLoad;
  57.       intLoadTotal += node.data.intLoad;
  58.       extLoadTotal += node.data.extLoad;
  59.     }
  60.   }
  61.  
  62.   // Do further processing with the data as required
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement