Last active
July 23, 2020 02:06
-
-
Save td512/564279112b8ac6bb840692a925a391cc to your computer and use it in GitHub Desktop.
Meter counting script for Flick Electric users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
csv = CSV.parse(File.read("/tmp/csvdata"), headers: true) | |
hash = Hash.new | |
total = 0.0 | |
csv.by_col[3].each_with_index do |val,index| | |
hash[Date.parse(val)] = 0.0 unless hash.key?(Date.parse(val)) | |
hash[Date.parse(val)] += csv.by_col[5][index].to_f | |
puts "Processed data for #{Date.parse(val)}: #{csv.by_col[5][index]} kWh" | |
end | |
puts '' | |
puts '' | |
puts '===============================' | |
puts "Completed processing!" | |
hash.each do |k,v| | |
total += (v*0.261).round(2) | |
puts "Data for #{k}: #{v.round(2)} kWh @ 0.261c/unit ($#{(v*0.261).round(2)})" | |
end | |
puts '===============================' | |
puts "Total (#{hash.keys.first} - #{hash.keys.last}, GST Exclusive): #{(total/0.261).round(2)} kWh @ 0.261c/unit ($#{total.round(2)})" | |
puts "Total (#{hash.keys.first} - #{hash.keys.last}, GST Inclusive): #{(total/0.261).round(2)} kWh @ 0.300c/unit ($#{(total + ((total / 100)*15)).round(2)}, GST Content: $#{((total / 100)*15).round(2)})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment