From e9b1a0b4728d9e74ae3c6dccbf037e07f36f5fd4 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 3 Oct 2010 20:57:16 +0100 Subject: More complete tests for getData and associated simplification of the getData code. --- jarmon/jarmon.js | 56 ++++++++++++++++++++------------------------------- jarmon/jarmon.test.js | 52 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 68 insertions(+), 40 deletions(-) diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index 3f63b3e..6ac410c 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -165,16 +165,11 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, dsId, cfNam 'endtime: ', endTimeJs].join('')); } - // The startTime, endTime and lastupdate time are not necessarily on a step - // boundaries. Here we divide, round and then multiply by the step size to - // find the nearest "Primary Data Point" (PDP) time. - console.log('RRD: ', this.rrd); - var minStep = this.rrd.getMinStep(); - var startTime = Math.round(startTimeJs/1000/minStep) * minStep; + var startTime = startTimeJs/1000; var lastUpdated = this.rrd.getLastUpdate(); - var lastPdpTime = Math.round(lastUpdated / minStep) * minStep; - var endTime = lastPdpTime; + // default endTime to the last updated time (quantized to rrd step boundry) + var endTime = lastUpdated - lastUpdated%this.rrd.getMinStep(); if(endTimeJs) { endTime = endTimeJs/1000; } @@ -202,8 +197,7 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, dsId, cfNam step = rra.getStep(); rraRowCount = rra.getNrRows(); - - lastRowTime = Math.round(lastUpdated/step)*step; + lastRowTime = lastUpdated-lastUpdated%step; firstRowTime = lastRowTime - rraRowCount * step; // We assume that the RRAs are listed in ascending order of time range, @@ -219,36 +213,30 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, dsId, cfNam throw TypeError('Unrecognised consolidation function: ' + cfName); } - var startRowTime = Math.floor(startTime/step)*step + step; - var endRowTime = Math.floor(endTime/step)*step + step; - var flotData = []; - var timestamp = startRowTime; + var dsIndex = ds.getIdx(); - // Fill in any blank values at the start of the query, before we reach the - // first data in the chosen RRA - while(timestamp<=endRowTime && timestamp