diff options
author | pks <pks@pks.rocks> | 2021-05-16 18:23:12 +0200 |
---|---|---|
committer | pks <pks@pks.rocks> | 2021-05-16 18:23:12 +0200 |
commit | 8a89176b2b563ad20c21eea6f31cef01c46582dc (patch) | |
tree | 7e9f0a44e9d52d6ed2e957ca4b524b2fa3b61f6c /power-meter | |
parent | 899ba88b76a2f01b1bab87fbb960c2277435c521 (diff) |
restart
Diffstat (limited to 'power-meter')
-rwxr-xr-x | power-meter | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/power-meter b/power-meter index 9ffd7c6..4e05af5 100755 --- a/power-meter +++ b/power-meter @@ -5,24 +5,28 @@ require 'sqlite3' def main db = SQLite3::Database.new ARGV[0] devices = db.execute "select distinct device_location_primary, device_location_secondary FROM power" + puts devices.to_s + exit devices.reject! { |i| not ["office", "living_room", "guest_restroom", "kitchen", "bedroom_2"].include? i[0] } - start_date = Date.new(2020,9,01).to_time.to_i - end_date = Date.new(2020,9,30).to_time.to_i + start_date = Date.new(2021,01,01).to_time.to_i + end_date = Date.new(2021,01,30).to_time.to_i totals = {} totals.default = 0.0 devices.sort_by{|i| i[0] }.each { |device| + puts "select TOTAL, TIMESTAMP from power WHERE TIMESTAMP >= #{start_date} and TIMESTAMP <= #{end_date} AND DEVICE_LOCATION_PRIMARY = '#{device[0]}' AND DEVICE_LOCATION_SECONDARY = '#{device[1]}' ORDER BY TIMESTAMP ASC LIMIT 1" + exit first = db.execute "select TOTAL, TIMESTAMP from power WHERE TIMESTAMP >= #{start_date} and TIMESTAMP <= #{end_date} AND DEVICE_LOCATION_PRIMARY = '#{device[0]}' AND DEVICE_LOCATION_SECONDARY = '#{device[1]}' ORDER BY TIMESTAMP ASC LIMIT 1" last = db.execute "select TOTAL, TIMESTAMP from power WHERE TIMESTAMP >= #{start_date} and TIMESTAMP <= #{end_date} AND DEVICE_LOCATION_PRIMARY = '#{device[0]}' AND DEVICE_LOCATION_SECONDARY = '#{device[1]}' ORDER BY TIMESTAMP DESC LIMIT 1" if first.size > 0 and last.size > 0 - puts "#{Time.at(first[0][1])} --- #{Time.at(last[0][1])}" - puts "#{first[0][0]} ::: #{last[0][0]}" + #puts "#{Time.at(first[0][1])} --- #{Time.at(last[0][1])}" + #puts "#{first[0][0]} ::: #{last[0][0]}" kwh = last[0][0] - first[0][0] - puts "#{device.join '/'}: #{kwh.round 0} kW/h" - puts + #puts "#{device.join '/'}: #{kwh.round 0} kW/h" + #puts totals[device[0]] += kwh end } - puts "=== TOTAL: #{totals.values.inject(:+).round 0} kW/h ===" + puts "TOTAL for #{start_date} - #{end_date}: #{totals.values.inject(:+).round 0} kW/h" puts "\nBy Room" puts "-------" totals.each_key { |k| |