Skip to content

Commit

Permalink
Merge branch 'release/0.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Oct 13, 2024
2 parents b97815b + 40aca0d commit 815fee7
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.4
3.3.5
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:3.3.4-alpine AS builder
FROM ruby:3.3.5-alpine AS builder
RUN apk add --no-cache build-base

WORKDIR /power-splitter
Expand All @@ -8,7 +8,7 @@ RUN bundle config --local frozen 1 && \
bundle install -j4 --retry 3 && \
bundle clean --force

FROM ruby:3.3.4-alpine
FROM ruby:3.3.5-alpine
LABEL org.opencontainers.image.authors="[email protected]"
LABEL org.opencontainers.image.description="Distributes imported grid power among individual consumers"

Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ gem 'influxdb-client'
# CSV Reading and Writing (https://github.com/ruby/csv)
gem 'csv'

# Support for encoding and decoding binary data using a Base64 representation. (https://github.com/ruby/base64)
gem 'base64'
# Class to build custom data structures, similar to a Hash. (https://github.com/ruby/ostruct)
gem 'ostruct'

# A toolkit of support libraries and Ruby core extensions extracted from the Rails framework. (https://rubyonrails.org)
gem 'activesupport', '~> 7.1', '< 7.2'
gem 'activesupport'

# A Ruby client library for Redis (https://github.com/redis/redis-rb)
gem 'redis'
Expand Down
52 changes: 26 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.4)
activesupport (7.2.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
amazing_print (1.6.0)
Expand All @@ -26,7 +27,7 @@ GEM
csv (3.3.0)
diff-lcs (1.5.1)
docile (1.4.1)
dotenv (3.1.2)
dotenv (3.1.4)
drb (2.2.1)
ffi (1.17.0)
formatador (1.1.0)
Expand All @@ -45,24 +46,25 @@ GEM
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashdiff (1.1.1)
i18n (1.14.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
influxdb-client (3.1.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.1)
lumberjack (1.2.10)
method_source (1.1.0)
minitest (5.25.1)
mutex_m (0.2.0)
nenv (0.3.0)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
ostruct (0.6.0)
parallel (1.26.3)
parser (3.3.4.2)
parser (3.3.5.0)
ast (~> 2.4.1)
racc
pry (0.14.2)
Expand All @@ -80,59 +82,57 @@ GEM
redis-client (0.22.2)
connection_pool
regexp_parser (2.9.2)
rexml (3.3.6)
strscan
rexml (3.3.8)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-core (3.13.1)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.2)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.65.1)
rubocop (1.66.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.1)
rubocop-ast (1.32.3)
parser (>= 3.3.1.0)
rubocop-performance (1.21.1)
rubocop-performance (1.22.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (3.0.4)
rubocop-rspec (3.1.0)
rubocop (~> 1.61)
rubocop-thread_safety (0.5.1)
rubocop (>= 0.90.0)
ruby-progressbar (1.13.0)
securerandom (0.3.1)
shellany (0.0.1)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
strscan (3.1.0)
thor (1.3.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
unicode-display_width (2.6.0)
vcr (6.3.1)
base64
webmock (3.23.1)
webmock (3.24.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand All @@ -141,13 +141,13 @@ PLATFORMS
ruby

DEPENDENCIES
activesupport (~> 7.1, < 7.2)
activesupport
amazing_print
base64
csv
dotenv
guard-rspec
influxdb-client
ostruct
rake
redis
rspec
Expand All @@ -161,4 +161,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
2.5.18
2.5.21
11 changes: 8 additions & 3 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def field(sensor_name)
@field[sensor_name] ||= splitted_sensor_name(sensor_name)&.last
end

def identifier(sensor_name)
sensor_method = sensor_name.downcase
return unless respond_to?(sensor_method)

public_send(sensor_method)
end

def exists?(sensor_name)
case sensor_name
when *SENSOR_NAMES
Expand Down Expand Up @@ -167,8 +174,6 @@ def validate!(sensor_name, value)
end

def splitted_sensor_name(sensor_name)
return unless respond_to?(sensor_name.downcase)

public_send(sensor_name.downcase)&.split(':')
identifier(sensor_name)&.split(':')
end
end
12 changes: 9 additions & 3 deletions lib/flux/extractor.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
require_relative 'reader'

ActiveSupport.to_time_preserves_timezone = true

module Flux
class Extractor < Flux::Reader
def records(day)
range = day_range(day)
return [] unless range

query_string = <<~FLUX
#{from_bucket}
|> #{day_range(day)}
|> #{range}
|> #{filter(selected_sensors: config.sensor_names)}
|> aggregateWindow(every: 1m, fn: mean)
|> fill(usePrevious: true)
Expand All @@ -28,7 +33,7 @@ def day_range(day)
start + 1.day
end

range(start:, stop:)
range(start:, stop:) if stop > start
end

def extract_and_transform_data(flux_tables)
Expand All @@ -37,10 +42,11 @@ def extract_and_transform_data(flux_tables)
table.records.each do |record|
time = record.values['_time'].to_time
field = record.values['_field']
measurement = record.values['_measurement']
value = record.values['_value']

results[time] ||= { 'time' => time }
results[time][field] = value
results[time]["#{measurement}:#{field}"] = value
end
end

Expand Down
3 changes: 0 additions & 3 deletions lib/null_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ def info(message)
def error(message)
end

def debug(message)
end

def warn(message)
end
end
4 changes: 3 additions & 1 deletion lib/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def heatpump_power(record)
end

def power_value(record, sensor_name)
record[config.field(sensor_name)] || 0.0
identifier = config.identifier(sensor_name)

record[identifier] || 0.0
end

def split_power(record)
Expand Down
5 changes: 0 additions & 5 deletions lib/stdout_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ def error(message)
puts "\e[31m#{message}\e[0m"
end

def debug(message)
# Blue text by using ANSI escape code
puts "\e[34m#{message}\e[0m"
end

def warn(message)
# Yellow text by using ANSI escape code
puts "\e[33m#{message}\e[0m"
Expand Down
16 changes: 8 additions & 8 deletions spec/lib/flux/extractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
expect(day_records).to be_an(Array).and all(be_a(Hash)).and all(
include(
'time',
'grid_power_plus',
'house_power',
'wallbox_charge_power',
'power',
'SENEC:grid_power_plus',
'SENEC:house_power',
'SENEC:wallbox_charge_power',
'Consumer:power',
),
)

Expand All @@ -66,10 +66,10 @@
expect(day_records).to be_an(Array).and all(be_a(Hash)).and all(
include(
'time',
'grid_power_plus',
'house_power',
'wallbox_charge_power',
'power',
'SENEC:grid_power_plus',
'SENEC:house_power',
'SENEC:wallbox_charge_power',
'Consumer:power',
),
)

Expand Down
16 changes: 8 additions & 8 deletions spec/lib/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
[
{
'time' => Time.new('2022-01-01 12:00:00 +01:00'),
'grid_power_plus' => 100,
'house_power' => 70,
'wallbox_charge_power' => 30,
'power' => 20,
'SENEC:grid_power_plus' => 100,
'SENEC:house_power' => 70,
'SENEC:wallbox_charge_power' => 30,
'Consumer:power' => 20,
},
{
'time' => Time.new('2022-01-01 12:30:00 +01:00'),
'grid_power_plus' => 0,
'house_power' => 140,
'wallbox_charge_power' => 60,
'power' => 40,
'SENEC:grid_power_plus' => 0,
'SENEC:house_power' => 140,
'SENEC:wallbox_charge_power' => 60,
'Consumer:power' => 40,
},
]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/redis_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
flush

expect(logger.error_messages).to include(
'Flushing Redis cache failed: Connection refused - connect(2) for 127.0.0.1:1234 (redis://localhost:1234)',
/Flushing Redis cache failed: Connection refused/,
)
end
end
Expand Down
7 changes: 0 additions & 7 deletions spec/lib/stdout_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@
it { expect { error }.to output(/\e\[31m/).to_stdout }
end

describe '#debug' do
subject(:debug) { logger.debug(message) }

it { expect { debug }.to output(/#{message}/).to_stdout }
it { expect { debug }.to output(/\e\[34m/).to_stdout }
end

describe '#warn' do
subject(:warn) { logger.warn(message) }

Expand Down
4 changes: 0 additions & 4 deletions spec/support/memory_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def warn(message)
synchronize { @warn_messages << message }
end

def debug(message)
synchronize { @debug_messages << message }
end

private

def synchronize(&)
Expand Down

0 comments on commit 815fee7

Please sign in to comment.