Skip to content
Snippets Groups Projects
Commit c73dca51 authored by Manuel Krombholz's avatar Manuel Krombholz
Browse files

Added event processing frequency for groups

parent d7a43929
No related branches found
No related tags found
2 merge requests!12Resolve "Cleanup parser",!11Resolve "Add processing frequency option for items"
Pipeline #9597 passed
......@@ -302,12 +302,20 @@ aspect ItemHandling {
logger.catching(e);
}
}
if (hasItemObserver() && this.getStateData().checkStateProcessingTime()) {
if (hasItemObserver() && this.getStateData().checkStateProcessingTime(getRelevantItemPerformance())) {
this.getStateData().afterStateChangeProcessed();
getItemObserver().apply();
}
}
protected ItemPerformance Item.getRelevantItemPerformance() {
ASTNode parent = getParent();
if (this.getItemPerformance()==null && parent instanceof Group) {
return ((Group)parent).getItemPerformance();
}
return this.getItemPerformance();
}
//--- sendState ---
protected void Item.sendState() throws Exception {
for (MachineLearningModel model : getRelevantInMachineLearningModels()) {
......
......@@ -3,11 +3,11 @@ aspect StateData {
this.setLastChangeDate(Instant.now());
}
public boolean StateData.checkStateProcessingTime() {
if (this.getItemPerformance()==null) {
public boolean StateData.checkStateProcessingTime(ItemPerformance itemPerformance) {
if (itemPerformance==null) {
return true;
}
double frequency = this.getItemPerformance().getEventProcessingFrequency();
double frequency = itemPerformance.getEventProcessingFrequency();
Instant lastStateChange = this.getLastChangeDate();
if (lastStateChange==null) {
return true;
......@@ -16,4 +16,5 @@ aspect StateData {
return lastStateChange.toEpochMilli() + (1/frequency)*1000 < Instant.now().toEpochMilli();
}
}
\ No newline at end of file
......@@ -153,6 +153,7 @@ Group group_body =
| AGGREGATION EQUALS TEXT.n group_body.g {: return eph.setSimpleAggregationFunction(g, n); :}
| AGGREGATION EQUALS TEXT.n round_string_list.params group_body.g
{: return eph.setParameterizedAggregationFunction(g, n, params); :}
| PERFORMANCE EQUALS TEXT.n group_body.g {: return eph.setPerformance(g, n); :}
| {: return new Group(); :}
;
......
......@@ -24,8 +24,10 @@ rel Channel.LinkedItem* <-> Item.Channel? ;
Parameter : DescribableModelElement ::= <Type:ParameterValueType> [DefaultValue:ParameterDefaultValue] <Context:String> <Required:boolean> ;
ParameterDefaultValue ::= <Value:String> ;
abstract PerformanceElement : LabelledModelElement ;
rel PerformanceElement.ItemPerformance -> ItemPerformance ;
abstract Item : LabelledModelElement ::= <_fetched_data:boolean> MetaData:ItemMetaData* [ItemObserver] /StateData/;
abstract Item : PerformanceElement ::= <_fetched_data:boolean> MetaData:ItemMetaData* [ItemObserver] /StateData/;
rel Item.Category? -> ItemCategory ;
......@@ -51,9 +53,9 @@ ItemMetaData ::= <Key:String> <Value:String> ;
ItemCategory ::= <Name:String> ;
StateData ::= <LastChangeDate:Instant> ;
rel StateData.ItemPerformance -> ItemPerformance ;
Group : LabelledModelElement ::= Group* Item* [AggregationFunction:GroupAggregationFunction] ;
Group : PerformanceElement ::= Group* Item* [AggregationFunction:GroupAggregationFunction] ;
abstract GroupAggregationFunction ;
SimpleGroupAggregationFunction : GroupAggregationFunction ::= <FunctionName:SimpleGroupAggregationFunctionName> ;
ParameterizedGroupAggregationFunction : GroupAggregationFunction ::= <FunctionName:ParameterizedGroupAggregationFunctionName>
......
......@@ -38,7 +38,7 @@ public class EraserParserHelper {
private Map<Item, Iterable<String>> missingControllingListMap = new HashMap<>();
private Map<Group, Iterable<String>> missingSubGroupListMap = new HashMap<>();
private Map<Group, Iterable<String>> missingItemListMap = new HashMap<>();
private Map<Item, String> missingItemPerformanceMap = new HashMap<>();
private Map<PerformanceElement, String> missingItemPerformanceMap = new HashMap<>();
private Map<ThingType, Iterable<String>> missingChannelTypeListMap = new HashMap<>();
private Map<ThingType, Iterable<String>> missingParameterListMap = new HashMap<>();
......@@ -115,8 +115,8 @@ public class EraserParserHelper {
group.addItem(item);
}
private void setPerformanceOnItem(Item item, ItemPerformance itemPerformance) {
item.getStateData().setItemPerformance(itemPerformance);
private void setPerformanceOnItem(PerformanceElement performanceElement, ItemPerformance itemPerformance) {
performanceElement.setItemPerformance(itemPerformance);
}
private void fillUnused() {
......@@ -301,11 +301,13 @@ public class EraserParserHelper {
return item;
}
public Item setPerformance(Item item, String performanceName) {
missingItemPerformanceMap.put(item, performanceName);
return item;
public PerformanceElement setPerformance(PerformanceElement performanceElement, String performanceName) {
missingItemPerformanceMap.put(performanceElement, performanceName);
return performanceElement;
}
public Item setMetaData(Item item, StringKeyMap metaData) {
for (AbstractMap.SimpleEntry<String, String> entry : metaData) {
item.addMetaData(new ItemMetaData(entry.getKey(), entry.getValue()));
......
......@@ -246,10 +246,6 @@ public class RulesTest {
assertEquals(2, counter.get(item), "Change of item to 7 should not trigger the rule, check2 violated");
}
private static void addItemToModel(SmartHomeEntityModel model, Item item) {
getDefaultGroup(model).addItem(item);
}
@Test
public void testTwoActions() {
......@@ -676,7 +672,7 @@ public class RulesTest {
ItemPerformance itemPerformance = new ItemPerformance();
itemPerformance.setEventProcessingFrequency(10);
numberItem.getStateData().setItemPerformance(itemPerformance);
numberItem.setItemPerformance(itemPerformance);
Rule rule = new Rule();
CountingAction counter = new CountingAction();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment