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
def WriteInterpolatedLEToDB(LEName, WellName, CorpID, ForecastGeneratedFrom, Wedge, LE_Date, 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: LEHeaderObj = m.LEHeaderRow(LEName, WellName, CorpID, ForecastGeneratedFrom, Wedge, LE_Date, '') Success, Message = LEHeaderObj.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'] LEDataObj = m.LEDataRow(LEName, CorpID, Date_Key, Gas_Production, Oil_Production, 0, '') Success, Message = LEDataObj.Write(UserName, UpdateDate) if not Success: Messages.append(Message) return Success, Messages
def SelectLEByCriteria(Wedge, WellorArea, NameFilter, start_date, end_date): from Model import ModelLayer as m import pandas as pd from datetime import datetime, timedelta Success = True Messages = [] try: ret_LE_list = [] if WellorArea: LEHeaderObj = m.LEHeader('', [WellorArea], [], []) else: LEHeaderObj = m.LEHeader('', [], [], []) rows, Success, Message = LEHeaderObj.ReadTable() if not Success: Messages.append(Message) else: if len(rows) > 0: df = pd.DataFrame([vars(s) for s in rows]) pd_start_date = pd.to_datetime(start_date) if not pd.isnull(pd_start_date): pd_end_date = pd.to_datetime(end_date) if start_date and pd.isnull(pd_end_date): end_date = pd_start_date + timedelta(days = 1) end_date = end_date.strftime('%m/%d/%Y') df = df.query('LE_Date >= @start_date and LE_Date <= @end_date') if Wedge: df = df.query('Wedge == @Wedge') if NameFilter: df = df.query('LEName.str.contains(@NameFilter)') if not df.empty: ret_LE_dict = {} ret_LE_dict['LEName'] = df['LEName'].values[0] ret_LE_dict['LE_Date'] = df['LE_Date'].values[0] ret_LE_list.append(ret_LE_dict) else: Messages.append('No LE in database matches search criteria.') except Exception as ex: Success = False Messages.append('Error during selection of LE. ' + str(ex)) return ret_LE_list, Success, Messages
def CallFilterWellsByArea(): """Interface Package Description""" interface = {"CorpIDList": list, "Area": str} pkg, success, msg = InitializePayload(request, interface) ret_well_list = [] if success: CorpIDList = pkg['CorpIDList'] Area = pkg['Area'] AreaObj = m.AreaAggregation('', [Area], [], []) rows, success, msg = AreaObj.ReadTable() #Create area_well_list area_well_list = [] for row in rows: area_well_list.append(row.CorpID) for corpID in CorpIDList: if corpID in area_well_list: ret_well_list.append(corpID) output = ConfigureOutput(ret_well_list, success, msg) return output
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 CallUpdateFracHitMultipliers(): """Interface Package Description""" interface = { "LEName": str, "CorpID": str, "Date_Key": str, "Multiplier": float, "UpdateUser": str } pkg, success, msg = InitializePayload(request, interface) if success: LEName = pkg['LEName'] CorpID = pkg['CorpID'] Date_Key = pkg['Date_Key'] Multiplier = pkg['Multiplier'] UpdateUser = pkg['UpdateUser'] FracHitRow = m.FracHitMultipliersRow(LEName, CorpID, Date_Key, Multiplier, '') success, msg = FracHitRow.Update(UpdateUser, datetime.now()) output = ConfigureOutput('', success, msg) return output
def CallUpdateOilNetting(): """Interface Package Description""" interface = { "WellName": str, "CorpID": str, "NettingValue": float, "NettingDate": datetime, "UpdateUser": str } pkg, success, msg = InitializePayload(request, interface) if success: WellName = pkg['WellName'] CorpID = pkg['CorpID'] NettingValue = pkg['NettingValue'] NettingDate = pkg['NettingDate'] UpdateUser = pkg['UpdateUser'] #Check CorpID if Wellname is passed and vice versa WellName, CorpID = iu.GetWellandCorpID(WellName, CorpID) NettingRow = m.GasNettingRow(WellName, CorpID, NettingValue, NettingDate, '') success, msg = NettingRow.Update(UpdateUser, datetime.now()) output = ConfigureOutput('', success, msg) return output
def CallUpdateLEHeader(): """Interface Package Description""" interface = { "LEName": str, "CorpID": str, "ForecastGeneratedFrom": str, "WellName": str, "Wedge": str, "LE_Date": datetime, "UserName": str } pkg, success, msg = InitializePayload(request, interface) if success: LEName = pkg['LEName'] CorpID = pkg['CorpID'] ForecastGeneratedFrom = pkg['ForecastGeneratedFrom'] WellName = pkg['WellName'] Wedge = pkg['Wedge'] LE_Date = pkg['LE_Date'] UserName = pkg['UserName'] #Check CorpID if Wellname is passed and vice versa WellName, CorpID = iu.GetWellandCorpID(WellName, CorpID) LEHeaderRowObj = m.LEHeaderRow(LEName, WellName, CorpID, ForecastGeneratedFrom, Wedge, LE_Date, '') success, msg = LEHeaderRowObj.Update(UserName, datetime.now()) output = ConfigureOutput('', success, msg) return output
def GetWellorAreaByWedge(Wedge): from Model import ModelLayer as m import pandas as pd from datetime import datetime Success = True Messages = [] well_list = [] try: #Query the LE tables to gather all wells listed by the Wedge name LEHeaderObj = m.LEHeader('', [], [], []) LEHeaderResults, Success, Message = LEHeaderObj.ReadTable() if not Success: Messages.append(Message) else: if len(LEHeaderResults) > 0: LE_df = pd.DataFrame([vars(s) for s in LEHeaderResults]) LE_df = LE_df.query('Wedge == @Wedge') well_list = list(LE_df['WellName'].unique()) except Exception as ex: Success = False Messages.append('Error during query for wells by given Wedge. ') return well_list, Success, Messages
def CallUpdateProduction(): """Interface Package Description""" interface = { "LEName": str, "CorpID": str, "WellorArea": str, "ProductionGas": list, "ProductionOil": list, "ProductionWater": list, "Dates": list, "UserName": str } pkg, success, msg = InitializePayload(request, interface) msgs = [] if success: dates = pkg['Dates'] oil_production = pkg['ProductionOil'] gas_production = pkg['ProductionGas'] water_production = pkg['ProductionWater'] UserName = pkg['UserName'] WellName = pkg['WellorArea'] CorpID = pkg['CorpID'] LEName = pkg['LEName'] #Check CorpID if Wellname is passed and vice versa WellName, CorpID = iu.GetWellandCorpID(WellName, CorpID) idx = 0 for date in dates: #Create object and update if oil_production: oil = oil_production[idx] else: oil = '' if gas_production: gas = gas_production[idx] else: gas = '' if water_production: water = water_production[idx] else: water = '' row = m.ProductionAdjustmentsRow(LEName, WellName, CorpID, date, gas, oil, water, '') success, msg = row.Update(UserName, datetime.now()) if not success: msgs.append(msg) else: msgs.append(CorpID + ' : ' + date + ' successfully updated prodcution value.') idx = idx + 1 output = ConfigureOutput('', success, msgs) return output
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 ImportActuals(corpID_list, start_date, end_date, LEName=''): from Model import BPXDatabase as bpxdb from Model import QueryFile as qf from Model import ModelLayer as m from datetime import datetime import pandas as pd Success = True Messages = [] Actuals = [] try: if isinstance(start_date, datetime): start_date = '\'' + start_date.strftime('%Y-%m-%d %H:%M:%S') + '\'' if isinstance(end_date, datetime): end_date = '\'' + end_date.strftime('%Y-%m-%d %H:%M:%S') + '\'' EDWobj = bpxdb.GetDBEnvironment('ProdEDW', 'OVERRIDE') query = qf.GetActualsFromDB(corpID_list, start_date, end_date) results = EDWobj.Query(query) Actuals = results[1] #ToDo: Add optional parameter of LE Name. Scan the production adjustments table for any overrides of #potentially incorrect production values from the EDH/EDW tables if LEName: ProdAdjObj = m.ProductionAdjustments('', [LEName], [], []) ProdAdjsRows, Success, Message = ProdAdjObj.ReadTable() if not Success: Messages.append(Message) #Query the production adjustments and see if there is any well entries for the given LE if len(ProdAdjsRows) > 0: #Loop through the results of the above query. for row in ProdAdjsRows: #Query the Actuals dataframe for the well and the dates and then update the production value (as long as value is not null) date = row.Date_Key.date() ActualsRow = Actuals.query( 'CorpID == @row.CorpID and Date_Key == @date') if not ActualsRow.empty: idx = ActualsRow.index.values[0] if row.AdjustedGasProduction: Actuals.loc[idx, 'Gas'] = row.AdjustedGasProduction if row.AdjustedOilProduction: Actuals.loc[idx, 'Oil'] = row.AdjustedOilProduction if row.AdjustedWaterProduction: Actuals.loc[idx, 'Water'] = row.AdjustedWaterProduction except Exception as ex: Messages.append('Error during query for actuals data. ' + str(ex)) Success = False return Actuals, Success, Messages
def GetLEProduction(LEName, Wedge, WellorArea, Phase = 'Gas'): from datetime import datetime from Model import ModelLayer as m from Controller import SummaryModule as s import pandas as pd #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 WellList = s.GetFullWellList(WellorArea) LERowObj = m.LEData('', [LEName], WellList, []) LEData, Success, Message = LERowObj.ReadTable() if not Success: Messages.append(Message) elif len(LEData) > 0: LEData = pd.DataFrame([vars(s) for s in LEData]) if Wedge: prod_LE_rows = LEData.query('Wedge == @Wedge') else: prod_LE_rows = LEData dates = prod_LE_rows['Date_Key'].unique() prod_array = [] date_array = [] if not prod_LE_rows.empty: if Phase == 'Gas': for date in dates: results = prod_LE_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_LE_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_LE_rows.query('Date_Key == @date') prod_array.append(results['Oil_Production'].sum()) date_array.append(date) ProductionDataObj = ProductionData(date_array, prod_array, Phase,'bbl') else: Messages.append('No Production data available with this criteria. ') except Exception as ex: Success = False Messages.append('Error during collection of production data. ' + str(ex)) return ProductionDataObj, Success, Messages
def WriteDefaultMultipliers(LE_Name, DefaultValue, Update_User, Update_Date, SuppressMessages): import datetime as datetime from Model import BPXDatabase as bpx from Model import ModelLayer as m Success = True Messages = [] try: config = m.GetConfig() DBObj = bpx.BPXDatabase(config['server'], config['database'], config['UID']) #Query the LE results LE_query = 'select * from [LEForecastDatabase].[dbo].[LE_Data] where HeaderName = \'' + LE_Name + '\'' res, df = DBObj.Query(LE_query) count = 1 for idx, row in df.iterrows(): FracHitObj = m.FracHitMultipliersRow(row['HeaderName'], row['CorpID'], row['Date_Key'], str(DefaultValue), DBObj) Success, Message = FracHitObj.Write(Update_User, Update_Date) if not Success: Messages.append(Message) if not SuppressMessages: callprogressbar(count, df.shape[0]) count = count + 1 except Exception as ex: Success = False Messages.append( 'Error during write of default frac hit multipliers. ' + str(ex)) return Success, Messages
def GetGFOValues(ForecastName, WellList, StartDate, EndDate): from Model import ModelLayer as m import pandas as pd from datetime import datetime from datetime import date Success = True Messages = [] GFO_df = [] try: #NEW Column in Header: Netting Factor. Query For this value and append to the returned GFO_df ForecastObj = m.ForecastData('', [ForecastName], WellList, []) ForecastHdrObj = m.ForecastHeader('', [], WellList, [ForecastName]) Rows, Success, Message = ForecastObj.ReadTable() HdrRows, Success, Message = ForecastHdrObj.ReadTable() if not Success: Messages.append(Message) else: GFO_df = pd.DataFrame([vars(s) for s in Rows]) GFO_hdr_df = pd.DataFrame([vars(s) for s in HdrRows]) if isinstance(StartDate, date): StartDate = datetime.combine(StartDate, datetime.min.time()) if isinstance(EndDate, date): EndDate = datetime.combine(EndDate, datetime.min.time()) GFO_df = GFO_df.query( 'Date_Key >= @StartDate and Date_Key <= @EndDate') pd.merge(GFO_df, GFO_hdr_df, on='CorpID') except Exception as ex: Success = False Messages.append('Error attempting to obtain Forecast Values. ' + str(ex)) return GFO_df, Success, Messages
def CallGetOilNF(): """Interface Package Description""" interface = {"WellNames": list, "CorpIDs": list} pkg, success, msg = InitializePayload(request, interface) rows = [] if success: WellNames = pkg['WellNames'] CorpIDs = pkg['CorpIDs'] NFobj = m.OilNetting('', WellNames, CorpIDs) rows, success, msg = NFobj.ReadTable() output = ConfigureOutput(rows, success, msg) return output
def CallGetWellsByLE(): """Interface Package Description""" interface = {"LEName": str} pkg, success, msg = InitializePayload(request, interface) rows = [] if success: LEName = pkg['LEName'] #Get LE rows LEHeaderObj = m.LEHeader('', [], [], [LEName], []) rows, success, msg = LEHeaderObj.ReadTable() output = ConfigureOutput(rows, success, msg) return output
def SelectForecastByCriteria(WellorArea, Wedge, NameFilter, GFOz): from Model import ModelLayer as m import pandas as pd Success = True Messages = [] df = pd.DataFrame() try: ret_LE_list = [] well_list = [] if WellorArea: well_list.append(WellorArea) if Wedge: wedge_list, Success, Message = GetWellorAreaByWedge(Wedge) if not Success: Messages.append(Message) well_list = [] else: well_list.extend(wedge_list) ForecastHeaderRowObj = m.ForecastHeader('', well_list, [], []) ForecastData, Success, Message = ForecastHeaderRowObj.ReadTable() if not Success: Messages.append(Message) elif len(ForecastData) > 0: df = pd.DataFrame([vars(s) for s in ForecastData]) if NameFilter: df = df.query('ForecastName.str.contains(@NameFilter)') if GFOz: df = df.query('GFO == 1') if not df.empty: ret_LE_dict = {} ret_LE_dict['ForecastName'] = df['ForecastName'].values[0] ret_LE_list.append(ret_LE_dict) else: Messages.append('No Forecast in database matches search criteria.') except Exception as ex: Success = False Messages.append('Error during selection of Forecast. ' + str(ex)) return ret_LE_list, Success, Messages
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
def CallGetFracHitMultipliers(): """Interface Package Description""" interface = {"LEName": str, "CorpIDs": list, "DateKeys": list} pkg, success, msg = InitializePayload(request, interface) ros = [] if success: LEName = pkg['LEName'] CorpIDs = pkg['CorpIDs'] DateKeys = pkg['DateKeys'] FracHitObj = m.FracHitMultipliers('', [LEName], CorpIDs, DateKeys) rows, success, msg = FracHitObj.ReadTable() output = ConfigureOutput(rows, success, msg) return output
def CallGetAreaDetails(): """Interface Package Description""" interface = {"AggregateName": str, "WellNames": list, "CorpIDs": list} pkg, success, msg = InitializePayload(request, interface) rows = [] if success: AggregateName = pkg['AggregateName'] WellNames = pkg['WellNames'] CorpIDs = pkg['CorpIDs'] AggregateObj = m.AreaAggregation('', [AggregateName], WellNames, CorpIDs) rows, success, msg = AggregateObj.ReadTable() output = ConfigureOutput(rows, success, msg) return output
def GetFullWellList(well_list): from Model import ModelLayer as m import pandas as pd #Check each item to see if an entry exists as an Area table and return a complete list new_list = [] for well in well_list: AreaObj = m.AreaAggregation('', [well], [], []) Rows, Success, Message = AreaObj.ReadTable() if len(Rows) > 0: Rows = pd.DataFrame([vars(s) for s in Rows]) new_wells = Rows['CorpID'].unique() if len(list(new_wells)) == 0: print('No wells in Area: ' + well) new_list.extend(list(new_wells)) else: new_list.append(well) return new_list
def CallDeleteArea(): """Interface Package Description""" interface = {"AreaName": str, "WellList": list} pkg, success, msg = InitializePayload(request, interface) if success: AreaName = pkg['AreaName'] WellList = pkg['WellList'] AreaRowsObj = m.AreaAggregation('', [AreaName], WellList, []) rows, success, msg = AreaRowsObj.ReadTable() for row in rows: success, msg = row.Delete() if success: DBObj = row.DBObj DBObj.Command('commit') output = ConfigureOutput('', success, msg) return output
def CallUpdateForecastHeader(): """Interface Package Description""" interface = { "HeaderName": str, "WellName": str, "CorpID": str, "ForecastName": str, "ForecastYear": str, "scenarioName": str, "GFO": str, "UpdateUser": str } pkg, success, msg = InitializePayload(request, interface) if success: HeaderName = pkg['HeaderName'] WellName = pkg['WellName'] CorpID = pkg['CorpID'] ForecastName = pkg['ForecastName'] ForecastYear = pkg['ForecastYear'] scenarioName = pkg['scenarioName'] GFO = pkg['GFO'] UserName = pkg['UpdateUser'] Arps = {} Arps['Di'] = '' Arps['qi'] = '' Arps['b'] = '' #Check CorpID if Wellname is passed and vice versa WellName, CorpID = iu.GetWellandCorpID(WellName, CorpID) ForecastHeaderRow = m.ForecastHeaderRow(WellName, CorpID, ForecastName, ForecastYear, scenarioName, Arps, GFO, '') success, msg = ForecastHeaderRow.Update(UserName, datetime.now()) output = ConfigureOutput('', success, msg) return output
def CallGetWedge(): """Interface Package Description""" interface = {"LEName": str, "WedgeName": str} pkg, success, msg = InitializePayload(request, interface) if success: LEName = pkg['LEName'] Wedge = pkg['WedgeName'] #Get LE rows and match on passed Wedge LEHeaderObj = m.LEHeader('', [], [], [LEName], []) rows, success, msg = LEHeaderObj.ReadTable() ret_rows = [] for row in rows: if row.Wedge == Wedge: ret_rows.append(row) output = ConfigureOutput(ret_rows, success, msg) return output
def CreateAreaWellsFromRoute(new_route_name, db_route_name, 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: ODSObj = bpx.GetDBEnvironment('ProdODS', 'OVERRIDE') EDWObj = bpx.GetDBEnvironment('ProdEDW', 'OVERRIDE') query = qf.RouteQuery([db_route_name]) results = ODSObj.Query(query) for idx, row in results[1].iterrows(): wellflac_query = qf.EDWKeyQueryFromWellFlac([row['wellflac']]) corpIDres = EDWObj.Query(wellflac_query) if not corpIDres[1].empty: corpID = corpIDres[1]['CorpID'].iloc[0] AggregateRowObj = m.AreaAggregationRow(new_route_name, row['name'], corpID, '') Row_Success, Message = AggregateRowObj.Write( Update_User, datetime.now()) if not Row_Success: Messages.append(Message) else: Messages.append('Missing well entry in key database EDW: ' + row['name']) except Exception as ex: Success = False Messages.append( 'Error during Area Aggegation interface from Enbase. ' + str(ex)) return Success, Messages
def CallUpdateFracMultiplier(): """Interface Package Description""" interface = { "WellorArea": str, "CorpID": str, "LEName": str, "Multipliers": list, "Dates": list, "UserName": str } pkg, success, msg = InitializePayload(request, interface) msgs = [] if success: LEName = pkg['LEName'] WellName = pkg['WellorArea'] CorpID = pkg['CorpID'] Dates = pkg['Dates'] Multipliers = pkg['Multipliers'] UserName = pkg['UserName'] #Check CorpID if Wellname is passed and vice versa WellName, CorpID = iu.GetWellandCorpID(WellName, CorpID) idx = 0 for date in Dates: row = m.FracHitMultipliersRow(LEName, CorpID, date, Multipliers[idx], '') success, msg = row.Update(UserName, datetime.now()) if not success: msgs.append(msg) else: msgs.append(CorpID + ' : ' + date + ' successfully updated frac hit multiplier.') idx = idx + 1 output = ConfigureOutput('', success, msgs) return output
def SOHA_WriteGFOToDB_2019Database(ForecastName, ForecastYear, User, start_date, end_date, WellFlac=['ALL'], GFO=False): #Part of to be deprecated methods to convert SoHa internal GFO data to standard from Model import BPXDatabase as bpxdb from Model import QueryFile as qf from Model import ImportUtility as imp from Model import ModelLayer as m import datetime as dt import numpy as np Sucess = True Messages = [] try: config = m.GetConfig() #Create DB Object return_df, Success, Message = imp.ImportGFOFromDB2019( start_date, end_date, WellFlac) if not Success: Messages.append(Message) Production_Column_Name = '2019Zmcfd' Success, Message = WriteInternalForecasttoDB(return_df, ForecastName, ForecastYear, Production_Column_Name, User, GFO) if not Success: Messages.append(Message) except Exception as ex: Success = False Messages.append('Error writing GFO to DB. ' + str(ex)) return Success, Messages
def CallGetSummary(): """Interface Package Description""" interface = { "SummaryName": list, "LEName": list, "Wedge": list, "GFOForecastName": list } pkg, success, msg = InitializePayload(request, interface) if success: SummaryName = pkg['SummaryName'] LEName = pkg['LEName'] Wedge = pkg['Wedge'] GFOForecastName = pkg['GFOForecastName'] table_obj = m.LESummary('', SummaryName, LEName, Wedge, GFOForecastName) results, success, msg = table_obj.ReadTable() output = ConfigureOutput(results, success, msg) return output
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