Beispiel #1
0
def upload_file():
    if request.method == 'POST':  # check if method is POST
        # check if the post request has the file part
        if 'file' not in request.files:  # check if file in received form
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':  # check if filename is not empty
            flash('No selected file')
            return redirect(request.url)
        if file and utils.allowed_file(
                file.filename, ALLOWED_EXTENSIONS
        ):  # check if file exists and file is one of the allowed (look on top)
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'],
                                   filename))  # save file in temp folder

            result_text, warn_text = gath_par.parse_gathering_report(
            )  # parse the data in excel file and return results

            session_json = utils.get_session_json(
            )  # read from json file all necessary app data
            well_details = xl_setup.read_conns(session_json["well_data"])

            result_text = utils.merge_route_slot(result_text, well_details)

            #remove file after getting data
            os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename))

    return jsonify({
        "result_text": result_text,
        "warn_text": warn_text
    })  # send back AJAX response with results from parsing
Beispiel #2
0
def live():
    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"

    page_active = {"live": "active"}

    return render_template('live.html', page_active=page_active)
Beispiel #3
0
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"
Beispiel #4
0
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"
Beispiel #5
0
def live_ro():
    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"
    ro_data = ro.get_well_routes(session_json)
    comb_num = ro.count_combs(ro_data)
    page_active = {"live_ro": "active"}
    return render_template('live_ro.html',
                           page_active=page_active,
                           ro_data=ro_data,
                           comb_num=comb_num)
Beispiel #6
0
def load():
    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"
    page_active = {
        "load_pcs": "active",
        "load_state": "",
        "load_streams": "",
        "setup": "",
        "live": "",
        "results": ""
    }
    return render_template('load.html', page_active=page_active)
Beispiel #7
0
def start_gap_calc():

    session_json = utils.get_session_json()
    if MOCKUP:
        print("skip xls calc")
        post_opt_state = nsopt.run_optimization(
            session_json, 1
        )  # pass state to GAP to make calculations, mode 1= normal optimization
    else:
        post_opt_state = gob.run_optimization(
            session_json, "None", 1
        )  # pass state to GAP to make calculations, "None" is placeholder for PE_server
    #------------------------------------------------------------------------------
    return "None"
Beispiel #8
0
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)
Beispiel #9
0
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"
Beispiel #10
0
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!"})
Beispiel #11
0
def save_2ref():
    session_json = utils.get_session_json()
    utils.save_2ref(session_json)
    emit('save_complete', {"data": "Reference case saved"})
    return "None"
Beispiel #12
0
def update_combs(data):
    session_json = utils.get_session_json()
    combs = ro.generate_comb2(data["ro_data"])
    combs = ro.filter_combs(combs, data["filters"], session_json)
    emit("comb_num", {"comb_num": len(combs)})
    return "None"
Beispiel #13
0
def start_route_opt(data):
    session_json = utils.get_session_json()
    ro.route_optimization(session_json, data["ro_data"], data["filters"],
                          MOCKUP)
    return "None"
Beispiel #14
0
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)