Пример #1
0
 def dump(self):
     if self.data:
         path = os.path.join(conf.get("SYS_HOME",""),conf.get("REPORTER_DATA_PATH",REPORTER_DATA_PATH),self.date+SUFFIX)
         Dumper.dump(path = path , data = report.data)
         logging.info("Reporter result : %s" % str(report))
     else:
         logging.warning("Reporter run fail.")
Пример #2
0
    def collect(self,strategic = None ,statisticsProjectPath = None):
        """
        对于整体数据,缓存之前计算。对于指定策略,暂时只收集15日内数据,反映短期内变动情况。
        收集统计数据
        >> statistics.stock == testCase['stock']
        >> statistics.collect()
        
        收集指定策略统计数据
        >> statistics.stock == testCase['stock']
        >> statistics.collect(strategic = testCase['collectStrategic']) 

        @param {list} strategic  符合策略的code list
        """
        conf={}
        conf.update(self.conf)
        isCache = False
        data={}
        if strategic: #计算指定策略统计
            allCode = strategic #符合指定策略的 code 可通过strategic[date][strategicName]读出
            allDate = []
            for i in range(0,conf.get("MIN_DATA_NUM",MIN_DATA_NUM)):
                date=Date.getDate(0-i,conf.get('date',Date.getDate()))
                allDate.append(date)
        else:    #计算整体统计
            isCache = True
            allDate = self.stock.allDate
            allCode = self.stock.allCode

        if isCache: #读取之前统计缓存
            data = Reader.read(path = self.getDataPath(dataType = "cache"))
            for date in allDate:
                if date in data and date in allDate:
                    allDate.remove(date)
            
        conf.update({
            "date":self.date,
            "stock":self.stock,
            "allCode":allCode
        })

        expression=Expression(conf)
        statisticsProjectPath = statisticsProjectPath or os.path.join(conf.get("SYS_HOME"),conf.get("STATISTICS_PROJECT_PATH"))
        expressions = expression.load(path = statisticsProjectPath)
        for date in allDate:
            result={} #初始化result变量,让result能在公式里直接使用,并且result[name]也能使用
            for code in allCode:
                result[code]={}
            expression.execute(expression= conf.get("expressions",expressions), context = {"result":result,"date":date})
            if not result:
                break;
            data[date]=result
        if isCache:
            Dumper.dump(path = self.getDataPath(dataType = "cache"),data =data)
        return data
Пример #3
0
 def dump(self):
     """
     保存所有日期的统计结果,不保存各策略短期结果。
     """
     dataPath = self.getDataPath()
     Dumper.dump(path = dataPath , data =self.data)
Пример #4
0
 def dump(self,data,path = None):
     if not path:
         path = os.path.join(self.conf.get("SYS_HOME"),self.conf.get("STRATEGIC_DATA_PATH",STRATEGIC_DATA_PATH),self.date+SUFFIX)
     Dumper.dump(path = path,data = data)
     return True