From 774f546662e76226cf1c3cba785a39b3c3d45c70 Mon Sep 17 00:00:00 2001 From: oetiker Date: Mon, 8 Dec 2008 16:07:27 +0000 Subject: [PATCH] Fix for last method in ruby bindings -- Hiroyuki Ikezoe git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.3@1700 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/bindings/ruby/main.c | 2 +- program/bindings/ruby/test.rb | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/program/bindings/ruby/main.c b/program/bindings/ruby/main.c index d2a7ace0..6b6989a9 100644 --- a/program/bindings/ruby/main.c +++ b/program/bindings/ruby/main.c @@ -300,7 +300,7 @@ VALUE rb_rrd_last( string_arr_delete(a); RRD_CHECK_ERROR - return rb_funcall(rb_cTime, rb_intern("at"), 1, INT2FIX(last)); + return rb_funcall(rb_cTime, rb_intern("at"), 1, UINT2NUM(last)); } void Init_RRD( diff --git a/program/bindings/ruby/test.rb b/program/bindings/ruby/test.rb index 48533266..3d0b95f3 100755 --- a/program/bindings/ruby/test.rb +++ b/program/bindings/ruby/test.rb @@ -8,12 +8,13 @@ require "RRD" name = "test" rrd = "#{name}.rrd" -start = Time.now.to_i +start_time = Time.now.to_i +end_time = start_time.to_i + 300 * 300 puts "creating #{rrd}" RRD.create( rrd, - "--start", "#{start - 1}", + "--start", "#{start_time - 1}", "--step", "300", "DS:a:GAUGE:600:U:U", "DS:b:GAUGE:600:U:U", @@ -21,13 +22,13 @@ RRD.create( puts puts "updating #{rrd}" -start.to_i.step(start.to_i + 300 * 300, 300) { |i| +start_time.step(end_time, 300) { |i| RRD.update(rrd, "#{i}:#{rand(100)}:#{Math.sin(i / 800) * 50 + 50}") } puts puts "fetching data from #{rrd}" -(fstart, fend, data) = RRD.fetch(rrd, "--start", start.to_s, "--end", (start + 300 * 300).to_s, "AVERAGE") +(fstart, fend, data) = RRD.fetch(rrd, "--start", start_time.to_s, "--end", end_time.to_s, "AVERAGE") puts "got #{data.length} data points from #{fstart} to #{fend}" puts @@ -35,7 +36,7 @@ puts "generating graph #{name}.png" RRD.graph( "#{name}.png", "--title", " RubyRRD Demo", - "--start", "#{start+3600}", + "--start", "#{start_time+3600}", "--end", "start + 1000 min", "--interlace", "--imgformat", "PNG", @@ -48,5 +49,12 @@ RRD.graph( "LINE3:line#ff0000") puts +# last method test +if end_time != RRD.last("#{rrd}").to_i + puts "last method expects #{Time.at(end_time)}." + puts " But #{RRD.last("#{rrd}")} returns." +end +puts + print "This script has created #{name}.png in the current directory\n"; print "This demonstrates the use of the TIME and % RPN operators\n"; -- 2.30.2