0

Working with Dashin.io framework to create some nice graphs. I'm trying to construct a specific array output that the application is looking for and I'm very close, but think I need help creating another dimension of the array.

This is what I have:

r = Redis.new(:host => "127.0.0.1", :password => 'password')
assGroups=['group1','group2', 'group3', 'group4']
points = ['Day', 'group1','group2', 'group3', 'group4']

history = 3
i = 0

while i <= history do
    getdate = (Date.today-i).strftime("%Y-%m-%d")
    i += 1
    countArr=[getdate]
    points.push(countArr)

    for group in assGroups
        query = [getdate,":",group].join()
        queue = r.hgetall query
        dCount = queue['incidents'].to_i
        countArr << dCount
    end
end
print points

This is giving me

["Day", "group1","group2", "group3", "group4", ["2016-06-06", 63, 13, 86, 13], ["2016-06-05", 64, 13, 84, 13], ["2016-06-04", 63, 13, 84, 13], ["2016-06-03", 64, 13, 84, 13]]

This is very close but I need the, "Day" and groups its own dimension of the array as well, so this would be my desired output:

[["Day", "group1","group2", "group3", "group4"], ["2016-06-06", 63, 13, 86, 13], ["2016-06-05", 64, 13, 84, 13], ["2016-06-04", 63, 13, 84, 13], ["2016-06-03", 64, 13, 84, 13]]

1 Answer 1

3

Looks like the simplest change would be to ensure points is a multidimensional array when you first define it: points = [['Day', 'group1','group2', 'group3', 'group4']]

Sign up to request clarification or add additional context in comments.

1 Comment

ahh yes much better then what I was trying with unshift() Thanks for the quick answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.