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