Пример #1
0
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
Пример #2
0
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