Sorry to ask, but I'm struggling somewhat. Essentially I have the following function:
weekly_reach_data = weekly_reach_arr.map do |data| [
{
name: "DCable",
data: {x: data['Graph numerics'].to_i, y: data['DCable'].to_f}
},
{
name: "DSat",
data: {x: data['Graph numerics'].to_i, y: data['DSat'].to_f}
},
{
name: "DTT",
data: {x: data['Graph numerics'].to_i, y: data['DTT'].to_f}
}
]
end
This outputs data in this form:
{:name=>"DCable", :data=>{:x=>1, :y=>1.8}}
{:name=>"DSat", :data=>{:x=>1, :y=>7.48}}
{:name=>"DTT", :data=>{:x=>1, :y=>5.81}}
{:name=>"DCable", :data=>{:x=>2, :y=>2.29}}
{:name=>"DSat", :data=>{:x=>2, :y=>7.74}}
{:name=>"DTT", :data=>{:x=>2, :y=>5.82}} etc
However, I require the data to be in this form:
{:name=>"DCable", :data=>[{:x=>1, :y=>2}, {:x=>2, :y=>3}]}
{:name=>"DSat", :data=>[{:x=>1, :y=>5}, {:x=>2, :y=>8}]}
{:name=>"DTT", :data=>[{:x=>1, :y=>3}, {:x=>2, :y=>9}]}
As you can see, the former is looping and creating multiple entries. Does anybody know how I can reconstruct the map function to output in this form?
Weekly_reach_arr is an array in this form:
{"Graph numerics"=>"1", "Users"=>"S", "All platforms"=>"14.99", "DSat"=>"7.48", "DTT"=>"5.81", "DCable"=>"1.80", "% Reach"=>"S", "Target"=>"33.33%"}
{"Graph numerics"=>"2", "Users"=>"O", "All platforms"=>"15.60", "DSat"=>"7.74", "DTT"=>"5.82", "DCable"=>"2.29", "% Reach"=>"O", "Target"=>"33.33%"}
{"Graph numerics"=>"3", "Users"=>"N", "All platforms"=>"16.83", "DSat"=>"7.78", "DTT"=>"6.65", "DCable"=>"2.52", "% Reach"=>"N", "Target"=>"33.33%"}
{"Graph numerics"=>"4", "Users"=>"D", "All platforms"=>"16.27", "DSat"=>"7.64", "DTT"=>"7.01", "DCable"=>"1.68", "% Reach"=>"D", "Target"=>"33.33%"}... etc
nameanddatakeys and flatten it to aHashthat has thenameas the key and thedataas the value