Skip to content

Instantly share code, notes, and snippets.

@andresprogra
Last active October 25, 2018 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andresprogra/c778f23ec0b6a6ca6e82a43147d59119 to your computer and use it in GitHub Desktop.
Save andresprogra/c778f23ec0b6a6ca6e82a43147d59119 to your computer and use it in GitHub Desktop.
Test.rb
# Antes
line_chart = []
@project.areas.uniq.each do |area|
activity_area = []
area.project_areas.where(project_id: @project.id).group("DATE_TRUNC('day', created_at)").sum(:progress).each do |key, values|
activity_area << { value: values, date: key}
end
line_chart << { name: area.name, series: activity_area }
end
# Despues
@project.areas.uniq.map do |area|
activity_area = area.project_areas.where(project_id: @project.id).group("DATE_TRUNC('day', created_at)").sum(:progress).map{ |key, item| { value: item, date: key} }
{ name: area.name, series: activity_area }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment