Exemplo n.º 1
0
def op_add_property_from_file():
    file = request.files['property_file']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
        file.save(filepath)
        property_list = Xutils.get_res_list_from_property_json(filepath)
        for res in property_list:
            client.add_res(*res)
            all_res.append(res[0])
            show_property.append({"label": res[0].encode()})
    return redirect(url_for('view_environment_list'))
Exemplo n.º 2
0
def op_add_software_from_file():
    global show_software
    file = request.files['software_file']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
        file.save(filepath)
        with open(filepath, "r") as fin:
            context = fin.read()
            client.add_res("room:software_model", {"initial": context}, None)
            software_data = json.load(open(filepath))["software"]["feature"]
            show_software = get_show_software(software_data)
            print show_software
    return redirect(url_for('view_environment_list'))
Exemplo n.º 3
0
def add_res(relist):
    for key in relist.keys():

        t = type(relist[key])
        if t is str:
            mo = {}
            mo["type"] = "string"
            mo["initial"] = relist[key]

        else:
            mo = {}
            mo["type"] = "number"
            mo["initial"] = relist[key]

        client.add_res(str(key), mo, None)
Exemplo n.º 4
0
def op_add_goal_from_file():
    global goal_data, show_goal
    file = request.files['goal_file']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
        file.save(filepath)
        with open(filepath, "r") as fin:
            goal_context = fin.read()
            client.add_res("room:goal_model", {"initial": goal_context}, None)
            goal_data = json.load(open(filepath))
            get_goal_list(goal_data)
            show_goal = get_show_goal(goal_data)

    return redirect(url_for('view_environment_list'))
Exemplo n.º 5
0
def op_add_res_from_file():
    file = request.files['res_file']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
        file.save(filepath)
        global file_path
        file_path['res_file'] = filepath
        res_list = Xutils.get_res_list_from_environment_json(filepath)
        for res in res_list:
            print res
            client.add_res(*res)
            all_res.append(res[0])
            show_environment.append({"label": res[0].encode()})
        print client.get_all_res_value(all_res, -1)
    return redirect(url_for('view_environment_list'))
Exemplo n.º 6
0
def op_set_environment():
    global res_list,goal_list,res_rule_id
    environment_name = request.form.get("environment_name",'default')
    cur = g.db.execute('select name, format, initial, delay, next, rule from entries where environment = (?) order by id desc', [environment_name])
    setting_res = [row for row in cur.fetchall()]
    for n, f, i, d, ni, r in setting_res:
        i = json.loads(i)
        model = {"format":f, "initial":i}
        update = {"delay":d, "next":ni, "rule":json.JSONDecoder().decode(r)}
        print "===========",n,model,update
        client.add_res(n,model,{'Default': utils.warp_update(update)})
        res_list.append(n)

    goal_list = filter(lambda x : 'goal' in x, res_list)
    for res in res_list:
        if 'rule_id' in res:
            res_rule_id = res
    return redirect(url_for('view_agent_choose'))
Exemplo n.º 7
0
def op_set_environment():
    global res_list,goal_list,res_rule_id
    environment_name = request.form.get("environment_name",'default')
    cur = g.db.execute('select name, format, initial, delay, next, rule from entries where environment = (?) order by id desc', [environment_name])
    setting_res = [row for row in cur.fetchall()]
    for n, f, i, d, ni, r in setting_res:
        i = json.loads(i)
        model = {"format":f, "initial":i}
        update = {"delay":d, "next":ni, "rule":json.JSONDecoder().decode(r)}
        print "===========",n,model,update
        client.add_res(n,model,{'Default': utils.warp_update(update)})
        res_list.append(n)

    goal_list = filter(lambda x : 'goal' in x, res_list)
    for res in res_list:
        if 'rule_id' in res:
            res_rule_id = res
    return redirect(url_for('view_agent_choose'))
Exemplo n.º 8
0
def use_config():
    #print "reach use_config"
    #print request.args
    res_file_path = UPLOAD_FOLDER + '/' + request.args.get('res_file')
    property_file_path = UPLOAD_FOLDER + '/' + request.args.get(
        'property_file')
    goal_file_path = UPLOAD_FOLDER + '/' + request.args.get('goal_file')
    software_file_path = UPLOAD_FOLDER + '/' + request.args.get(
        'software_file')

    res_list = Xutils.get_res_list_from_environment_json(res_file_path)
    for res in res_list:
        print res
        client.add_res(*res)
        all_res.append(res[0])
        #show_environment.append({"label": res[0].encode()})
    print client.get_all_res_value(all_res, -1)

    property_list = Xutils.get_res_list_from_property_json(property_file_path)
    for res in property_list:
        client.add_res(*res)
        all_property.append(res[0])
        #show_property.append({"label": res[0].encode()})

    with open(goal_file_path, "r") as fin:
        goal_context = fin.read()
        client.add_res("room:goal_model", {"initial": goal_context}, None)
        goal_data = json.load(open(goal_file_path))
        get_goal_list(goal_data)
        show_goal = get_show_goal(goal_data)

    with open(software_file_path, "r") as fin:
        context = fin.read()
        client.add_res("room:software_model", {"initial": context}, None)
        software_data = json.load(
            open(software_file_path))["software"]["feature"]
        # add
        # print software_data
        show_software = get_show_software(software_data)
        get_software_list(show_software)
    return "ok"
Exemplo n.º 9
0
from ResPool import client, res_manager, utils

client.reset_res_pool()
sen = "sensor"
client.add_res(sen, {"format": "number", 'initial': 20}, None)
print '----', client.get_res_value(sen), '-----'