Skip to content

Commit

Permalink
feat: added read_last_influx script
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-dintino committed May 28, 2024
1 parent 343c119 commit 8fea20b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
8 changes: 8 additions & 0 deletions contracts/hestia/1_create_flux_query_read.keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"24h": "86400",
"flux_query_1": "from(bucket: \"hestia\") |> range(start: ",
"flux_query_2": ", stop: ",
"flux_query_3": ") |> filter(fn: (r) => r._measurement == \"active_energy\" and r.device_id == \"",
"flux_query_4": "\") |> last()",
"1000": "1000"
}
7 changes: 7 additions & 0 deletions contracts/hestia/2_execute_flux_query_read.keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"influx": {
"token": "u_g2ZwegiBxffdkXhiAlfXYjSGxreLnb4Ia2Ek8BSPnraT57xFYz6erKZ7joTZRzcAhSEuoc2UNcFo9HxBKk2w==",
"url": "https://hestia-platform.imp.bg.ac.rs:8086",
"org": "hestia"
}
}
80 changes: 80 additions & 0 deletions contracts/hestia/read_last_influx_hestia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
zenchain: 1.0
start: 1_create_flux_query_read.zen
blocks:
1_create_flux_query_read.zen:
zenContent: |-
Rule unknown ignore
Given I fetch the local timestamp and store it into 'timestamp'
# restroom data
Given I have a 'integer' named 'timestamp'
# keys
Given I have a 'string' named 'flux_query_1'
Given I have a 'string' named 'flux_query_2'
Given I have a 'string' named 'flux_query_3'
Given I have a 'string' named 'flux_query_4'
Given I have a 'integer' named '24h'
Given I have a 'integer' named '1000'
# data
Given I have a 'string array' named 'household'
# timestamp
When I create the result of 'timestamp' / '1000'
When I rename 'result' to 'now'
When I create the result of 'now' - '24h'
Foreach 'device' in 'household'
If I verify 'device' has suffix '-grid-exported'
When I copy 'device' to 'meter_exported_energy'
EndIf
If I verify 'device' has suffix '-grid-imported'
When I copy 'device' to 'meter_imported_energy'
EndIf
Endforeach
When I copy 'flux_query_1' to 'flux_query_exported'
and I append 'result' to 'flux_query_exported'
and I append 'flux_query_2' to 'flux_query_exported'
and I append 'now' to 'flux_query_exported'
and I append 'flux_query_3' to 'flux_query_exported'
and I append 'meter_exported_energy' to 'flux_query_exported'
and I append 'flux_query_4' to 'flux_query_exported'
When I rename 'flux_query_1' to 'flux_query_imported'
and I append 'result' to 'flux_query_imported'
and I append 'flux_query_2' to 'flux_query_imported'
and I append 'now' to 'flux_query_imported'
and I append 'flux_query_3' to 'flux_query_imported'
and I append 'meter_imported_energy' to 'flux_query_imported'
and I append 'flux_query_4' to 'flux_query_imported'
When I create the 'string array' named 'flux_queries'
and I move 'flux_query_exported' in 'flux_queries'
and I move 'flux_query_imported' in 'flux_queries'
Then print the 'flux_queries'
keysFile: 1_create_flux_query_read.keys
next: 2_execute_flux_query_read.zen
2_execute_flux_query_read.zen:
zenContent: >
Rule unknown ignore
Given I connect to influxdb with the connection object named 'influx'
Given I execute the array of flux queries named 'flux_queries' and save
the output into 'flux_result'
Given I have a 'string array' named 'flux_result'
Then print the data
# 4690925
keysFile: 2_execute_flux_query_read.keys

0 comments on commit 8fea20b

Please sign in to comment.