Skip to content

Instantly share code, notes, and snippets.

@debborafernandess
Last active June 22, 2017 19:02
Show Gist options
  • Save debborafernandess/64f3610ae455cb52e99544c5043af64c to your computer and use it in GitHub Desktop.
Save debborafernandess/64f3610ae455cb52e99544c5043af64c to your computer and use it in GitHub Desktop.
yesterday = Date.parse('2017-06-21')
this_in_last_week = Date.parse('2017-06-21') - 7
report = File.new("exportacao.csv", 'w')
report << "Location, #{yesterday.strftime('%d-%m')}, #{this_in_last_week.strftime('%d-%m')}, \n"
locations_br = Country.find_by(name: 'Brasil').locations.active
locations_br.each do |location|
new_access = location.accesses.by_period(yesterday.beginning_of_day, yesterday.end_of_day).count
old_access = location.accesses.by_period(this_in_last_week.beginning_of_day, this_in_last_week.end_of_day).count
report << "#{location.acronym};#{new_access};#{old_access}\n"
end
report.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment