fixed CSV cache
authorAndrew Tridgell <tridge@samba.org>
Sun, 10 Oct 2010 02:35:02 +0000 (13:35 +1100)
committerAndrew Tridgell <tridge@samba.org>
Sun, 10 Oct 2010 02:35:02 +0000 (13:35 +1100)
live/graphs.js

index 400e0b0591b4eeccd2cdf495ab631e20c587231e..21aee3ed4f78338b6d6f5884de2dced5de21e49d 100644 (file)
@@ -46,20 +46,30 @@ function parse_date(s) {
 /* keep a cache of loaded CSV files */
 CSV_Cache = new Array();
 
+
 /*
-  load a CSV file, returing column names and data
+  load a CSV file, returing column names and data via a callback
  */
 function load_CSV(d, filename, callback) {
 
   /* maybe its in the global cache? */
   if (CSV_Cache[filename] !== undefined) {
+    if (CSV_Cache[filename].pending) {
+      /* it might be pending */
+      var q = CSV_Cache[filename].queue.length;
+      CSV_Cache[filename].queue[q] = {filename:filename, d:d, callback:callback};
+      return;
+    }
     d.filename = CSV_Cache[filename].filename;
     d.labels   = CSV_Cache[filename].labels;
     d.data     = CSV_Cache[filename].data;
+    writeDebug("cache hit: " + filename);
     callback(d);
     return;
   }
 
+  CSV_Cache[filename] = { pending: true, queue: new Array()};
+
   /*
     async callback when the CSV is loaded
    */
@@ -85,7 +95,17 @@ function load_CSV(d, filename, callback) {
     }
     
     /* save into the global cache */
-    CSV_Cache[caller.filename] = { filename: caller.filename, labels:labels, data:data };
+    CSV_Cache[caller.filename].filename = filename;
+    CSV_Cache[caller.filename].labels   = labels;
+    CSV_Cache[caller.filename].data     = data;
+    for (var q=0; q<CSV_Cache[caller.filename].queue.length; q++) {
+      CSV_Cache[caller.filename].queue[q].d.data = data;
+      CSV_Cache[caller.filename].queue[q].d.labels = labels;
+      CSV_Cache[caller.filename].queue[q].callback(CSV_Cache[caller.filename].queue[q].d);
+    }
+    CSV_Cache[caller.filename].pending = false;
+    CSV_Cache[caller.filename].queue   = null;
+
     caller.ret.filename = caller.filename;
     caller.ret.labels   = labels;
     caller.ret.data     = data;
@@ -475,6 +495,15 @@ function show_graphs() {
                  "E-Total",
                  { includeZero: false });
 
+  heading(3, "Fan voltage for each inverter (V)");
+
+  graph_csv_files("Fan Voltage", 
+                 todays_csv_files(),
+                 "U-Fan",
+                 { includeZero: true, 
+                   avoidMinZero: true,
+                   valueRange: [0, 12] });
+
 }
 
 function set_date() {