diff --git a/contracts/hestia/1_create_flux_query_read.keys b/contracts/hestia/1_create_flux_query_read.keys new file mode 100755 index 0000000..6d20d82 --- /dev/null +++ b/contracts/hestia/1_create_flux_query_read.keys @@ -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" +} diff --git a/contracts/hestia/2_execute_flux_query_read.keys b/contracts/hestia/2_execute_flux_query_read.keys new file mode 100755 index 0000000..9abf564 --- /dev/null +++ b/contracts/hestia/2_execute_flux_query_read.keys @@ -0,0 +1,7 @@ +{ + "influx": { + "token": "u_g2ZwegiBxffdkXhiAlfXYjSGxreLnb4Ia2Ek8BSPnraT57xFYz6erKZ7joTZRzcAhSEuoc2UNcFo9HxBKk2w==", + "url": "https://hestia-platform.imp.bg.ac.rs:8086", + "org": "hestia" + } +} diff --git a/contracts/hestia/read_last_influx_hestia.yml b/contracts/hestia/read_last_influx_hestia.yml new file mode 100755 index 0000000..f91b470 --- /dev/null +++ b/contracts/hestia/read_last_influx_hestia.yml @@ -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