-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from destroyedlolo/Dev
Add NamedMinMax
- Loading branch information
Showing
24 changed files
with
636 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# .namedminmax | ||
NamedMinMax generates some statistics from several named dataset (instead of only one as [MinMax](MinMax.md) is doing). | ||
|
||
## Syntax | ||
|
||
NamedMinMax are basically **[Lua tasks](Task(lua).md)** and are following the same syntax. | ||
|
||
In the header of the script (comment block at the very beginning of the script), each line starting with `-->>` are Majordome's commands.<br> | ||
Consequently, `--->>` are commented out commands (notice the 3 dashes). | ||
|
||
## Directives | ||
|
||
### Generals | ||
|
||
#### -->> name= | ||
Unique name to identify the NamedMinMax. If not set, uses the filename. | ||
`-->> name=toto` | ||
#### -->> quiet | ||
Remove some trace. This option is useful to avoid logging of very noisy topics. | ||
|
||
#### -->> disabled | ||
This NamedMinMax starts as disabled : stats change and incoming messages are ignored. | ||
|
||
### NamedMinMax owns | ||
None | ||
|
||
### Exposed variables | ||
- **MAJORDOME_Myself** is automatically created and correspond to the current NamedMinMax | ||
- **MAJORDOME_NAMEDMINMAX** - NamedMinMax's name | ||
|
||
## at Lua side | ||
### Exposed objects | ||
Statistics sequencing and retrieving are done through the **MajordomeNamedMinMax**'s API : | ||
- `getContainer()` returns the container (directory) in which this NamedMinMax has been defined | ||
- `getName()` returns NamedMinMax's name | ||
- `isEnabled()` returns a boolean reflecting if this NamedMinMax is enabled or not | ||
- `Enable()` to enable this NamedMinMax | ||
- `Disable()` to disable this NamedMinMax | ||
- `Clear(name)` or `Reset(name)` to reset data statistics : a new collection is starting (only impacting the one the name is provided) | ||
- `getMin(name)`, `getMax(name)`, `getAverage(name)` : some statistics | ||
- `getSum(name)` : sum of all incoming data since last `Reset()` | ||
- `getSamplesNumber(name)` : number of samples received since last `Reset()` | ||
- `FiguresNames()` : return all figures name's |
25 changes: 25 additions & 0 deletions
25
Documentations/SamplesCode/NamedMinMax/50_TestNamedMinMax/10s.timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Timer to launch tasks every 10 secondes | ||
|
||
# name of the timer | ||
# if not set, takes the filename | ||
#name=toto | ||
|
||
# repeating delay (in seconds) | ||
# ignored if null | ||
every=10 | ||
|
||
# This timer is set to an absolute time, | ||
# format HHMM | ||
#at=2256 | ||
|
||
# NOTEZ-BIEN : every has precedence on at. | ||
# If both are present, only every is took in account | ||
|
||
# Launch tasks at startup | ||
#immediate | ||
|
||
# Launch tasks if Majordome is starting after at= time (for the same day) | ||
#runifover | ||
|
||
# disable this timer | ||
#disabled |
43 changes: 43 additions & 0 deletions
43
Documentations/SamplesCode/NamedMinMax/50_TestNamedMinMax/Collector.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- This task with collect minmax data every 1 minute. | ||
-- | ||
-- In the header of the script (comment block at the very beginning of | ||
-- the script), each line starting with -->> are Majordome's commands. | ||
-- Consequently, '--->>' are commented out commands. | ||
-- | ||
-- Name of this script | ||
-- if not set, takes the filename | ||
-- Notez-bien : if used, this directive MUST be defined before any | ||
-- listen directive. | ||
--->> name=Toto | ||
-- | ||
-- Indicate the Timer(s) to wait for | ||
-- (more than one "when" can be present) | ||
-->> when=10s | ||
-- | ||
-- Create this rendez-vous object | ||
-->> need_namedminmax=TestNamedMinMax | ||
-- | ||
-- remove some trace | ||
-- This option is useful to avoid logging of very noisy topics | ||
--->> quiet | ||
-- | ||
-- Disable this script | ||
--->> disabled | ||
-- | ||
|
||
print "" | ||
|
||
-- Iterate against stored values | ||
for _,v in ipairs( table.pack(TestNamedMinMax:FiguresNames()) ) do | ||
|
||
print(v) | ||
print "---------" | ||
|
||
print( "Number of samples :", TestNamedMinMax:getSamplesNumber(v) ) | ||
print( "Min value :", TestNamedMinMax:getMin(v) ) | ||
print( "Max value :", TestNamedMinMax:getMax(v) ) | ||
print( "Max Average :", TestNamedMinMax:getAverage(v) ) | ||
|
||
-- Clear storage : restart a new series | ||
TestNamedMinMax:Clear(v) | ||
end |
4 changes: 4 additions & 0 deletions
4
Documentations/SamplesCode/NamedMinMax/50_TestNamedMinMax/ConsPower.topic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Retrieve electricity consumed for my home | ||
|
||
topic=TeleInfo/Consommation/values/PAPP | ||
#store |
4 changes: 4 additions & 0 deletions
4
Documentations/SamplesCode/NamedMinMax/50_TestNamedMinMax/ProdPower.topic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Retrieve power consumed | ||
|
||
topic=TeleInfo/LinkyProduction/values/SINSTI | ||
#store |
36 changes: 36 additions & 0 deletions
36
Documentations/SamplesCode/NamedMinMax/50_TestNamedMinMax/TestNamedMinMax.namedminmax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- This is an example of Tracker script | ||
-- In the header of the script (comment bloc at the very beginning of | ||
-- the script), each line starting with -->> are Majordome's commands. | ||
-- Consequently, '--->>' are commented out commands. | ||
-- | ||
-- Name of this script | ||
-- if not set, takes the filename | ||
-- Notez-bien : if used, this directive MUST be defined before any | ||
-- listen directive. | ||
--->> name=Toto | ||
-- | ||
-- remove some trace | ||
-- This option is useful to avoid logging of very noisy topics | ||
-->> quiet | ||
-- | ||
-- Disable this trigger | ||
--->> disabled | ||
-- | ||
-- Indicate MQTT topic(s) to listen to | ||
-- More than one "listen" can be present | ||
-- In such case, it's wise for this function to return different name. | ||
-->> listen=ConsPower | ||
-->> listen=ProdPower | ||
-- | ||
-->> need_topic=ConsPower | ||
-->> need_topic=ProdPower | ||
|
||
-- The function bellow has to return the name of the figure | ||
-- (or nothing if the data has to be rejected) | ||
|
||
-- Determine which data is it | ||
if MAJORDOME_TOPIC == ConsPower:getTopic() then | ||
return "Consumer" | ||
elseif MAJORDOME_TOPIC == ProdPower:getTopic() then | ||
return "Producer" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Demonstrates the usage of **MinMax** object : It will gather real-time consumed electricity and, every 10 seconds, will display some statistics about it : | ||
``` | ||
Number of samples : 7.0 | ||
Min value : 530.0 | ||
Max value : 2640.0 | ||
Max Average : 1640.0 | ||
``` | ||
|
||
--- | ||
|
||
* `ConsPower.topic` : data source | ||
* `ProdPower.topic` : data source | ||
* `TestNamedMinMax.minmax` : statistic generator for this example | ||
* `10s.timer` : Timeframe to generate statistics on | ||
* `Collector.lua` : display MinMax's statistics | ||
|
||
--- | ||
|
||
To test it, create a config file like this : | ||
|
||
# URL to reach the broker | ||
Broker_URL=tcp://torchwood.local:1883 | ||
|
||
# Application directory | ||
ApplicationDirectory=Documentations/SamplesCode/Tracker_HowMany | ||
|
||
And obviously you have to find out your own data source. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.