Example #1
0
 def serialAuto(fn, *args, **kwargs):
     """对于大数据, 进行dump到数据目录, 统一序列化和反序列化
     fn: 数据获取的过程, [注意], 这是函数指针,不要带括号, fn返回的值即保存的值
     **kwargs : restart=True 先删除原来的文件, 亦即重新来一遍
     fname='' 指定文件名
     return: 数据, 例如df"""
     #命名方式,v1 调用的函数名+参数+调用次数
     #v2, 调用文件名+函数名
     #fname = 'datas/'+fn.__name__+str(*args)+str(SerialMgr.count)+'.searial'
     #fname = 'datas/'+fn.__name__+str(*args)+'.searial'
     caller_name = getCallerName()
     fname = 'datas/' + caller_name + '.searial'
     if 'fname' in kwargs.keys():
         fname = 'datas/' + kwargs[fname] + '.searial'
     #删除文件
     if 'restart' in kwargs.keys():
         if kwargs['restart'] == True:
             if help.FileExist(fname):
                 help.FileDelete(fname)
             else:
                 fname = str(fname).replace('.searial', '.df')
                 if help.FileExist(fname):
                     help.FileDelete(fname)
     result = SerialMgr.unserial(fname)
     if result is None:
         SerialMgr.count += 1
         result = fn(*args)
         SerialMgr.serial(result, fname)
     #print '[serial]:',fname
     return result
Example #2
0
 def unserial(self):
     #强制重新开始
     if not help.FileExist(self.fpath):
         self.pre_price = 0
         return
     a = np.loadtxt(self.fpath, delimiter=',')
     if len(a) > 0:
         #if len(a[0])>0:
         #print 'unserial', a[0]
         self.prices_traded.prices = a[:-2]
         self.pre_price = a[-2]
         self.first_buy_price = a[-1]
     else:
         self.pre_price = 0
Example #3
0
 def DelSerial(code):
     """当回测时需要先删除serial"""
     fpath = help.getPythonPath() + "/datas/qjjy/back/" + code + ".serial"
     if help.FileExist(fpath):
         help.FileDelete(fpath)