def _fixPreProcessing(channel_dict, tap_dict, template_numeric_dict=None, timing_exp_list=None): """ after applying this, there is no template rule anymore, and every tap rule only causes one edge :param system: :param template_numeric_dict: :return: """ # break down templates if not template_numeric_dict: template_numeric_dict = dict() if not timing_exp_list: timing_exp_list = list() for tap_name, tap in tap_dict.items(): template_match = _triggerTemplateMatch(tap.trigger, list(template_numeric_dict.keys())) if template_match: del tap_dict[tap_name] template = template_match.group('template') operator = template_match.group('operator') value = float(template_match.group('value')) for crit_value in _getEnhancedNumericList(template_numeric_dict[template]): if (crit_value > value and operator == '>') or \ (crit_value < value and operator == '<') or (crit_value == value and operator == '='): new_tap_name = tap_name + str(crit_value).replace('.', '_') new_trigger = template + 'SetTo' + str(crit_value).replace('.', '_') tap_dict[new_tap_name] = Tap(tap.action, new_trigger, tap.condition) _channel_dict = copy.deepcopy(channel_dict) result = generateIoTSystem('TempSystem', _channel_dict, tap_dict, timing_exp_list) # break down every rule tap_index_dict = {key: 0 for key, tap in result.tap_dict.items()} new_tap_dict = dict() ts = result.transition_system for transition in ts.trans_list: if '->' in transition.act: # add a new rule handling this rule_name = re.match(r'rule\((?P<rule_name>[\s\S]+)\)->[^ ]+', transition.act).group('rule_name') prev_index = ts.getPrevIndex(transition.src_index) prev_field = ts.getField(prev_index) ap_list = [ap for ap in result.getApList(prev_field) if '@' not in ap and 'trigger' not in ap and ap not in result.tap_dict] ap_list = ap_list + ['!' + ap for ap in result.getAllAp() if '@' not in ap and 'trigger' not in ap and ap not in ap_list and ap not in result.tap_dict] new_rule_name = rule_name + '_' + str(tap_index_dict[rule_name]) action = result.tap_dict[rule_name].action trigger = result.tap_dict[rule_name].trigger tap_index_dict[rule_name] = tap_index_dict[rule_name] + 1 new_tap_dict[new_rule_name] = Tap(action, trigger, ap_list) _channel_dict = copy.deepcopy(channel_dict) result = generateIoTSystem('systemAfterPreProcess', _channel_dict, new_tap_dict, timing_exp_list) ts = result.transition_system # put system back to initial state result._restoreFromStateVector(ts.getField(0)) return result
def translate_rule_into_autotap_tap(rule): """ :param rule: :return: """ try: esrule = m.ESRule.objects.get(id=rule.id) trigger = trigger_to_clause(esrule.Etrigger, True) trigger_statement = trigger_to_autotap_statement(trigger, True) # conditions of the rule condition_list = [ trigger_to_clause(cond, False) for cond in esrule.Striggers.all() ] condition_statement_list = [ trigger_to_autotap_statement(cond, False) for cond in condition_list ] # action of the rule action = state_to_clause(esrule.action) action_statement = trigger_to_autotap_statement(action, True) return Tap(action_statement, trigger_statement, condition_statement_list) except Exception as exc: raise exc
def translate_rule_into_autotap_tap(rule): """ :param rule: :return: """ #进入翻译函数 #print("进入翻译规则函数") #pdb.settrace() try: esrule = m.ESRule.objects.get(id=rule.id) #print("esrule为" + str(esrule)) trigger = trigger_to_clause(esrule.Etrigger, True) #print("trigger为" + str(trigger)) trigger_statement = trigger_to_autotap_statement(trigger, True) #print("trigger_statement为" + str(trigger_statement)) # conditions of the rule condition_list = [ trigger_to_clause(cond, False) for cond in esrule.Striggers.all() ] condition_statement_list = [ trigger_to_autotap_statement(cond, False) for cond in condition_list ] # action of the rule action = state_to_clause(esrule.action) #condition和state轉換為clause,轉換為json格式,最後轉換為autotap格式 action_statement = trigger_to_autotap_statement(action, True) #拿到了不同的action的statement,trigger_statement,condition_statement然後進行相應的處理 return Tap(action_statement, trigger_statement, condition_statement_list) except Exception as exc: raise exc
def to_tap(self, var_resolve: dict = {}): if str(self.show_symb) in var_resolve: if var_resolve[str(self.show_symb)] or self.plain: action = '%s=%s' % (self.action.var, self.action.val) if self.trigger_e.hold_t: trigger = '%d*%s%s%s' % ( self.trigger_e.hold_t, self.trigger_e.var, self.trigger_e.comp, self.trigger_e.val) elif self.trigger_e.delay: trigger = '%d#%s%s%s' % ( self.trigger_e.delay, self.trigger_e.var, self.trigger_e.comp, self.trigger_e.val) else: trigger = '%s%s%s' % (self.trigger_e.var, self.trigger_e.comp, self.trigger_e.val) condition = [ '%s%s%s' % (cond.var, cond.comp, cond.val) for cond in self.condition ] return Tap(action=action, trigger=trigger, condition=condition) else: return None else: raise Exception( 'cannot translate symbolic rule into real tap without assignment' )
def generateCompactFix(ltl, tap_list, init_value_dict={}, template_dict=vars(DeviceList)): # stage 0: remove all duplicated taps #print("移除所有的重複tap") tap_list = list(set(tap_list)) # stage 1: find all critical value #print("tap_list為"+ str(tap_list)) crit_value_dict = generateCriticalValue(ltl, tap_list) # stage 2: find all timing expressions #print("由tap_list產生的權值詞典為" + str(crit_value_dict)) exp_t_list, record_exp_list = generateTimeExp(ltl, tap_list) # stage 3: generate channels channel_name_list, cap_name_list, tap_list = getChannelList(ltl, tap_list) # stage 4: change tap, ltl format new_tap_list = tapFormat(tap_list, crit_value_dict) new_ltl = ltlFormat(ltl) # stage 4: generate system tap_dict = { 'rule' + str(key): value for key, value in zip(range(len(new_tap_list)), new_tap_list) } channel_dict = generateChannelDict(channel_name_list, crit_value_dict, init_value_dict, cap_name_list, template_dict) #print("此時產生一個system") system = _fixPreProcessing(channel_dict=channel_dict, tap_dict=tap_dict, template_numeric_dict=crit_value_dict, timing_exp_list=exp_t_list) # stage 5: fix system = _fixRuleEdges(system, new_ltl, record_exp_list) edge_t, complete_edge_t = _fixConditionGenerator(system, new_ltl, record_exp_list, include_orig=True) template_t, other_t = _getPatternList( edge_t, template_numeric_dict=crit_value_dict) result_1 = _fixPatternEdge(template_t, complete_edge_t, crit_value_dict) result_2 = _fixRegualarEdge(other_t, complete_edge_t) # preserved_taps = [Tap(action=[tap.action], trigger=tap.trigger, condition=tap.condition) # for key, tap in system.tap_dict.items()] result = result_1 + result_2 result_taps = [ Tap(action=act, trigger=trig, condition=(cond.split(' & ') if cond else list())) for trig, cond, act in result ] # taps = preserved_taps + result_taps for tap in result_taps: tap.trigger = textToformula(tap.trigger) tap.condition = [textToformula(cond) for cond in tap.condition] tap.action = [textToformula(act) for act in tap.action] #print("拿到了result_taps") return result_taps
def generateNamedFix(ltl, tap_dict, init_value_dict={}, template_dict=vars(DeviceList)): # stage 0: remove all duplicated taps tap_dict_inv = {v: k for k, v in tap_dict.items()} tap_dict = {v: k for k, v in tap_dict_inv.items()} tap_list = [v for k, v in tap_dict.items()] # stage 1: find all critical value crit_value_dict = generateCriticalValue(ltl, tap_list) # stage 2: find all timing expressions exp_t_list, record_exp_list = generateTimeExp(ltl, tap_list) # stage 3: generate channels channel_name_list, cap_name_list, tap_list = getChannelList(ltl, tap_list) # stage 4: change tap, ltl format new_tap_dict = namedTapFormat(tap_dict, crit_value_dict) new_ltl = ltlFormat(ltl) # stage 4: generate system tap_dict = new_tap_dict channel_dict = generateChannelDict(channel_name_list, crit_value_dict, init_value_dict, cap_name_list, template_dict) system = _fixPreProcessing( channel_dict=channel_dict, tap_dict=tap_dict, template_numeric_dict=crit_value_dict, timing_exp_list=exp_t_list ) # stage 5: fix system = _fixRuleEdges(system, new_ltl, record_exp_list) edge_t, complete_edge_t = _fixConditionGenerator(system, new_ltl, record_exp_list, include_orig=True) template_t, other_t = _getPatternList(edge_t, template_numeric_dict=crit_value_dict) result_1 = _fixPatternEdge(template_t, complete_edge_t, crit_value_dict) result_2 = _fixRegualarEdge(other_t, complete_edge_t) result = result_1 + result_2 result_taps = [Tap(action=act, trigger=trig, condition=(cond.split(' & ') if cond else list())) for trig, cond, act in result] # should be a mark phase marking the pre-existing rules result_tap_label = ['*'] * len(result_taps) for o_tap_name, o_tap in tap_dict.items(): index = 0 for tap_index, tap in zip(range(len(result_taps)), result_taps): if result_tap_label[tap_index] == '*' and o_tap.trigger == tap.trigger and [o_tap.action] == tap.action: result_tap_label[tap_index] = '%s.%d' % (o_tap_name, index) index = index + 1 for tap in result_taps: tap.trigger = textToformula(tap.trigger) tap.condition = [textToformula(cond) for cond in tap.condition] tap.action = [textToformula(act) for act in tap.action] new_index = 0 for ri in range(len(result_tap_label)): if result_tap_label[ri] == '*': result_tap_label[ri] = '*.%d' % new_index new_index = new_index + 1 return result_taps, result_tap_label
def expand_autotap_result_into_patches_named(patch_list, label_list, is_compact=False): if not is_compact: action_list = [tap.action for tap in patch_list] result_list = list() for selected_action in itertools.product(*action_list): patch = {k: tap_to_frontend_view(Tap(action=[s_a], condition=tap.condition, trigger=tap.trigger)) for k, s_a, tap in zip(label_list, selected_action, patch_list)} result_list.append(patch) else: result_list = {k: tap_to_frontend_view(tap) for k, tap in zip(label_list, patch_list)} return result_list
def _fixActionRule(rule_name, bad_edge_list, safe_state_list, system, only_print=False): """ fix a bad edge caused by rule action :param rule_name: the rule to be fixed :param bad_edge_list: all bad edges :param safe_state_list: list of fields of safe states :param system: the IoTSystem :return: [[patches], [patches], ...], each 'patches' represents a possible fix """ ts = system.transition_system bad_edge_src_field_list = [edge.src_field for edge in bad_edge_list] rule = system.tap_dict[rule_name] trigger = rule.trigger action = rule.action result_patch_list = list() result_patch_list.append(Patch('delete', rule_name)) for trans in ts.trans_list: dst_field = ts.state_list[trans.dst_index].field src_field = ts.state_list[trans.src_index].field if trans.act == trigger and system.isTapTriggered(dst_field, rule_name): # this is an edge that will trigger the tap rule if dst_field not in bad_edge_src_field_list and dst_field in safe_state_list: # need to keep this condition label = system.getLabel(src_field) ap_list = [ap if label[index] else '!' + ap for index, ap in enumerate(ts.ap_list) if '.' in ap] hitting_set_list = list() for t in ts.trans_list: t_src_field = ts.state_list[t.src_index].field t_dst_field = ts.state_list[t.dst_index].field if t.act == trigger and t_src_field != src_field and t_dst_field in safe_state_list: l = system.getLabel(t_src_field) conflict_ap_list = ['!'+ap if l[index] else ap for index, ap in enumerate(ts.ap_list) if '.' in ap] hitting_set_list.append(conflict_ap_list) # print('ap_list = %s' % ap_list) # print('hitting_set = %s' % str(hitting_set_list)) condition = hittingSet(ap_list, hitting_set_list) result_patch_list.append(Patch('add', '', Tap(action, trigger, condition))) if only_print: print('--- Fix rule edge ---') for patch in result_patch_list: print(patch.log()) print('--- End ---') else: return [result_patch_list]
def _fixEventEdge(edge, system, only_print=False): """ fix a bad edge caused by external event :param edge: the bad edge :param system: the IoTSystem :return: [[patches], [patches], ...], each 'patches' represents a possible fix """ ts = system.transition_system # First: find all possible actions action_list = list() for action, dst_field in system.getAction(edge.dst_field, False): # after the external event, what action can be triggered? dst_label = system.getLabel(dst_field) ap_dict = dict() for ap, value in zip(ts.ap_list, dst_label): ap_dict[ap] = value if not calculateBoolean(edge.ltl_req, ap_dict): # is good for redirecting, doesn't violate ltl by entering accepting cluster action_list.append(action) # Second: get the correct trigger action trigger = edge.action # Third: find minimum condition that only cover the source state of the edge using hitting set src_label = ts.label_list[edge.src_index_ts] src_ap_list = [(ap if src_label[index] else '!' + ap) for index, ap in enumerate(ts.ap_list) if '.' in ap] hitting_set_list = list() for trans in ts.trans_list: if trans.act == edge.action and ts.state_list[ trans.src_index].field != edge.src_field: label = system.getLabel(ts.state_list[trans.src_index].field) conflict_ap_list = [ '!' + ap if label[index] else ap for index, ap in enumerate(ts.ap_list) if '.' in ap ] hitting_set_list.append(conflict_ap_list) condition = hittingSet(src_ap_list, hitting_set_list) if only_print: print('trigger: %s, condition: %s' % (trigger, str(condition))) else: # return all possible patches result = list() for action in action_list: new_tap = Tap(action, trigger, condition) result.append([Patch('add', '', new_tap)]) return result
def modify_patch_to_taps(orig_taps, modify_patch): index = modify_patch['index'] new_cond = modify_patch['new_condition'] new_taps = [] for ii in range(len(orig_taps)): orig_tap = orig_taps[ii] if ii == index: new_conditions = orig_tap.condition + [new_cond] tap = Tap(action=orig_tap.action, trigger=orig_tap.trigger, condition=new_conditions) else: tap = orig_tap new_taps.append(tap) return new_taps
def testall(): print('----------------------------task16--------------------------------') ltl = '!(!F(bedroom_window.openclose_window_position=true & weather_sensor.is_it_raining_condition=true))' tap_dict = { '0': Tap(action='bedroom_window.openclose_window_position=false', condition=[], trigger='weather_sensor.is_it_raining_condition=true') } new_patch, label = generateNamedFix(ltl, tap_dict, init_value_dict={}, template_dict=template_dict) for patch, label in zip(new_patch, label): print(label, printTap(patch)) print('------------------------------------------------------------------')
def namedTapFormat(tap_dict, critical_value_dict): def isfloat(s): try: float(s) return True except ValueError: return False new_tap_dict = dict() re_splitter = r'(\s+|\(|\)|\&|\||!|<|>|=|F|G|U|W|\#|\*|X|@)' ops = { '!': Operator('!', 1, 4, 1), '&': Operator('&', 2, 2, 0), '|': Operator('|', 2, 2, 0), '<': Operator('<', 2, 6, 0), '>': Operator('>', 2, 6, 0), '=': Operator('=', 2, 6, 0), 'G': Operator('G', 1, 3, 1), 'F': Operator('F', 1, 3, 1), 'U': Operator('U', 2, 3, 0), 'X': Operator('X', 1, 3, 1), 'W': Operator('W', 2, 3, 0), '#': Operator('#', 2, 5, 0), '*': Operator('*', 2, 5, 0), '@': Operator('@', 1, 5, 1) } for tap_name, tap in tap_dict.items(): new_trigger = list() if not re.match(r'^tick\[(?P<time_exp>[()\w<>=#*.]+)\]$', tap.trigger): trigger_post_exp = parse(tap.trigger, ops, re_splitter) if trigger_post_exp[-1] == '<': value = int(trigger_post_exp[-2]) crit_list = critical_value_dict[trigger_post_exp[-3]] left_list = crit_list[:-1] right_list = crit_list[1:] mid_list = [(v1 + v2) / 2 for v1, v2 in zip(left_list, right_list)] enhanced_list = crit_list + mid_list + [ min(crit_list) - 1, max(crit_list) + 1 ] sat_list = [v for v in enhanced_list if v < value] for sat_val in sat_list: new_trigger.append(trigger_post_exp[-3] + 'SetTo' + str(sat_val).replace('.', '_')) elif trigger_post_exp[-1] == '>': value = int(trigger_post_exp[-2]) crit_list = critical_value_dict[trigger_post_exp[-3]] left_list = crit_list[:-1] right_list = crit_list[1:] mid_list = [(v1 + v2) / 2 for v1, v2 in zip(left_list, right_list)] enhanced_list = crit_list + mid_list + [ min(crit_list) - 1, max(crit_list) + 1 ] sat_list = [v for v in enhanced_list if v > value] for sat_val in sat_list: new_trigger.append(trigger_post_exp[-3] + 'SetTo' + str(sat_val).replace('.', '_')) elif trigger_post_exp[-1] == '=': if not isfloat(trigger_post_exp[-2]): new_trigger.append(trigger_post_exp[-3] + 'Set' + trigger_post_exp[-2].capitalize()) else: new_trigger.append(trigger_post_exp[-3] + 'SetTo' + trigger_post_exp[-2].replace('.', '_')) else: new_trigger.append(tap.trigger) condition = list() for cond in tap.condition: if '#' in cond or '*' in cond: condition.append(cond) else: cond_post_exp = parse(cond, ops, re_splitter) if cond_post_exp[-1] == '=': if cond_post_exp[-2] == 'true': condition.append(cond_post_exp[-3] + 'IsTrue') elif cond_post_exp[-2] == 'false': condition.append('!' + cond_post_exp[-3] + 'IsTrue') elif isfloat(cond_post_exp[-2]): condition.append('!' + cond_post_exp[-3] + 'GreaterThan' + cond_post_exp[-2].replace('.', '_')) condition.append('!' + cond_post_exp[-3] + 'LessThan' + cond_post_exp[-2].replace('.', '_')) else: # should be 'set' condition.append(cond_post_exp[-3] + 'Is' + cond_post_exp[2].capitalize()) elif cond_post_exp[-1] == '<': condition.append(cond_post_exp[-3] + 'LessThan' + cond_post_exp[-2].replace('.', '_')) elif cond_post_exp[-1] == '>': condition.append(cond_post_exp[-3] + 'GreaterThan' + cond_post_exp[-2].replace('.', '_')) act_post_exp = parse(tap.action, ops, re_splitter) if not isfloat(act_post_exp[-2]): action = act_post_exp[-3] + 'Set' + act_post_exp[-2].capitalize() else: action = act_post_exp[-3] + 'SetTo' + act_post_exp[-2].replace( '.', '_') for trigger, new_tap_index in zip(new_trigger, range(len(new_trigger))): new_tap_dict['%s.%d' % (tap_name, new_tap_index)] = Tap( action, trigger, condition) return new_tap_dict
from autotapta.analyze.DecisionTree import traceToTree import datetime import json def inputFromJson(filename: str): with open(filename, 'r') as fp: dct = json.load(fp) return dct['trace'], dct['template_dict'], dct['boolean_map'] filename = 'data/trace-rob-0817.json' trace_raw, template_dict, boolean_map = inputFromJson(filename) tap_list = [ Tap(action='table_lamp.power_onoff_setting=true', condition=[], trigger='multipurpose_sensor.contact_sensor_contact=true'), Tap(action='table_lamp.power_onoff_setting=false', condition=[], trigger='multipurpose_sensor.contact_sensor_contact=false') ] trace = inputTraceFromList(trace_raw, trunc_none=True, template_dict=template_dict, boolean_map=boolean_map, only_sensor=True) for action, is_ext in zip(trace.actions, trace.is_ext_list): if not is_ext or 'table_lamp' in action[1]: print(is_ext, action)
for cap, typ in template_dict[channel].items(): if typ.startswith('bool'): cap_dict[channel + '.' + cap] = (PoiisonGenerator(3600), BooleanGenerator()) elif typ.startswith('numeric'): cap_dict[channel + '.' + cap] = (PoiisonGenerator(1000), RandomWalkValueGenerator( step=5, target=50)) else: opt_list = typ.split('[')[-1][:-1].split(', ') cap_dict[channel + '.' + cap] = (PoiisonGenerator(3600), SetGenerator(opt_list=opt_list)) tap_dict = { 'rule1': Tap(action='smart_oven.lockunlock_setting=true', trigger='smart_oven.lockunlock_setting=false', condition=['location_sensor.kitchen_bobbie=true']), 'rule2': Tap(action='smart_oven.lockunlock_setting=true', trigger='location_sensor.kitchen_bobbie=true', condition=['smart_oven.lockunlock_setting=false']) } trace = generateTraceEnhanced(cap_dict, tap_dict, length=10000, template_dict=template_dict) print(trace) # trace = truncateTraceByLastAction(trace, 'smart_oven.lockunlock_settingSetTrue')
def to_tap(self, var_resolve: dict = None): if var_resolve is None: var_resolve = dict() if str(self.show_symb) in var_resolve and var_resolve[str( self.show_symb)]: # showing the rule trigger = None comp_dict = { 'eq': '=', 'neq': '!=', 'gt': '>', 'lt': '<', 'geq': '>=', 'leq': '<=' } # resolving the trigger for trig_show, trig_cap, trig_comp, trig_val, trig_typ in zip( self.trig_show_list, self.trig_cap_list, self.trig_comp_list, self.trig_val_list, self.trig_cap_typ_list): if str(trig_show) in var_resolve and var_resolve[str( trig_show)]: # this is the trigger to be selected val = str(var_resolve[str(trig_val)]).lower() if trig_typ == 'bool' \ else str(var_resolve[str(trig_val)]) comp = comp_dict[str(var_resolve[str( trig_comp)])] if trig_typ == 'numeric' else '=' trigger = trig_cap + comp + val break else: for timing_trig_show, timing_trig_cap_t, timing_trig_comp, timing_trig_val, timing_trig_typ in \ zip(self.timing_trig_show_list, self.timing_cap_list, self.timing_trig_comp_list, self.timing_trig_val_list, self.timing_cap_typ_list): timing_trig_cap, timing_trig_time = timing_trig_cap_t if str(timing_trig_show) in var_resolve and var_resolve[ str(timing_trig_show)]: # this is the trigger to be selected val = str(var_resolve[str(timing_trig_val)]).lower() if timing_trig_typ == 'bool' \ else str(var_resolve[str(timing_trig_val)]) comp = comp_dict[str(var_resolve[str(timing_trig_comp)])] \ if timing_trig_typ == 'numeric' else '=' trigger = str(timing_trig_time ) + '*' + timing_trig_cap + comp + val break else: if str(self.clock_trig_show ) in var_resolve and var_resolve[str( self.clock_trig_show)]: # the clock trigger is chosen clock_trig_val = int(var_resolve[str( self.clock_trig_val)].as_long()) trigger = 'clock.clock_time=%d' % clock_trig_val else: raise Exception( 'rule is shown but no trigger is selected') # resolving the condition condition = list() for ap_show, ap_cap, ap_comp, ap_val, ap_typ in zip( self.ap_show_list, self.ap_cap_list, self.ap_comp_list, self.ap_val_list, self.ap_cap_typ_list): if str(ap_show) in var_resolve and var_resolve[str(ap_show)]: # this ap is selected val = str(var_resolve[str(ap_val)]).lower( ) if ap_typ == 'bool' else str(var_resolve[str(ap_val)]) comp = comp_dict[str(var_resolve[str(ap_comp)])] condition.append(ap_cap + comp + val) # resolving the action action_val = str(self.action.val).lower( ) if self.action_cap_typ == 'bool' else str(self.action.val) action = self.action.var + self.action.comp + action_val return Tap(trigger=trigger, condition=condition, action=action) else: # not showing the rule return None
def __init__(self, _type='add', tap_name='', tap=Tap()): self.type = _type self.tap_name = tap_name self.tap = tap
from autotapmc.analyze.Fix import generateCompactFix from autotapmc.channels.template.DbTemplate import template_dict from autotapmc.model.Tap import Tap # print('----------------------------scenario1--------------------------------') # ltl1 = '!F(living_room_window.openclose_window_position=false & ' \ # 'bathroom_window.openclose_window_position=false & ' \ # 'bedroom_window.openclose_window_position=false)' # ltl = '!(%s)' % (ltl1) # tap_list = [Tap(action='living_room_window.openclose_window_position=true', # condition=['weather_sensor.is_it_raining_condition=false'], # trigger='weather_sensor.weather_sensor_weather=Clear')] # new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}, template_dict=template_dict) # print('\n'.join([str(patch) for patch in new_rule_patch])) # print('---------------------------------------------------------------------') print('----------------------------scenario1--------------------------------') ltl1 = '1' ltl = '!(%s)' % (ltl1) tap_list = [Tap(action='smart_refrigerator.openclose_door_position=true', condition=['!120#smart_refrigerator.openclose_door_position=true'], trigger='location_sensor.kitchen_alice=false')] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}, template_dict=template_dict) print('\n'.join([str(patch) for patch in new_rule_patch])) print('---------------------------------------------------------------------')
filename = 'data/trace-pedro.json' trace_raw, template_dict, boolean_map = inputFromJson(filename) trace = inputTraceFromList(trace_raw, trunc_none=True, template_dict=template_dict, boolean_map=boolean_map) trace = enhanceTraceWithTiming( trace, [('aeotec_multisensor_6.detect_motion_status', 60)]) tap = Tap(trigger='60#aeotec_multisensor_6.detect_motion_status=false', condition=[ 'aeotec_multisensor_6.detect_motion_status=false', 'multipurpose_sensor.acceleration_sensor_acceleration=false', 'aeotec_multisensor_6.illuminance_measurement_illuminance<72', 'wifi_smart_plug__kettle.power_meter_power>-1' ], action='hue_color_lamp_1.power_onoff_setting=false') target_action = tap.action episode_list = extractEpisodes(trace, target_action, pre_time_span=datetime.timedelta(minutes=5), post_time_span=datetime.timedelta(minutes=5)) for episode in episode_list: start_time = episode.actions[0][0] trigger_time_list = calcTriggerTime(tap, episode) trigger_time_dct_list = [{