new rb_rrd_xport function for ruby bindings. -- Pavel Pachkovskij pavel.pachkovskij...
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Fri, 5 Feb 2010 18:28:41 +0000 (18:28 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Fri, 5 Feb 2010 18:28:41 +0000 (18:28 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@2016 a5681a0c-68f1-0310-ab6d-d61299d08faa

bindings/ruby/CHANGES
bindings/ruby/main.c
bindings/ruby/test.rb

index c84ff29..9e01ed5 100644 (file)
@@ -1,3 +1,7 @@
+2010-02-05 Pavel Pachkovskij (Azati corp.)
+ add rrd_xport
+ update test.rb with rrd_xport example
+
 2006-07-25 Loïs Lherbier
  add y_min and y_max parameters to rrd_graph
  update test.rb to send only strings to RRD.fetch
 2006-07-25 Loïs Lherbier
  add y_min and y_max parameters to rrd_graph
  update test.rb to send only strings to RRD.fetch
index 355625f..6fe6a35 100644 (file)
@@ -319,6 +319,53 @@ VALUE rb_rrd_last(
         return rb_funcall(rb_cTime, rb_intern("at"), 1, UINT2NUM(last));
 }
 
         return rb_funcall(rb_cTime, rb_intern("at"), 1, UINT2NUM(last));
 }
 
+VALUE rb_rrd_xport(
+    VALUE self,
+    VALUE args)
+{
+    string_arr a;
+    unsigned long i, j, k, step, col_cnt;
+    int xxsize;
+    rrd_value_t *data;
+    char **legend_v;
+    VALUE legend, result, rdata;
+    time_t start, end;
+
+    a = string_arr_new(args);
+    rrd_xport(a.len, a.strings, &xxsize, &start, &end, &step, &col_cnt, &legend_v, &data);
+    string_arr_delete(a);
+
+    RRD_CHECK_ERROR;
+            
+    legend = rb_ary_new();
+    for (i = 0; i < col_cnt; i++) {
+        rb_ary_push(legend, rb_str_new2(legend_v[i]));
+        free(legend_v[i]);
+    }
+    free(legend_v);
+
+    k = 0;
+    rdata = rb_ary_new();
+    for (i = start; i <= end; i += step) {
+        VALUE line = rb_ary_new2(col_cnt);
+        for (j = 0; j < col_cnt; j++) {
+            rb_ary_store(line, j, rb_float_new(data[k]));
+            k++;
+        }
+        rb_ary_push(rdata, line);
+    }
+    free(data);
+
+    result = rb_ary_new2(6);
+    rb_ary_store(result, 0, INT2FIX(start));
+    rb_ary_store(result, 1, INT2FIX(end));
+    rb_ary_store(result, 2, INT2FIX(step));
+    rb_ary_store(result, 3, INT2FIX(col_cnt));
+    rb_ary_store(result, 4, legend);
+    rb_ary_store(result, 5, rdata);
+    return result;
+}
+
 void Init_RRD(
     )
 {
 void Init_RRD(
     )
 {
@@ -338,4 +385,5 @@ void Init_RRD(
     rb_define_module_function(mRRD, "info", rb_rrd_info, -2);
     rb_define_module_function(mRRD, "updatev", rb_rrd_updatev, -2);
     rb_define_module_function(mRRD, "graphv", rb_rrd_graphv, -2);
     rb_define_module_function(mRRD, "info", rb_rrd_info, -2);
     rb_define_module_function(mRRD, "updatev", rb_rrd_updatev, -2);
     rb_define_module_function(mRRD, "graphv", rb_rrd_graphv, -2);
+    rb_define_module_function(mRRD, "xport", rb_rrd_xport, -2);
 }
 }
index 3d0b95f..2ca502d 100755 (executable)
@@ -56,5 +56,17 @@ if end_time != RRD.last("#{rrd}").to_i
 end
 puts
 
 end
 puts
 
+# xport method test
+puts "xporting data from #{rrd}"
+(fstart,fend,step,col,legend,data)=RRD.xport(
+       "--start", start_time.to_s, 
+       "--end", (start_time + 300 * 300).to_s, 
+       "--step", 10.to_s, 
+       "DEF:A=#{rrd}:a:AVERAGE",
+       "DEF:B=#{rrd}:b:AVERAGE",
+       "XPORT:A:a",
+       "XPORT:B:b")
+puts "Xported #{col} columns(#{legend.join(", ")}) with #{data.length} rows from #{fstart} to #{fend} and step #{step}\n"
+
 print "This script has created #{name}.png in the current directory\n";
 print "This demonstrates the use of the TIME and % RPN operators\n";
 print "This script has created #{name}.png in the current directory\n";
 print "This demonstrates the use of the TIME and % RPN operators\n";