import keras
# -*- encoding:utf-8 -*-
import numpy as np
from keras.models import Sequential
from keras.layers import Dense,Dropout
import random
from keras.models import load_model

lines = []
def read_data(path):
    with open(path) as f:
        for line in f.readlines()[:]:
            lines.append(eval(line.strip()))

    train_x=[s[:-2] for s in lines]
    train_y=[s[-1] for s in lines]
    return np.array(train_x),np.array(train_y)


def predict():
    test_x,test_y=read_data("D:\\data\\quantization\\stock6_test.log")
    test_x = test_x.reshape(test_x.shape[0], 1,80,5)

    path="15min_cnn_seq.h5"
    model=load_model(path)
    score = model.evaluate(test_x, test_y)
    print('CNN', score)

    result=model.predict(test_x)
    # print(result)

    up_num = 0
    up_right = 0
    i = 0
    for r in result:
        fact = test_y[i]
        if r[0] > 0.5:
            if fact[0] == 1:
                up_right = up_right + 1
            elif fact[1] == 1:
                up_right = up_right + 0.2
            up_num = up_num + 1

        i = i + 1
    print('CNN', up_right, up_num, up_right/up_num) # 预测涨的正确率

    i = 0
    win_dnn = []
    for r in result:
        if r[0] > 0.5:
            # print(lines[i][-2])
            win_dnn.append([lines[i][-2], lines[i][-1]])
        i = i + 1

    return win_dnn


if __name__ == '__main__':
    predict()

