lib/ericssonmanager.js
/**
 * Run the Zone by Time query in Elasticsearch.
 * @param {Elasticsearch} esClient The Elasticsearch client.
 * @param {function} callback The function to call on completion.
 */
Run the Zone by Time query in Elasticsearch.
@param {Elasticsearch} esClient The Elasticsearch client.
@param {function} callback The function to call on completion.
Run the Zone by Time query in Elasticsearch . @param { Elasticsearch } esClient The Elasticsearch client . @param { function } callback The function to call on completion .
function queryZoneByTime(esClient, callback) {
  let startTimestamp = new Date(Date.now() - 300000).getTime();
  let endTimestamp = new Date().getTime();
  let body = {
      "size": 0,
      "aggs": {
        "date": {
          "date_histogram": {
            "field": "timestamp",
            "interval": "30s"
          },
          "aggs": {
            "receivers": {
              "significant_terms": {
                "field": "receiverId.keyword",
                "size": 5
              }
            }
          }
        }     
      },
      "query": {
        "bool": {
          "must": [
            {
              "range": {
                "timestamp" : {
                  "gte" : startTimestamp,
                  "lt" :  endTimestamp
                }
              }
            },
            {
              "range": {
                "rssi" : {
                  "gte" : RSSI_MIN_THRESHOLD,
                  "lt" :  RSSI_MAX_THRESHOLD
                }
              }
            }
          ]
        }
      }
  };
  let query = { index: 'raddec', body: body };
  esClient.search(query, function(err, result) {
    let data = { x: [], y: [], z: [] };
    if(err) {
     console.log('Ericsson queryZoneByTime error:', err);
    }
    else {
      let buckets = result.body.aggregations.date.buckets;
      let numberOfTimestamps = 0;
      buckets.forEach(function(item) {
        let timestamp = new Date(item.key).getTime();
        data.x.push(timestamp);
        let receiverBuckets = item.receivers.buckets;
        receiverBuckets.forEach(function(receiver) {
          let receiverId = receiver.key;
          let count = receiver.doc_count;
          let isNewReceiverId = (data.y.indexOf(receiverId) < 0);
          if(isNewReceiverId) {
            data.y.push(receiverId);
            let counts = Array(numberOfTimestamps).fill(0);
            data.z.push(counts);
          }
          let receiverIndex = data.y.indexOf(receiverId);
          data.z[receiverIndex].push(count);
        });
        numberOfTimestamps++;
        data.z.forEach(function(receiver) {
          if(receiver.length < numberOfTimestamps) {
            receiver.push(0);
          }
        });
      });
    }
    return callback(data);
  });
}
function queryZoneByTime ( esClient , callback ) { let startTimestamp = new Date ( Date . now ( ) - 300000 ) . getTime ( ) ; let endTimestamp = new Date ( ) . getTime ( ) ; let body = { "size" : 0 , "aggs" : { "date" : { "date_histogram" : { "field" : "timestamp" , "interval" : "30s" } , "aggs" : { "receivers" : { "significant_terms" : { "field" : "receiverId.keyword" , "size" : 5 } } } } } , "query" : { "bool" : { "must" : [ { "range" : { "timestamp" : { "gte" : startTimestamp , "lt" : endTimestamp } } } , { "range" : { "rssi" : { "gte" : RSSI_MIN_THRESHOLD , "lt" : RSSI_MAX_THRESHOLD } } } ] } } } ; let query = { index : 'raddec' , body : body } ; esClient . search ( query , function ( err , result ) { let data = { x : [ ] , y : [ ] , z : [ ] } ; if ( err ) { console . log ( 'Ericsson queryZoneByTime error:' , err ) ; } else { let buckets = result . body . aggregations . date . buckets ; let numberOfTimestamps = 0 ; buckets . forEach ( function ( item ) { let timestamp = new Date ( item . key ) . getTime ( ) ; data . x . push ( timestamp ) ; let receiverBuckets = item . receivers . buckets ; receiverBuckets . forEach ( function ( receiver ) { let receiverId = receiver . key ; let count = receiver . doc_count ; let isNewReceiverId = ( data . y . indexOf ( receiverId ) < 0 ) ; if ( isNewReceiverId ) { data . y . push ( receiverId ) ; let counts = Array ( numberOfTimestamps ) . fill ( 0 ) ; data . z . push ( counts ) ; } let receiverIndex = data . y . indexOf ( receiverId ) ; data . z [ receiverIndex ] . push ( count ) ; } ) ; numberOfTimestamps ++ ; data . z . forEach ( function ( receiver ) { if ( receiver . length < numberOfTimestamps ) { receiver . push ( 0 ) ; } } ) ; } ) ; } return callback ( data ) ; } ) ; }
Run the Zone by Time query in Elasticsearch.
Run the Zone by Time query in Elasticsearch .
// Time range is from five minutes ago to now // Iterate through each timestamp // Iterate through each receiver with counts // Iterate through all to fill in missing counts