def ImportAriesByScenario(scenarioName, start_date, end_date, Area, CorpID=['ALL']): from Model import BPXDatabase as bpxdb from Model import QueryFile as qf import pandas as pd #Create ODS and EDW objects Success = True Messages = [] combined_df = pd.DataFrame() try: ODSobj = bpxdb.GetDBEnvironment('ProdODS', 'OVERRIDE') EDWobj = bpxdb.GetDBEnvironment('ProdEDW', 'OVERRIDE') scenario_query = qf.ScenarioQuery(scenarioName, CorpID, start_date, end_date) results = ODSobj.Query(scenario_query) #Extract APINumbers from the results and concatenate into an 'IN' sql clause corpid_list = [] for result in results[0]: if not result['CorpID'] in corpid_list: corpid_list.append(result['CorpID']) if None in corpid_list: corpid_list.remove(None) key_query = qf.EDWKeyQueryFromCorpID(corpid_list, Area) key_results = EDWobj.Query(key_query) #Join the key_results to the Aries results combined_df = pd.merge(results[1], key_results[1], on='CorpID', how='right') except Exception as ex: Messages.append('Error on Import from Aries. ' + str(ex)) Success = False return combined_df, 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 WriteLEFromTemplate(all_data_df, InterpolationMethod, LEName, LE_Date, Update_User, IDCol='WellName'): from datetime import datetime, date import pandas as pd from Model import QueryFile as qf from Model import BPXDatabase as bpx from Model import ImportUtility as i Success = True Messages = [] results = [] try: #Data Frame must be the same structure as the output from the 'Read From Excel Function #'CorpID', 'WellName', 'Wedge', 'Date', 'Gas', 'Oil', 'Water', 'OilNF', 'GasNF' wellname = '' if not Success: Messages.append(Message) if IDCol == 'CorpID': corpid_list = list(all_data_df['CorpID'].unique()) corpid_query = qf.EDWKeyQueryFromCorpID(corpid_list) corpid_results, corpid_df = bpx.GetDBEnvironment( 'ProdEDW', 'OVERRIDE').Query(corpid_query) well_list = list(corpid_df['WellName'].unique()) well_query = 'CorpID == @corpid' else: well_list = list(all_data_df['WellName'].unique()) well_query = 'WellName == @wellname' well_list = [i for i in well_list if i] for wellname in well_list: wellname, corpid = i.GetWellandCorpID(wellname, '') if not corpid: corpid = wellname data_df = all_data_df.query(well_query) row_count = 1 if not data_df.empty: df_previous_row = (0, data_df.iloc[1]) for idx, df_row in data_df.iterrows(): if InterpolationMethod == 'MonthlyRates': if row_count == 1: df_next_row = data_df.iloc[row_count] results = InterpolateDailyRatesFromMonthlyRates( CurrentMonthVal=df_row, NextMonthVal=df_next_row, GasProduction='Gas', OilProduction='Oil') elif row_count != data_df.shape[0] and row_count != 1: df_next_row = data_df.iloc[row_count] results = InterpolateDailyRatesFromMonthlyRates( CurrentMonthVal=df_row, NextMonthVal=df_next_row, PreviousMonthVal=df_previous_row, GasProduction='Gas', OilProduction='Oil') elif row_count == data_df.shape[0]: results = InterpolateDailyRatesFromMonthlyRates( CurrentMonthVal=df_row, PreviousMonthVal=df_previous_row, GasProduction='Gas', OilProduction='Oil') elif InterpolationMethod == 'MonthlyVolume': if row_count == 1: df_next_row = data_df.iloc[row_count] results = InterpolateDailyRatesFromMonthlyVolumes( CurrentMonthVal=df_row[1], NextMonthVal=df_next_row) else: results = InterpolateDailyRatesFromMonthlyVolumes( CurrentMonthVal=df_row[1], PreviousMonthVal=df_previous_row[1]) elif InterpolationMethod == 'None': results = ConvertNonInterpolatedResults(df_row) Wedge, Message = i.GetWedgeData(corpid, True) Success, Message = WriteInterpolatedLEToDB( LEName, wellname, corpid, '', Wedge, LE_Date, Update_User, results) if not Success: Messages.append(Message) df_previous_row = df_row row_count = row_count + 1 except Exception as ex: Success = False Messages.append('Error during the writing of the LE from template. ' + str(ex)) return Success, Messages