def task12(): print('----------------------------task12--------------------------------') ltl = 'F([email protected]=true & window_liv.curtain=true)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def task16(): print('----------------------------task16--------------------------------') ltl = '!G(!(@fitbit.sleep=true & smart_tv.power=true) | (1800#fitbit.sleep=true W @smart_tv.power=false))' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def task11(): print('----------------------------task11--------------------------------') ltl = 'F([email protected]_pop=true & echo.playing=true)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def task2(): print('----------------------------task2--------------------------------') ltl = 'F(window_liv.open=false & window_bed.open=false & window_bath.open=false)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task_set(): print('----------------------------task_set--------------------------------') ltl = '!G(!location.appear=true | hue_light.color=red)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def task4(): print('----------------------------task4--------------------------------') ltl = 'F(thermostat.thermostat>80)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task3(): print('----------------------------task3--------------------------------') ltl = 'F(oven.lock=false & location.appear=true)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task6(): print('----------------------------task6--------------------------------') ltl = 'F(60*refrigerator.door=true)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task5(): print('----------------------------task5--------------------------------') ltl = 'F(refrigerator.temperature_ctl>40)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task7(): print('----------------------------task7--------------------------------') ltl = 'F(15*faucet.water=true)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task8(): print('----------------------------task8--------------------------------') ltl = '!G(!(weather.temperature>60 & weather.temperature<80 & weather.raining=false) | window_liv.open=true)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task10(): print('----------------------------task10--------------------------------') ltl = 'F(@window_bath.curtain=false)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def task14(): print('----------------------------task14--------------------------------') ltl = 'F([email protected]=false & fitbit.sleep=true)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def task15(): print('----------------------------task15--------------------------------') ltl = 'F(10800#location.appear=true & X(@roomba.power=true))' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def fix(request): json_resp = dict() #print("进入fix函数") #pdb.set_trace(); try: req_dict = parse_fix_request(request) #print(str(request.body)) user_id_rules = req_dict['user_id_rules'] user_id_sp = req_dict['user_id_sp'] task_id = req_dict['task_id'] is_named = req_dict['is_named'] is_compact = req_dict['is_compact'] rule_list = m.Rule.objects.filter(task=task_id, owner=user_id_rules) #根据访问ID和任务ID建立连接关系 sp_list = m.SafetyProp.objects.filter(task=task_id, owner=user_id_sp) #把SP转换为LTL ltl_list = [] for sp in sp_list: ltl_list.append(translate_sp_to_autotap_ltl(sp)) #ltl_list = [translate_sp_to_autotap_ltl(sp) for sp in sp_list] if ltl_list: ltl = '!(%s)' % ' & '.join(ltl_list) else: ltl = '!(1)' #print("得到的ltl_list为" + str(ltl_list)) template_dict = generate_all_device_templates() # print("得到的template模板为" + str(template_dict)) if is_named: #print("is_named为1") tap_dict = {str(k): translate_rule_into_autotap_tap(v) for k, v in zip(range(len(rule_list)), rule_list)} # print("tap_dict为"+ tap_dict) tap_patch, tap_label = generateNamedFix(ltl, tap_dict, {}, template_dict) result_list = expand_autotap_result_into_patches_named(tap_patch, tap_label, is_compact) orig_rule_dict = {str(k): backend_to_frontend_view(v) for k, v in zip(range(len(rule_list)), rule_list)} #如何把原先的运行图生产规则 json_resp['original'] = orig_rule_dict json_resp['patches'] = result_list else: #print("is_named为0") tap_list = [translate_rule_into_autotap_tap(v) for v in rule_list] #print("拿到了tap_list") tap_patch = generateCompactFix(ltl, tap_list, {}, template_dict) #print("拿到了tap_patch" + str(tap_patch)) result_list = expand_autotap_result_into_patches_unnamed(tap_patch, is_compact) #print("拿到了result_list") orig_rule_list = [backend_to_frontend_view(v) for v in rule_list] #前端輸入的相當于是個模板 #print("orig_rule_list为" + str(orig_rule_list)) # print("result_list为" + str(result_list)) json_resp['original'] = orig_rule_list json_resp['patches'] = result_list json_resp['succeed'] = True except Exception as exc: json_resp['patches'] = [] json_resp['succeed'] = False json_resp['fail_exc'] = str(exc) return JsonResponse(json_resp)
def task4_3(): print( '----------------------------task4_3--------------------------------') ltl = '!G(!weather.temperature>79 | (!thermostat.ac=false))' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task9(): print('----------------------------task9--------------------------------') ltl = '!(G(!(location.appear=true) | thermostat.thermostat>70) & ' \ 'G(!(location.appear=true) | thermostat.thermostat<75))' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task7_2(): print( '----------------------------task7_2--------------------------------') ltl = '!G(!(@faucet.water=true) | (15#faucet.water=true W @faucet.water=false))' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task6_2(): print( '----------------------------task6_2--------------------------------') ltl = '!G(!(@refrigerator.door=true) | (120#refrigerator.door=true W @refrigerator.door=false))' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task14_2(): print( '----------------------------task14_2--------------------------------') ltl = '!G((!fitbit.sleep=true | door.lock=true) & (!door.lock=true | fitbit.sleep=true))' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def task14_4(): print( '----------------------------task14_4--------------------------------') ltl = '!G(!(location.appear=true & hue_light.power=false) | door.lock=true)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def task16_2(): print( '----------------------------task16_2--------------------------------') ltl = 'F(1800*smart_tv.power=true & fitbit.sleep=true)' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def task3_4(): print( '----------------------------task3_4--------------------------------') ltl = '!G((!location.appear=true | oven.lock=true) & (!oven.lock=true | location.appear=true))' tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def generate_text_for_single_user(code, task_id, ltl): try: user_id_rule = m.User.objects.get(code=code, mode="rules") rule_list = m.Rule.objects.filter(owner=user_id_rule, task=int(task_id)) except m.User.DoesNotExist: rule_list = list() rule_text = "" tap_list = list() for rule in rule_list: tap = translate_rule_into_autotap_tap(rule) # print(tap.__dict__) tap_list.append(tap) rule_text = rule_text + '[] IF %s WHILE %s, THEN %s<br>' % ( tap.trigger, str(tap.condition), tap.action) template_dict = generate_all_device_templates() new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}, template_dict=template_dict) new_rule_patch_text_list = [ '[] IF %s WHILE %s, THEN %s' % (patch.trigger, ' & '.join(patch.condition), str(patch.action)) for patch in new_rule_patch ] new_rule_patch_text = '<br>'.join(new_rule_patch_text_list) rule_id_list = [rule.id for rule in rule_list] action_num_list = [len(patch.action) > 0 for patch in new_rule_patch] if all(action_num_list): success_flag = True else: success_flag = False http_content = "==========user=%s, task=%s==========<br>" \ "The property being checked is %s<br> " \ "Rule IDs: %s <br> %s <br> Fixing Patch: <br>%s <br>" \ "Visit <a href=\"localhost:4200/%s/%s\">localhost:4200/%s/%s</a> " \ "to see the user-written properties/rules<br>" \ "====================================<br>" % \ ( code, str(task_id), ltl, str(rule_id_list), rule_text, new_rule_patch_text, code, task_id, code, task_id ) if not success_flag: http_content = "<font color=\"red\">failed</font>" + http_content return http_content
def task9_2(): print( '----------------------------task9_2--------------------------------') ltl1 = 'G(!location.appear=true | thermostat.thermostat=71)' ltl = '!%s' % ltl1 tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task3_6(): print( '----------------------------task3_6--------------------------------') ltl1 = 'G(!location.appear=true | oven.lock=true)' ltl2 = 'G(!location.appear=true | oven.door=true)' ltl = '!(%s & %s)' % (ltl1, ltl2) tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task16_3(): print( '----------------------------task16_3--------------------------------') ltl1 = 'G(!(@fitbit.sleep=true & smart_tv.power=true) | (1860#fitbit.sleep=true W @smart_tv.power=false))' ltl2 = '!F(1800#fitbit.sleep=true & X@smart_tv.power=false)' ltl = '!(%s & %s)' % (ltl1, ltl2) tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('------------------------------------------------------------------')
def task2_4(): print( '----------------------------task2_4--------------------------------') ltl1 = 'G((window_bath.open=false & window_bed.open=false & window_liv.open=true) | ' \ '(window_bath.open=true & window_bed.open=true & window_liv.open=false))' ltl = '!(%s)' % (ltl1) tap_list = [] new_rule_patch = generateCompactFix(ltl, tap_list, init_value_dict={}) print('\n'.join([str(patch) for patch in new_rule_patch])) print('-----------------------------------------------------------------')
def task3_1(): print( '----------------------------task3_1--------------------------------') ltl = 'F(smart_oven.openclose_door_position=true & location_sensor.kitchen_bobbie=true)' tap_list = [] 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('-----------------------------------------------------------------')
def task15_1(): print( '----------------------------task15_1--------------------------------') ltl = 'F(10800#location_sensor.home_a_family_member=true & X(@roomba.power_onoff_setting=true))' tap_list = [] 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('------------------------------------------------------------------')