diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2014-02-13 08:54:35 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2014-02-13 08:54:35 +0100 |
commit | ca90189f199f35017cf16b92947d738c2880b444 (patch) | |
tree | 69d92b5044a9d3f469601b69c143f11298771dad | |
download | imusician-reports-ca90189f199f35017cf16b92947d738c2880b444.tar.gz imusician-reports-ca90189f199f35017cf16b92947d738c2880b444.tar.bz2 imusician-reports-ca90189f199f35017cf16b92947d738c2880b444.zip |
Initial commit.
Parse the CSV-file, and aggregate total sales by date.
-rw-r--r-- | parse_report.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/parse_report.rb b/parse_report.rb new file mode 100644 index 0000000..840708e --- /dev/null +++ b/parse_report.rb @@ -0,0 +1,26 @@ +require "csv" + +csv_opts = { + :col_sep => ";", + :skip_lines => /^(Notes|The |;)/, + :headers => true, + :converters => :all, +} + +sales_by_date = {} + +rows = CSV.foreach(ARGV[0], csv_opts) + +rows.each do |row| + d = Date.parse(row["Date"]) + if sales_by_date[d] + sales_by_date[d][:count] += row["quantity"] + sales_by_date[d][:total] += row["revenue EUR"] + else + sales_by_date[d] = {:count => row["quantity"], :total => row["revenue EUR"]} + end +end + +sales_by_date.each do |row| + p row +end |