예제 #1
0
def func1():
    pgconn = MySQLdb.Connect(host="192.168.1.42",port=3307, user="******",passwd="0.618", db="test",charset="utf8")
    connection = pygrametl.ConnectionWrapper(pgconn)
    connection.setasdefault()

    student = CSVSource(file("./resource/student.txt",'r',100000),delimiter=',')

    studentdim=CachedDimension(name="Student",
                              key="id",
                              attributes=("studentid",'name',"birthday"),
                              lookupatts=("studentid",))
    
    score = CSVSource(file("./resource/studentscore.txt",'r',100000),delimiter=',')

    scoredim=CachedDimension(name="StudentScore",
                              key="id",
                              attributes=("studentid",'coursename',"score"),
                              lookupatts=("studentid",))
    
    mjdata = MergeJoiningSource(student,'no',score,'no')
    
    for row in mjdata:
        row['birthday'] =  datetime.strptime(row['birthday'],'%Y-%m-%d').date()#pygrametl.getdate(connection,row['birthday']) # Convert to an date
        studentdim.ensure(row, {'studentid':'no'})
        scoredim.ensure(row, {'studentid':'no','coursename':'course'})
        
    connection.commit()
예제 #2
0
def func1():
    pgconn = MySQLdb.Connect(host="192.168.1.42",port=3307, user="******",passwd="0.618", db="Data_Fundamental_Master_Genius",charset="utf8")
    connection = pygrametl.ConnectionWrapper(pgconn)
    connection.setasdefault()

    rehabdata = CSVSource(file(ur"d:\temp\ReHis000001.csv",'r',10000),delimiter=',')

    rehabdim=CachedDimension(name="SFM_StockAdjPrices",
                              key="RecordID",
                              attributes=("MarketCode",'StockListID',"TradeDate","PreClosePrice","OpenPrice","ClosePrice","HighPrice","LowPrice","PriceAdjType"),
                              lookupatts=("MarketCode",'StockListID',"TradeDate","PriceAdjType"))
    
    title_mapping={"StockListID":"stockcode",
                   "TradeDate":"tradedate",
                   "PreClosePrice":"preClosePrice",
                   "OpenPrice":"OpenClosePrice",
                   "ClosePrice":"ClosePrice"}
    
    for row in rehabdata:
        row['MarketCode'] = 102
        row['PriceAdjType'] = 1
        rehabdim.ensure(row, title_mapping)
        
    connection.commit()