Ejemplo n.º 1
0
def get_result_path():
    cur_dir = get_root_path()
    dir_path = 'datas/' + MyCode.get() + '/'
    cur_dir += '/'
    cur_dir += dir_path
    agl.createDir(cur_dir)
    return cur_dir
Ejemplo n.º 2
0
def run():
    fpath = env.get_root_path()
    for code in stock.get_codes():
        fname = '/datasources/%s.csv' % (code)
        fname = fpath + fname
        df = stock.getFiveHisdatDf(code)
        df.to_csv(fname)
Ejemplo n.º 3
0
def load_user_info():
    """json [user,pwd]"""
    fname = os.path.abspath(get_root_path()+'/../notify/'+'info.json')
    f = open(fname, 'r')
    t = str(f.read())
    f.close()
    t = t.replace('\t','')
    t = t.replace('\n', '')
    return json.loads(t)
Ejemplo n.º 4
0
 def __init__(self, reinit=False):
     self.fname = os.path.join(env.get_root_path(), 'datas', self.fname)
     if os.path.exists(self.fname) and reinit == False:
         self.df = pd.read_csv(self.fname)
         #print(self.df)
     else:
         result = self._initLabeDescTable()
         self.df = pd.DataFrame(result)
         self.df.to_csv(self.fname)
         print(self.df)
         print('write label_desc_table')
Ejemplo n.º 5
0
 def getLocal(code):
     import pandas as pd
     from autoxd.cnn_boll import env
     fname = '../datas/%s.csv' % (code)
     fname = env.get_root_path() + '/datas/%s.csv' % (code)
     import os
     print(os.path.abspath(fname))
     df = pd.read_csv(fname)
     df.index = pd.DatetimeIndex(df[df.columns[0]])
     df = stock.TDX_BOLL_df(df)
     return df
Ejemplo n.º 6
0
def genImgToFile(code):
    """产生图形到文件
    """
    datas = load_data()
    #    indexs: list 数据偏移索引
    df = pd.read_csv(get_result_csv_path(), index_col=0)
    indexs = df['datas_index'].values
    cur_dir = get_root_path()
    fname = cur_dir + '/img_labels/imgs'
    if not os.path.exists(fname):
        agl.createDir(fname)
    for i in indexs:
        i = int(i)
        fname1 =fname + '/%s_%d.png'%(code, i)
        print(fname1)
        pl.figure
        draw(datas[i])
        pl.savefig(fname1)
        pl.close()
Ejemplo n.º 7
0
def load_data(num=-1, method='img'):
    """加载imgs
    method: str img/data
    return: (x_train, y_train), (x_test, y_test)
    x_train, np.dnarray  (num, row, col)
    y_train, (num, [0,0,0,1,0,0]) 分类标签
    """
    img_path = os.path.join(env.get_root_path(), 'img_labels/imgs/')
    files = os.listdir(img_path)
    files = files[:num]
    datas = None
    pre_code = ''
    imgs = []
    labels = []
    n = 28
    label_converter = Label2Id()
    for f in files:
        fname = img_path + f
        #label
        #这里和pearson_clust里的数据加载有区别, 这里是遍历
        f = f.split('.')[0]
        code, datas_index = str(f).split('_')
        print(code)
        datas_index = int(datas_index)
        label_path = os.path.join(env.get_root_path(),
                                  ('datas/%s/%s') % (code, g_fname_csv))
        #... 等待人工标签结果, 人工标签最后再进行归类
        table_colmns = "id,datas_index,code,dt,tick_period,clust_id,label_id,label_desc".split(
            ',')
        df = pd.read_csv(label_path)
        label = df[df[table_colmns[1]] == int(datas_index)]
        label_id = np.nan
        if len(label) > 0:
            label = label[table_colmns[-1]].values[0]
            if isinstance(label, str) and label[-1] == ',':
                label = label[:-1]
            label_id = label_converter.label_desc_to_label_id(label)
        labels.append(label_id)

        #img
        if method == 'img':
            img = cv2.imread(fname, cv2.IMREAD_GRAYSCALE)
            img = cv2.resize(img, (64 * 3, 48 * 3))
            img = np.array(img)
            img[img == 255] = 0
        if method == 'data':
            if pre_code != code:
                datas = main_load_data(code)
            #归一化
            bolls = datas[datas_index]
            img = BollsToImg(bolls)
            img = img.astype(np.uint8)
            #print(img)
        imgs.append(img)

    #for i in range(5):
    #imgs += imgs
    #labels += labels
    data = np.array(imgs)
    labels = np.array(labels).astype(np.uint8)
    len_data = len(data)
    len_labels = len(labels)
    assert (len_data == len_labels)
    split_len_pos = int(len_data * 0.8)
    return (data[:split_len_pos],
            labels[:split_len_pos]), (data[split_len_pos:],
                                      labels[split_len_pos:])
Ejemplo n.º 8
0
 def _getPath(self):
     """数据源目录
     """
     sources_path = env.get_root_path() + '/cnn_boll/datasources/'
     return sources_path
Ejemplo n.º 9
0
 def _get_datas_dir(self):
     #cur_dir = os.path.abspath(os.path.dirname(sys.argv[0]) + '/..')
     cur_dir = env.get_root_path()
     cur_dir += '/datas'
     return cur_dir
Ejemplo n.º 10
0
 def _getPath(self):
     """数据源目录
     """
     sources_path = 'datasources/'
     data_path = env.get_root_path()
     return data_path + '/' + sources_path