示例#1
0
                workDF = pd.merge(workDF, secInf, on='TMSRS_CD', how='left')
                NOW_DT = dt.datetime.now()
                tmStr = NOW_DT.strftime("%Y-%m-%d %H:%M:%S.") + format(
                    int(round(NOW_DT.microsecond / 1000, 0)), "03d")
                workDF['REG_DTTM'] = tmStr
                workDF['REG_EMP_NMB'] = '2150416'
                workDF['LST_DTTM'] = tmStr
                workDF['LST_EMP_NMB'] = '2150416'
                workDF = workDF[up.typeStr.index]

                #*--- cleanse values to fit in sql table ---
                workDF['freq'] = workDF['freq'].str.replace('Norm', 'Nr')
                str_cols = [
                    'Code', 'CD_ref', 'ref_CTRY', 'adj_op', 'ref_Name',
                    'ref_SEDOL', 'ref', 'freq'
                ]
                for col in str_cols:
                    workDF[col] = workDF[col].apply(
                        lambda x: x if isinstance(x, str) else 'NULL')
                float_cols = ['Value_', 'Value_adj']
                for col in float_cols:
                    workDF[col] = workDF[col].round(8)
                workDF['ref_Name'] = workDF['ref_Name'].apply(
                    lambda x: re.sub("'", " ", x))
                #*--- cleanse values to fit in sql table ---

                print('\n    - Uploading ({}) {}'.format(adj_, fctr))
                update_table(conn, db_name, workDF, up.typeStr, verbose=True)
                conn.close()
                continue
示例#2
0
from batch_utils import WS_currVal

bkfil, rtvStart, seq_DT = batch_sequence('backfill', 'M')

Table = 'WSPITCmpIssFData'
Code = ['6751']
Item = '9802'  # beta
cal_dt_ = seq_DT.rename('marketdate')

S0 = pd.Series({'marketdate': 'datetime'})
primary = 'marketdate'
typeStr = create_typeStr(S0, primary=primary)

conn = connectDB(ODBC_NAME="MSSQL_QAD")
create_table(conn, '#Calendar', typeStr, primary=primary)
update_table(conn, '#Calendar', cal_dt_, typeStr, verbose=False)

Sql_S = """
Select convert(varchar(8),mm.marketdate,112) as marketdate, dt.Code,
        dt.Item, convert(varchar(8), dt.StartDate,112) as StartDate,
        convert(varchar(8), dt.EndDate,112) as EndDate, dt.Value_
    from #Calendar mm
    left outer join {} dt with (nolock)
    on mm.marketdate >= dt.StartDate
    and mm.marketdate <= isnull(dt.EndDate, dateadd(d,2,GETDATE()))
    where dt.Code in ({})
    and dt.Value_ <> -1e+38
    and not (dt.Value_ = 0  and dt.EndDate is NULL)
    and dt.Item='{}'
""".format(Table, list2sqlstr(Code), Item)
DT = pd.read_sql(Sql_S, conn)