Skip to content

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Aug 30, 2024
2 parents d27c99e + 278a79d commit b97815b
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 211 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
##### Timezone
TZ=Europe/Berlin

# Options
POWER_SPLITTER_INTERVAL=3600

##### InfluxDB credentials
INFLUX_HOST=localhost
INFLUX_SCHEMA=http
INFLUX_PORT=8086
INFLUX_TOKEN=my-token # With permissions to read AND write to the bucket
INFLUX_ORG=my-org
INFLUX_BUCKET=my-bucket
INFLUX_INTERVAL=3600

#### Sensor mapping: Map to Measurement/Field in InfluxDB

Expand Down
4 changes: 3 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Timezone
TZ=Europe/Berlin

# Options
POWER_SPLITTER_INTERVAL=300

##### InfluxDB credentials
INFLUX_HOST=localhost
INFLUX_SCHEMA=http
INFLUX_PORT=8086
INFLUX_TOKEN=my-token
INFLUX_ORG=my-org
INFLUX_BUCKET=my-bucket
INFLUX_INTERVAL=5

##### Redis
REDIS_URL=redis://localhost:6379/1
Expand Down
23 changes: 0 additions & 23 deletions .github/workflows/lock-closed-issues.yml

This file was deleted.

6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.3.4)
activesupport (7.1.4)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
Expand Down Expand Up @@ -126,7 +126,7 @@ GEM
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
strscan (3.1.0)
thor (1.3.1)
thor (1.3.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
Expand Down Expand Up @@ -161,4 +161,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
2.5.17
2.5.18
4 changes: 2 additions & 2 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Config # rubocop:disable Metrics/ClassLength
:influx_token,
:influx_org,
:influx_bucket,
:influx_interval,
:interval,
:redis_url,
:time_zone

Expand All @@ -24,7 +24,7 @@ def initialize(env, logger: NullLogger.new)
@influx_token = env.fetch('INFLUX_TOKEN')
@influx_org = env.fetch('INFLUX_ORG')
@influx_bucket = env.fetch('INFLUX_BUCKET')
@influx_interval = [env.fetch('INFLUX_INTERVAL', '3600').to_i, 300].max
@interval = [env.fetch('POWER_SPLITTER_INTERVAL', '3600').to_i, 300].max
validate_url!(influx_url)
logger.info "Accessing InfluxDB at #{influx_url}, bucket #{influx_bucket}"

Expand Down
20 changes: 11 additions & 9 deletions lib/flux/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
module Flux
class Extractor < Flux::Reader
def records(day)
return [] if day.today? && Time.current.hour.zero?

query_string = <<~FLUX
#{from_bucket}
|> #{day_range(day)}
Expand All @@ -20,13 +18,17 @@ def records(day)
private

def day_range(day)
range(
start: day.beginning_of_day,
stop: [
day.beginning_of_day + 1.day,
Time.current.beginning_of_hour,
].min,
)
start = day.beginning_of_day

stop =
if day.today?
current_time = Time.current
current_time.beginning_of_minute - (current_time.min % 5).minutes
else
start + 1.day
end

range(start:, stop:)
end

def extract_and_transform_data(flux_tables)
Expand Down
4 changes: 2 additions & 2 deletions lib/loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def process_current_data
count += 1
break if max_count && count >= max_count

config.logger.info " Sleeping for #{config.influx_interval} seconds...\n\n"
sleep(config.influx_interval)
config.logger.info " Sleeping for #{config.interval} seconds...\n\n"
sleep(config.interval)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def group_by_5min(splitted)
.group_by { |item| (item[:time].to_i - 1.minute) / 5.minutes }
.map do |_interval, items|
{
time: items.first[:time].beginning_of_minute,
time: items.last[:time],
house_power_grid: sum(items, :house_power_grid),
wallbox_power_grid:
wallbox_present ? sum(items, :wallbox_power_grid) : nil,
Expand Down
32 changes: 16 additions & 16 deletions spec/cassettes/extractor.yml

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions spec/cassettes/first_sensor-with-records.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions spec/cassettes/first_sensor-without-records.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions spec/cassettes/influx_success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions spec/cassettes/last_splitter-with-records.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions spec/cassettes/last_splitter-without-records.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b97815b

Please sign in to comment.