aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/js
diff options
context:
space:
mode:
authorPeter Wu2014-08-02 11:52:22 +0200
committerPim van den Berg2014-11-14 00:09:54 +0100
commit9b361b4969d84cb09a1095354bfb516e275edfe2 (patch)
tree3cb40bfe48f53483f662e89e74623f7a77eac711 /js
parentjsrrdgraph: Improve performance for graphs in the future (diff)
downloadapt-panopticon_cgp-9b361b4969d84cb09a1095354bfb516e275edfe2.zip
apt-panopticon_cgp-9b361b4969d84cb09a1095354bfb516e275edfe2.tar.gz
apt-panopticon_cgp-9b361b4969d84cb09a1095354bfb516e275edfe2.tar.bz2
apt-panopticon_cgp-9b361b4969d84cb09a1095354bfb516e275edfe2.tar.xz
jsrrdgraph: Simplify matching logic
Instead of using a flag for determining whether a value is set or not, set values that will never match and test for the validity of the results instead of checking the flags.
Diffstat (limited to 'js')
-rw-r--r--js/RrdDataFile.js18
1 files changed, 8 insertions, 10 deletions
diff --git a/js/RrdDataFile.js b/js/RrdDataFile.js
index 4f96234..46f7811 100644
--- a/js/RrdDataFile.js
+++ b/js/RrdDataFile.js
@@ -40,11 +40,10 @@ RrdDataFile.prototype = {
40 build: function(gdp, ft_step, rrd) 40 build: function(gdp, ft_step, rrd)
41 { 41 {
42 var cal_start, cal_end; 42 var cal_start, cal_end;
43 var best_full_rra = 0, best_part_rra = 0, chosen_rra = 0; 43 var best_full_rra = -1, best_part_rra = -1, chosen_rra = 0;
44 var best_full_step_diff = 0, best_part_step_diff = 0, tmp_step_diff = 0, tmp_match = 0, best_match = 0; 44 var best_full_step_diff = Infinity, best_part_step_diff = Infinity;
45 var tmp_step_diff = 0, tmp_match = 0, best_match = -1;
45 var full_match; 46 var full_match;
46 var first_full = 1;
47 var first_part = 1;
48 var data_ptr; 47 var data_ptr;
49 var rows; 48 var rows;
50 var rra; 49 var rra;
@@ -80,16 +79,15 @@ RrdDataFile.prototype = {
80 79
81 tmp_step_diff = Math.abs(ft_step - range_secs); 80 tmp_step_diff = Math.abs(ft_step - range_secs);
82 if (cal_start <= gdp.start) { 81 if (cal_start <= gdp.start) {
83 if (first_full || (tmp_step_diff < best_full_step_diff)) { 82 if (tmp_step_diff < best_full_step_diff) {
84 first_full = 0;
85 best_full_step_diff = tmp_step_diff; 83 best_full_step_diff = tmp_step_diff;
86 best_full_rra = i; 84 best_full_rra = i;
87 } 85 }
88 } else { 86 } else {
89 tmp_match = full_match; 87 tmp_match = full_match;
90 if (cal_start > gdp.start) tmp_match -= (cal_start - gdp.start); 88 if (cal_start > gdp.start) tmp_match -= (cal_start - gdp.start);
91 if (first_part || (best_match < tmp_match) || (best_match === tmp_match && tmp_step_diff < best_part_step_diff)) { 89 if (best_match < tmp_match || (best_match === tmp_match &&
92 first_part = 0; 90 tmp_step_diff < best_part_step_diff)) {
93 best_match = tmp_match; 91 best_match = tmp_match;
94 best_part_step_diff = tmp_step_diff; 92 best_part_step_diff = tmp_step_diff;
95 best_part_rra = i; 93 best_part_rra = i;
@@ -98,8 +96,8 @@ RrdDataFile.prototype = {
98 } 96 }
99 } 97 }
100 98
101 if (first_full === 0) chosen_rra = best_full_rra; 99 if (best_full_rra >= 0) chosen_rra = best_full_rra;
102 else if (first_part === 0) chosen_rra = best_part_rra; 100 else if (best_part_rra >= 0) chosen_rra = best_part_rra;
103 else throw "the RRD does not contain an RRA matching the chosen CF"; 101 else throw "the RRD does not contain an RRA matching the chosen CF";
104 102
105 var rra_info = rrd.getRRAInfo(chosen_rra); 103 var rra_info = rrd.getRRAInfo(chosen_rra);