Exemplo n.º 1
0
def WriteInterpolatedForecastToDB(WellName, corpID, ForecastName, ForecastYear,
                                  scenarioName, GFO, UserName, results):
    import datetime as dt
    import pandas as pd
    from Model import ModelLayer as m

    header_corpID = ''
    Messages = []
    for item in results.iterrows():
        idx = item[0]
        UpdateDate = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        if header_corpID != corpID:
            ForecastHeaderObj = m.ForecastHeaderRow(WellName, corpID,
                                                    ForecastName, ForecastYear,
                                                    scenarioName, [], GFO, '')
            Success, Message = ForecastHeaderObj.Write(UserName, UpdateDate)
            if not Success:
                Messages.append(Message)
            else:
                header_corpID = corpID

        Date_Key = item[1]['Date'].strftime('%m/%d/%Y')
        Gas_Production = item[1]['GasProduction']
        Oil_Production = item[1]['OilProduction']
        GasNF = item[1]['GasNF']
        OilNF = item[1]['OilNF']
        ForecastDataObj = m.ForecastDataRow(ForecastName, corpID, Date_Key,
                                            Gas_Production, Oil_Production, 0,
                                            GasNF, OilNF, 0, '')
        Success, Message = ForecastDataObj.Write(UserName, UpdateDate)
        if not Success:
            Messages.append(Message)

    return Success, Messages
Exemplo n.º 2
0
def CallUpdateForecastRow():
    """Interface Package Description"""
    interface = {
        "HeaderName": str,
        "CorpID": str,
        "Dates": list,
        "Gas_Production": list,
        "Oil_Production": list,
        "Water_Production": list,
        "Gas_NF": list,
        "Oil_NF": list,
        "Water_NF": list,
        "UpdateUser": str
    }

    pkg, success, msg = InitializePayload(request, interface)
    msgs = []
    if success:
        HeaderName = pkg['HeaderName']
        CorpID = pkg['CorpID']
        Dates = pkg['Dates']
        Gas_Production = pkg['Gas_Production']
        Oil_Production = pkg['Oil_Production']
        Water_Production = pkg['Water_Production']
        GasNF = pkg['Gas_NF']
        OilNF = pkg['Oil_NF']
        WaterNF = pkg['Water_NF']
        UpdateUser = pkg['UpdateUser']

        idx = 0
        for date in Dates:
            ForecastRow = m.ForecastDataRow(HeaderName, CorpID, date,
                                            Gas_Production[idx],
                                            Oil_Production[idx],
                                            Water_Production[idx], GasNF[idx],
                                            OilNF[idx], WaterNF[idx], '')
            success, msg = ForecastRow.Update(UpdateUser, datetime.now())
            if not success:
                msgs.append(msg)
                break
            else:
                msgs.append(CorpID + ' : ' + date +
                            ' successfully updated for ' + HeaderName)
            idx = idx + 1

    output = ConfigureOutput('', success, msgs)
    return output
Exemplo n.º 3
0
def SOHA_WriteInternalForecasttoDB(df,
                                   ForecastName,
                                   ForecastYear,
                                   Production_Column_Name,
                                   User,
                                   GFO=True):
    #Part of to be deprecated methods to convert SoHa internal GFO data to standard
    from Model import BPXDatabase as bpx
    from Model import ModelLayer as m
    import datetime as dt
    from Model import QueryFile as qf

    Success = True
    Messages = []

    try:
        config = m.GetConfig()
        DBObj = bpx.BPXDatabase(config['server'], config['database'],
                                config['UID'])
        EDWObj = bpx.GetDBEnvironment('ProdEDW', 'OVERRIDE')

        wellname_list = df['WellName'].unique()
        wellname_list = list(wellname_list)
        if '' in wellname_list:
            wellname_list.remove('')
        count = 1
        for name in wellname_list:
            monthly_df = df.query('WellName == @name')
            monthly_df = monthly_df.sort_values(by=['Date'], ascending=True)
            df_previous_row = (0, monthly_df.iloc[1])
            nettingFactor = monthly_df['NettingFactor'].values[0]
            well_count = 1
            header_corpid = ''
            for df_row in monthly_df.iterrows():
                if well_count == 1:
                    df_next_row = monthly_df.iloc[well_count]
                    results = InterpolateDailyRatesFromMonthlyRates(
                        CurrentMonthVal=df_row[1],
                        NextMonthVal=df_next_row,
                        GasRateField=Production_Column_Name)
                elif well_count != monthly_df.shape[0] and well_count != 1:
                    df_next_row = monthly_df.iloc[well_count]
                    results = InterpolateDailyRatesFromMonthlyRates(
                        CurrentMonthVal=df_row[1],
                        NextMonthVal=df_next_row,
                        PreviousMonthVal=df_previous_row[1],
                        GasRateField=Production_Column_Name)
                elif well_count == monthly_df.shape[0]:
                    results = InterpolateDailyRatesFromMonthlyRates(
                        CurrentMonthVal=df_row[1],
                        PreviousMonthVal=df_previous_row[1],
                        GasRateField=Production_Column_Name)

                for row in results.iterrows():
                    corpid_query = qf.EDWKeyQueryFromWellName([name])
                    corpid_results = EDWObj.Query(corpid_query)
                    if not corpid_results[1].empty:
                        CorpID = corpid_results[1].at[0, 'CorpID']
                    else:
                        CorpID = name
                    WellName = name
                    Update_Date = dt.datetime.now().strftime(
                        "%Y-%m-%d %H:%M:%S")
                    Update_User = User
                    if header_corpid != CorpID:
                        #Create Header entry
                        header_corpid = CorpID
                        ForecastHeaderObj = m.ForecastHeaderRow(
                            WellName, CorpID, ForecastName, ForecastYear, '',
                            [], GFO, DBObj)
                        Success, Message = ForecastHeaderObj.Write(
                            Update_User, Update_Date)
                        if not Success:
                            Messages.append(Message)

                    Date_Key = row[1]['Date'].strftime('%m/%d/%Y')
                    Gas_Production = row[1]['GasProduction']
                    GasNF = row[1]['GasNF']
                    if Gas_Production >= 0 and Date_Key:
                        ForecastDataObj = m.ForecastDataRow(
                            ForecastName, CorpID, Date_Key, Gas_Production, 0,
                            0, GasNF, 0, 0, DBObj)
                        Success, Message = ForecastDataObj.Write(
                            Update_User, Update_Date)
                        if not Success:
                            Messages.append(Message)

                    df_previous_row = df_row

                well_count = well_count + 1

            callprogressbar(count, len(wellname_list))
            count = count + 1

    except Exception as ex:
        Success = False
        Messages.append('Error writing Forecast to Database. ' + str(ex))

    return Success, Messages