Beispiel #1
0
def test_cxReturnValue() :
    returnValue = cxReturnValue()
    print returnValue.func_name, returnValue.value, returnValue.result
    returnValue2 = cxReturnValue(['a','b'])
    print returnValue2.func_name, returnValue2.value, returnValue2.result
    returnValue3 = cxReturnValue(u'',u'invalid value')
    print returnValue3.func_name, '"',returnValue3.value,'"', returnValue3.result
Beispiel #2
0
 def getPath(self, argChartType=u'') :
     if argChartType == u'' :
         return cxReturnValue(self.basePath)
     subDir = self.getChartDir(argChartType)
     if subDir.result != u'ok' :
         return cxReturnValue(subDir.value, subDir.result)
     return cxReturnValue(self.basePath+subDir.value+u'\\')
Beispiel #3
0
 def getFieldList(self, argFieldList ) :
     fieldList = []
     if argFieldList == [] or argFieldList == None :
         return cxReturnValue(None, u'invalid argFieldList')
     for fieldName in argFieldList :
         if fieldName in self.fieldDic.keys() :
             fieldList.append(self.fieldDic[fieldName])
         else :
             return cxReturnValue(None,
                                  u'failed to find field index(%s)'%fieldName)
     return cxReturnValue(fieldList, u'ok')
Beispiel #4
0
 def getFileName(self, argChartType, argStockCode) :
     if argStockCode == u'' or argStockCode == None :
         return cxReturnValue(u'',u'invalid argStockCode')
     cpStockCode = self.cpClsDic['cxCpStockCode']
     stockName = cpStockCode.CodeToName(argStockCode)
     if stockName == u'' :
         return cxReturnValue(u'',
                              u'failed to find stock name of "%s"'%argStockCode)
     path = self.getPath(argChartType)
     if path.result != u'ok' :
         return cxReturnValue(path.value,path.result)
     fileName = path.value + argStockCode + u'.data'
     return cxReturnValue(fileName)
Beispiel #5
0
 def getChartType(self, argChartType) :
     chartType = argChartType.lower()
     if chartType in self.chartType.keys() :
         return cxReturnValue(self.chartType[chartType])
     if argChartType in self.chartType.values() :
         return cxReturnValue(argChartType)
     if argChartType == u'w' :
         return cxReturnValue(u'W')
     elif argChartType == u'd' :
         return cxReturnValue(u'd')
     elif argChartType == u'Time' or argChartType == u'time' :
         return cxReturnValue(u'm')
     elif argChartType == u't' :
         return cxReturnValue(u'T')
     else :
         return cxReturnValue(u'',
                              u'failed to find chart type for "%s"'%argChartType)
Beispiel #6
0
 def getChartDir(self, argChartType) :
     if argChartType == u'' :
         return cxReturnValue(u'',u'argChartType is null')
     chartType = argChartType.lower()
     if chartType in self.chartType.keys() :
         return cxReturnValue(common.UNI(chartType))
     if argChartType in self.chartType.values() :
         for item in self.chartType.items() :
             if item[1] == argChartType :
                 return cxReturnValue(common.UNI(item[0]))
     if argChartType == u'w' :
         return cxReturnValue(u'week')
     elif argChartType == u'd' :
         return cxReturnValue(u'day')
     elif argChartType == u'Time' or argChartType == u'time' :
         return cxReturnValue(u'minute')
     elif argChartType == u't' :
         return cxReturnValue(u'tick')
     else :
         return cxReturnValue(u'',
                              u'failed to find chart type for "%s"'%argChartType)
Beispiel #7
0
    def update(self, argChartType, argStockCode, argClear=False, argFileName=u'') :
        # filtering chart type
        chartType = self.getChartType(argChartType)
        if chartType.result != u'ok' :
        #{
            return cxReturnValue(chartType.value, chartType.result)
        #}

        # filtering file name or set default file name
        fileName = u''
        if argFileName == u'' : # if there aren't specific file name
        #{
            dataFileName = self.getFileName(chartType.value, argStockCode)
            if dataFileName.result != u'ok' :
            #{
                return cxReturnValue(dataFileName.value, dataFileName.result)
            #}
            fileName = dataFileName.value
        #}
        else :  # specific file name are given.
        #{
            fileName = argFileName
        #}

        # filtering argClear
        if chartType.value == u'M' or chartType.value == u'W':
            argClear = True    

        dataFile = cxFile(fileName) 

        if argClear == True :   # delete file and update file
            if dataFile.isExist() == True :
                dataFile.delete()
            dataFile = cxFile(fileName)

        # call updateDataList
        import time

        if dataFile.isEmpty() == False :    # not empty
            # get last date time info from file
            lastDate = 19900101
            lastLine = dataFile.getLastLine()
            #####print u"'"+lastLine+u"'"
            #####print lastLine.split()
            if lastLine != None and lastLine != u'' :
                parsedDate = lastLine.split()[0]
                if parsedDate.isdigit() == True :
                    lastDate = common.getOneDayPlus(int(parsedDate))
            # request data from last date time to today.
            today = int(time.strftime('%Y%m%d'))
            todayTime = int(time.strftime('%H%M%S'))

            if (today > lastDate) or (today == lastDate and todayTime > 153000) :
                #오후 3시까지가 장 시간이지만,
                #데이타 정리가 될 때까지 기다리는 시간을 감안하여
                #오후 3시 30분까지 기다렸다가 update하려 함.
                requestArg = [lastDate, today]
                print '(',lastDate,'-',today,')',
                result = self.updateDataList( chartType.value,
                                              u'period',
                                              requestArg,
                                              0,
                                              self.fieldDic.keys(),
                                              argStockCode )
            else :
                result = cxReturnValue(None, u'invalid period (%d-%d)'%(lastDate,today))

            bFirstWrite = False

        else :  # empty file means new file
            # update all. (from 1900 ~ )
            reqType = u'period'
            requestArg = [19900101,int(time.strftime('%Y%m%d'))]
            
            if chartType.value == u'M' or chartType.value == u'W' :  # month
                reqType = u'count'
                requestArg = 2048
            
            print requestArg,
            result = self.updateDataList( chartType.value,
                                          reqType,
                                          requestArg,
                                          0,
                                          self.fieldDic.keys(),
                                          argStockCode )
            bFirstWrite = True

        # writing result to file

        if result.result != u'ok' :
            dataFile.close()
            del dataFile
            return cxReturnValue(result.value, result.result)
        else :
            fieldNameList = []
            lineList = []
            bFirst = True
            for resultList in result.value :
                #print common.getResultStringPortrait( resultList, 1, 1, 1, 1 )
                for itemDic in resultList[6] :
                    valueList = []
                    for key in itemDic.keys() :
                        if bFirst == True :
                            fieldNameList.append(itemDic[key][1])
                        valueList.append(itemDic[key][2])
                    lineList.append(valueList)
                    if bFirst == True :
                        bFirst = False

            if len(lineList) == 0 :
                dataFile.close()
                del dataFile
                return cxReturnValue(None,u'no data')

            print len(lineList),

            if bFirstWrite == True :
                for fieldName in fieldNameList :
                    dataFile.write(common.UNI(fieldName)+u' ')
                dataFile.write(u'\n')
                bFirstWrite = False

            for i in range(len(lineList)-1,-1,-1) :
                for value in lineList[i] :
                    dataFile.write(common.UNI(value) + u' ')
                dataFile.write(u'\n')

        # write results to file with reverse order.
        dataFile.close()
        del dataFile
        return cxReturnValue(fileName)
Beispiel #8
0
    def updateDataList(self,
                       argChartType,        #[u'M',u'W',u'D',u'm',u'T']
                       argRequestType,      #요청방식:기간요청(u'period'),
                                            #         갯수요청(u'count')
                       argRequestArg,       #요청방식이 기간요청일 경우, list
                       argCorrPriceType,    #수정 주가 여부 [0,1]
                       argFieldList,
                       argStockCode ):

        chartTypeResult = self.getChartType(argChartType)
        if chartTypeResult.result != u'ok':
            return cxReturnValue(None, u'invalid argChartType "%s"'%argChartType)
        chartType = ord(chartTypeResult.value)

        #if argChartType in self.chartType.values() :
        #    chartType = ord(argChartType)
        #else :
        #    return cxReturnValue(None,
        #                         u'invalid argChartType "%s"'%argChartType)

        if argRequestType == u'P' or    \
            argRequestType == u'p' or   \
            argRequestType == u'Period' or  \
            argRequestType == u'period' :
            requestType = ord(u'1')
        elif argRequestType == u'C' or  \
            argRequestType == u'c' or   \
            argRequestType == u'Count' or \
            argRequestType == u'count'  :
            requestType = ord(u'2')
        else :
            return cxReturnValue(None,
                                 u'invalid argRequestType "%s"'%argRequestType)
        if requestType == ord(u'1') :
            if isinstance(argRequestArg,list) == False :
                return cxReturnValue(None,
                                    u'invalid argRequestArg : not list')
            else :
                startTime = argRequestArg[0]
                endTime = argRequestArg[1]
                #print '(',startTime,'-',endTime,')'
                #print type(startTime),type(endTime)
        if requestType == ord(u'2') :
            if isinstance(argRequestArg,int) == False :
                return cxReturnValue(None,
                                    u'invalid argReqeustArg : not int')
            else :
                count = argRequestArg
        if argCorrPriceType in [0, 1] :
            corrPriceType = ord(unicode(argCorrPriceType))
        else :
            return cxReturnValue(None,
                                 u'invalid argCorrPriceType "%d"'%argCorrPriceType)
        if argFieldList == [] or argFieldList == None :
            return cxReturnValue(None, u'invalid argFieldList')
        fieldList = self.getFieldList(argFieldList)
        if fieldList.result != u'ok' :
            return cxReturnValue(None, fieldList.value, fieldList.result)
        paramList = []
        if requestType == ord(u'1') :   #period
            paramList = [
                [ 0, argStockCode   ],
                [ 1, requestType    ],
                [ 2, endTime        ],
                [ 3, startTime      ],
                [ 5 ] + fieldList.value,
                [ 6, chartType      ],
                #[ 7, 1              ],  # 주기 (default - 1)
                [ 8, ord('0')       ],  # 갭보정여부 ('0'-갭무보정,'1'-갭보정)
                [ 9, corrPriceType  ],
                [10, ord(u'3')      ],  # 시간외 거래량 모두 제외
            ]
        else :  #requestType == ord('2')  #count
            paramList = [
                [ 0, argStockCode   ],
                [ 1, requestType    ],
                [ 4, count          ],
                [ 5 ] + fieldList.value,
                [ 6, chartType      ],
                #[ 7, 1              ],  # 주기 (default - 1)
                [ 8, ord('0')       ],  # 갭보정여부 ('0'-갭무보정,'1'-갭보정)
                [ 9, corrPriceType  ],
                [10, ord(u'3')      ],  # 시간외 거래량 모두 제외
            ]
        #print paramList
        #print 'argChartType=',argChartType
        stockChart = self.cpClsDic['cxStockChart']
        resultList = common.templateBlockRequest(stockChart, paramList)
        if resultList == None :
            return cxReturnValue(None, u'templateBlockRequest result is None')
        if len(resultList) == 0 :
            return cxReturnValue(None, u'templateBlockRequest result is []')

        return cxReturnValue(resultList, u'ok')