Forum: Ruby Gruff labels

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B205fb18750395f1677c26382309bad2?d=identicon&s=25 Rick Jones (ukbell)
on 2008-12-06 15:49
I have been working on this code for a few days and can't seem to figure
out what I am doing wrong... Labeling gruff is pretty easy for the most
part (just put it in hash format) but I can't get this to work for
anything...

This is basically the code that I am working on:

I won't go through the code to get the first input and the last input
for both the hour and the minute, but I am fine on that part of the code
and I named them: last_min_hour, last_time_min, last_time_hour and
first_time_min.

count_incr += 0
access_bar_hash = Hash.new(0)

time_regex = /d{1,2}:[5][0]/ # looks for only 50 minute intervals

reads = 60 # this will change based on how many times the program runs
label_spacing = 60/reads # 60 is how many columns there are

final_last_time = [last_time_hour, last_time_min].join(":")
final_first_time = [first_time_hour, first_time_min].join(":")

incr_hash[count_incr] = final_first_time
while count_incr < 8 # the 8 will actually be dynamic, but use this for
now
    if incr_hash[count_incr] =~ time_regex
        first_time_hour += 1
        first_time_min = '00'
    else
        first_time_min = first_time_min.to_i
        first_time_min += 10
    end
    count_incr += 1
    incr_hash[count_incr] = [first_time_hour, first_time_min].join(":")
    spacer = label_spacing * (count_reads)
    access_bar_hash[(label_spacing * count_incr)] =
incr_hash[count_incr]
end

access_bar.labels = access_bar_hash

----

What I don't understand is that if i take the output of what
access_bar_hash gives me, it input that directly into the
access_bar.labels, this works perfect. But I must be putting this into
the hash wrong somehow... Can anyone take a look at this and give me
some help?
B205fb18750395f1677c26382309bad2?d=identicon&s=25 Rick Jones (ukbell)
on 2008-12-06 15:51
I said up there that "reads = 60" but actually reads should equal 8 for
now... That shouldn't matter too much though.
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2008-12-08 07:04
> reads = 60 # this will change based on how many times the program runs
> label_spacing = 60/reads # 60 is how many columns there are

Just guessing, make sure your labels are for "exactly the right x
locations"--are you trying to label x or y?  What happens currently?
What did you expect to happen instead?
Thanks!
-=R
B205fb18750395f1677c26382309bad2?d=identicon&s=25 Rick Jones (ukbell)
on 2008-12-08 13:43
Rereading through my description above, this isn't a very good
description of what I am trying to do... Essentially I am trying to
dynamically update the x-axis. I am reading in apache's server every 60
seconds and storing the data to a csv file. Then in this program, I take
that csv file and graph the data. And for the labels, I need to print a
label at every 10 minute interval. So if the program runs from 7:00 to
8:00, I should have 7:00, 7:10, etc... 8:00.

The error message that I am getting is something about annotation.
"cannot convert fixnum to string."
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2008-12-11 13:22
> The error message that I am getting is something about annotation.
> "cannot convert fixnum to string."

Odd
I'd first make sure you're passing in something like
    g.labels = {
      0 => '5/6',
      2 => '5/15',
      4 => '5/24',
      6 => '5/30',
    }

-=R
B205fb18750395f1677c26382309bad2?d=identicon&s=25 Rick Jones (ukbell)
on 2008-12-11 18:19
Roger Pack wrote:
>
>> The error message that I am getting is something about annotation.
>> "cannot convert fixnum to string."
>
> Odd
> I'd first make sure you're passing in something like
>     g.labels = {
>       0 => '5/6',
>       2 => '5/15',
>       4 => '5/24',
>       6 => '5/30',
>     }
>
> -=R

It turned out, my problem was that when I initialized my hash, I
shouldn't have ended with the (0). I didn't think it was a big deal but
it worked perfect as soon as I took it away...

Thanks for your help on the matter though. Much appreciated.
This topic is locked and can not be replied to.