def CreateAreaFromWells(new_route_name, well_list, Update_User): from Model import ModelLayer as m from Model import QueryFile as qf from Model import BPXDatabase as bpx from datetime import datetime import pandas as pd Success = True Messages = [] try: WellQuery = qf.EDWKeyQueryFromWellName(well_list) obj = bpx.GetDBEnvironment('ProdEDW', 'OVERRIDE') wells, wells_df = obj.Query(WellQuery) for idx, well in wells_df.iterrows(): WellName = well['WellName'] corpID = well['CorpID'] AggregateRowObj = m.AreaAggregationRow(new_route_name, WellName, corpID, '') Row_Success, Message = AggregateRowObj.Write( Update_User, datetime.now()) if not Row_Success: Messages.append(Message) except Exception as ex: Success = False Messages.append( 'Error during the creation of the area from well list. ' + str(ex)) return Success, Messages
def SOHA_WriteGasNettingFactorsFromDB(Update_User, Update_Date, wellnames=[]): from Model import BPXDatabase as bpx from Model import QueryFile as qf from Model import ModelLayer as m import datetime as datetime Success = True Messages = [] try: config = m.GetConfig() DBObj = bpx.BPXDatabase(config['server'], config['database'], config['UID']) TeamOpsObj = bpx.GetDBEnvironment('OnPrem', 'OVERRIDE') EDWObj = bpx.GetDBEnvironment('ProdEDW', 'OVERRIDE') #Get Well List of required netting values from data that is already in database. query = qf.GetNettingFactorsfromDB(wellnames) res, res_df = TeamOpsObj.Query(query) count = 1 for idx, item in res_df.iterrows(): wellquery = qf.EDWKeyQueryFromWellName([item['WellName']]) res, well_row = EDWObj.Query(wellquery) if not well_row.empty: corpID = well_row['CorpID'].values[0] NettingObj = m.GasNettingRow(item['WellName'], corpID, item['NF'], item['FirstSalesDateInput'], DBObj) Success, Message = NettingObj.Write(Update_User, Update_Date) if not Success: Messages.append(Message) callprogressbar(count, res_df.shape[0]) count = count + 1 except Exception as ex: Success = False Messages.append('Error during write of netting factors to DB. ' + str(ex)) return Success, Messages
def GetWellandCorpID(WellName, CorpID): from Model import QueryFile as qf from Model import BPXDatabase as bpx #Check CorpID if Wellname is passed if not CorpID and WellName: CorpID_query = qf.EDWKeyQueryFromWellName([WellName]) EDWObj = bpx.GetDBEnvironment('ProdEDW', 'OVERRIDE') res, res_df = EDWObj.Query(CorpID_query) if not res_df.empty: CorpID = res_df['CorpID'].values[0] #Check WellName if CorpID not passed if not WellName and CorpID: WellName_Query = qf.EDWKeyQueryFromCorpID([CorpID], '') EDWObj = bpx.GetDBEnvironment('ProdEDW', 'OVERRIDE') res, res_df = EDWObj.Query(WellName_Query) if not res_df.empty: WellName = res_df['WellName'].values[0] return WellName, CorpID
def GetActuals(WellorArea, Wedge, start_date, end_date, LEName = '', Adjusted = False, Phase = 'Gas'): from Model import ModelLayer as m import pandas as pd from Controller import SummaryModule as s from Model import ImportUtility as i from Model import QueryFile as qf from Model import BPXDatabase as bpx Success = True Messages = [] ActualProduction = [] try: WellList = [] if WellorArea: WellList = s.GetFullWellList(WellorArea) if Wedge: wedge_list, Success, Message = GetWellorAreaByWedge(Wedge) if not Success: Messages.append('Error finding wells associated with input Wedge. ') else: WellList.extend(wedge_list) EDWobj = bpx.GetDBEnvironment('ProdEDW', 'OVERRIDE') corpid_query = qf.EDWKeyQueryFromWellName(WellList) corpid_list = EDWobj.Query(corpid_query) corpid_list = list(corpid_list[1]['CorpID']) if LEName and Adjusted == True: actuals_df, Success, Message = i.ImportActuals(corpid_list, pd.to_datetime(start_date), pd.to_datetime(end_date), LEName) else: actuals_df, Success, Message = i.ImportActuals(corpid_list, pd.to_datetime(start_date), pd.to_datetime(end_date), '') if not Success: Messages.append(Message) else: dates = actuals_df['Date_Key'].unique() prod_array = [] date_array = [] if not actuals_df.empty: if Phase == 'Gas': for date in dates: results = actuals_df.query('Date_Key == @date') prod_array.append(results['Gas'].sum()) date_array.append(date) ActualProduction = ProductionData(date_array, prod_array, Phase,'scf') elif Phase == 'Water': for date in dates: results = actuals_df.query('Date_Key == @date') prod_array.append(results['Water'].sum()) date_array.append(date) ActualProduction = ProductionData(date_array, prod_array, Phase,'bbl') elif Phase == 'Oil': for date in dates: results = actuals_df.query('Date_Key == @date') prod_array.append(results['Oil'].sum()) date_array.append(date) ActualProduction = ProductionData(date_array, prod_array, Phase,'bbl') except Exception as ex: Success = False Messages.append('Error during import of Actual production data. ' + str(ex)) return ActualProduction, Success, Messages
def GetForecastProduction(ForecastName, Wedge, WellorArea, Phase = 'Gas'): from datetime import datetime from Model import ModelLayer as m import pandas as pd from Model import BPXDatabase as bpx from Model import QueryFile as qf #Get the production values from the LE table by the input criteria Success = True Messages = [] ProductionDataObj = [] try: #Get all CorpIDs from Well or Area passed well_list = [] corpid_list = [] if WellorArea: well_list.append(WellorArea) EDWobj = bpx.GetDBEnvironment('ProdEDW', 'OVERRIDE') corpid_query = qf.EDWKeyQueryFromWellName(well_list) corpid_list = EDWobj.Query(corpid_query) corpid_list = list(corpid_list[1]['CorpID']) if Wedge: wedge_list, Success, Message = GetWellorAreaByWedge(Wedge) if not Success: Messages.append(Message) else: well_list.extend(wedge_list) ForecastDataRowObj = m.ForecastData('', [ForecastName], corpid_list, []) ForecastData, Success, Message = ForecastDataRowObj.ReadTable() if not Success: Messages.append(Message) else: prod_Forecast_rows = pd.DataFrame([vars(s) for s in ForecastData]) dates = prod_Forecast_rows['Date_Key'].unique() prod_array = [] date_array = [] if not prod_Forecast_rows.empty: if Phase == 'Gas': for date in dates: results = prod_Forecast_rows.query('Date_Key == @date') prod_array.append(results['Gas_Production'].sum()) date_array.append(date) ProductionDataObj = ProductionData(date_array, prod_array, Phase,'scf') elif Phase == 'Water': for date in dates: results = prod_Forecast_rows.query('Date_Key == @date') prod_array.append(results['Water_Production'].sum()) date_array.append(date) ProductionDataObj = ProductionData(date_array, prod_array, Phase,'bbl') elif Phase == 'Oil': for date in dates: results = prod_Forecast_rows.query('Date_Key == @date') prod_array.append(results['Oil_Production'].sum()) date_array.append(date) ProductionDataObj = ProductionData(date_array, prod_array, Phase,'bbl') except Exception as ex: Success = False Messages.append('Error during collection of production data. ' + str(ex)) return ProductionDataObj, Success, Messages
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