Example #1
0
File: views.py Project: gagon/dino
def savestate_loaded():
    loaded_data = request.json  # get data loaded in load state page
    session_json = utils.get_session_json()  # read session data
    session_json = utils.save_loaded2session(
        session_json, loaded_data)  # populate session with loaded data
    utils.save_session_json(session_json)  # save data to file

    return "None"
Example #2
0
File: views.py Project: gagon/dino
def savestate_results():
    fwhp_results = request.json  # remember fwhp data from results page passed from AJAX call
    session_json = utils.get_session_json()
    for well, s in fwhp_results["wells"].items(
    ):  # loop through fwhp data from results page
        session_json["well_data"][well]["target_fwhp"] = s[
            "fwhp"]  # overwrite existing session state fwhps with data from results page
        utils.save_session_json(session_json)
        # Note: no need to check if session state exists because precondition to go to results page is to have state initialized
    return "None"
Example #3
0
File: views.py Project: gagon/dino
def results():

    session_json = utils.get_session_json()

    if not "well_data" in session_json:  # check if state was exists. well_data ~ state
        return "NO session well state. Go back to <b>Setup</b> and save state"

    # get well results from GAP
    #------------------------------------------------------------------------------

    # get results from GAP or mockup excel
    if MOCKUP:
        session_json["well_data"] = nsgr.get_all_well_data(session_json)
    else:
        session_json["well_data"] = ggr.get_all_well_data(session_json)
    #------------------------------------------------------------------------------

    # group wells by unit for html page
    session_json = utils.make_well_data_by_unit(session_json)

    # calculate totals by field/unit/rms
    session_json["totals"] = rs.calculate_totals(
        session_json["well_data_byunit"])

    # field balance calculation
    session_json["fb_data"] = fb.calculate(session_json)

    # this is done so that routings/sep pres dont get updated as cant be done on results page
    session_json["state"] = 0

    # save results to json
    utils.save_session_json(session_json)

    # merge data to present if ref case exists
    data, merge_done = rs.merge_ref(session_json)

    page_active = {
        "load_pcs": "",
        "load_state": "",
        "load_streams": "",
        "setup": "",
        "live": "",
        "results": "active"
    }

    return render_template('results.html',
                           data=data,
                           page_active=page_active,
                           merge_done=merge_done)
Example #4
0
File: views.py Project: gagon/dino
def load_pcs():
    print('start loading PCs')
    well_pcs = xl_setup.read_pcs()
    emit('load_progress',
         {"data": "Well PCs read from Deliverability complete"})

    print('saving PCs to session')
    session_json = utils.get_session_json()
    session_json["well_pcs"] = well_pcs
    utils.save_session_json(session_json)

    print('loading PCs to GAP')
    if MOCKUP:
        pcs2ns.load_pcs2ns(well_pcs)
    else:
        pcs2gap.load_pcs2gap(well_pcs)

    emit('load_progress', {"data": "Finished PCs loading!"})

    return "None"
Example #5
0
def route_optimization(session_json,ro_data,filters,mockup):

    # combinations=generate_comb(session_json)
    combinations=generate_comb2(ro_data)
    combinations=filter_combs(combinations,filters,session_json)
    # print(len(combinations))
    # for cnt,comb in enumerate(combinations):
    #     print(comb)
    # return None
    utils.save_orig_session_json(session_json)

    # session_json_copy=session_json
    # return None
    if not mockup:
        PE_server=ut.PE.Initialize()
    else:
        PE_server="None"

    # ut.showinterface(PE_server,0)
    start=datetime.datetime.now()

    best_res={
        "tot_qoil":0.0,
        "tot_qgas":0.0,
        "tot_qwat":0.0
    }
    best_comb=[]

    for cnt,comb in enumerate(combinations):

        iter_start=datetime.datetime.now()

        best=0
        print("iter:",cnt)
        emit("route_table",{"comb":comb,"comb_cnt":cnt+1,"comb_tot":len(combinations)}) # update table highlights according to routes applied
        sleep(0.1)

        res=solve_comb(session_json,comb,mockup,PE_server)

        iter_dt=datetime.datetime.now()-iter_start


        if res["tot_qoil"]>best_res["tot_qoil"]:
            best=1
            best_res=res
            best_comb=comb
            utils.save_best_session_json(session_json)

        comb_str='|'.join([c["well"]+":"+c["route_name"] for c in comb])
        # print([c["well"]+":"+c["route_name"] for c in comb])

        emit("progress",{
                "data":"Calculations complete. Switching to next State... <br> Time spent: %s" % iter_dt,
                "finish":2,
                "res":res,
                "state_id":cnt+1,
                "time":str(iter_dt).split('.')[0],
                "best":best,
                "comb":comb_str
            })





    session_json=utils.get_best_session_json()
    utils.save_session_json(session_json)
    emit("progress",{"data":"Applied best routing to current state"})

    if not best_comb==comb: # resolve combination if best is not equal to current combination
        emit("progress",{"data":"Resolving best combination.."})
        emit("route_table",{"comb":best_comb,"comb_cnt":-1,"comb_tot":len(combinations)}) # update table highlights according to routes applied
        res=solve_comb(session_json,best_comb,mockup,PE_server)

    if not mockup:
        PE_server=ut.PE.Stop()

    dt=datetime.datetime.now()-start
    dt=str(dt).split('.')[0]
    emit("progress",{"data":"Route optimization complete. <br>Time spent: %s" % dt,"finish":1,"best_comb":best_comb})
    sleep(0.1)

    return "None"
Example #6
0
File: views.py Project: gagon/dino
def save_afs():
    session_json = utils.get_session_json()  # read session data
    session_json = utils.save_afs2session(request.json, session_json)
    utils.save_session_json(session_json)
    return jsonify({'data': "Saved AFs successfully!"})
Example #7
0
File: views.py Project: gagon/dino
def savestate():
    session_json = utils.calc_target_fwhps(request.json)
    utils.save_session_json(session_json)
    return jsonify(
        {'data': "Saved State successfully!\nReload Page to update tables"})
Example #8
0
File: views.py Project: gagon/dino
def setup():

    session_json = utils.get_session_json(
    )  # read from json file all necessary app data

    if not "well_data" in session_json:  # create a well_data if does not exist, this normally happens very first time user logs in.
        session_json["well_data"] = {}
        # populate well data with wells from GAP
        if MOCKUP:
            session_json["well_data"] = nsst.get_gap_wells()
        else:
            print("add GAP openserver")
            session_json["well_data"] = st.get_gap_wells()
        print(session_json["well_data"])

    # get well connections from "well_connections.xlsm" file
    session_json["well_data"] = xl_setup.read_conns(session_json["well_data"])

    # get MAPs from "Deliverability.xlsx" file
    session_json["well_data"] = xl_setup.read_maps(session_json["well_data"])

    #------------------------------------------------------------------------------
    if MOCKUP:
        if session_json[
                "state"] == 1:  # check if state has been saved by the user (1)
            nsst.set_unit_routes(
                session_json["well_data"])  # set well routes as per state
            nsst.set_sep_pres(
                session_json["fb_data"]
                ["unit_data"])  # set separator pressure as per state

        session_json["well_data"] = nsst.get_all_well_data(
            session_json["well_data"], None, 1)
        session_json["unit_data"] = nsst.get_sep_pres(
            session_json["unit_data"])
    else:
        if session_json[
                "state"] == 1:  # check if state has been saved by the user (1)
            st.set_unit_routes(session_json["well_data"], None,
                               1)  # set well routes as per state
            st.set_sep_pres(
                session_json["fb_data"]
                ["unit_data"])  # set separator pressure as per state

        session_json["well_data"] = st.get_all_well_data(
            session_json["well_data"], None,
            1)  # get well data from GAP such as GOR, limits and current routes
        session_json["fb_data"]["unit_data"] = st.get_sep_pres(
            session_json["fb_data"]
            ["unit_data"])  # get separator pressure if state doesn't exist
    #------------------------------------------------------------------------------

    # group wells by unit for html page
    session_json = utils.make_well_data_by_unit(session_json)

    # save gathered data to json file
    utils.save_session_json(session_json)

    page_active = {"setup": "active"}
    # render page, pass data dictionary to the page
    return render_template('setup.html',
                           data=session_json,
                           page_active=page_active)