from stock import cnn_predict
from stock import dnn_predict
from stock import kmeans


def dnn_and_kmeans():
    # cnn_result = cnn_predict.predict()
    dnn_result = dnn_predict.predict(file_path='D:\\data\\quantization\\stock6_5_test.log', model_path='5d_dnn_seq.h5')
    cnn_result = kmeans.class_fic(file_path="D:\\data\\quantization\\stock2_20.log")
    print('计算完成')

    with open('dnn_and_kmeans.txt', 'a') as f:
        up_num = 0
        up_right = 0
        i = 0
        for m in cnn_result: #3位 时间是字符串
            # print('find', m)
            for n in dnn_result: #5位 时间是int
                if m[0][0] == n[0][0] and int(m[0][1]) == n[0][1]:
                    print('AND', m)
                    f.write(str(m) + '\n')

                    if n[1][0] == 1:
                        up_right = up_right + 1.13
                    elif n[1][1] == 1:
                        up_right = up_right + 1.05
                    elif n[1][2] == 1:
                        up_right = up_right + 1
                    else:
                        up_right = up_right - 0.15
                    up_num = up_num + 1
                    i = i + 1

                    break

    print(up_right, up_num, up_right / up_num)


def and_predict():
    # cnn_result = cnn_predict.predict()
    dnn_result = dnn_predict.predict(file_path='D:\\data\\quantization\\stock6_5_test.log', model_path='5d_dnn_seq.h5')
    cnn_result = dnn_predict.predict(file_path='D:\\data\\quantization\\stock6_test.log', model_path='15m_dnn_seq.h5')
    print('计算完成')

    with open('and_predict.txt', 'a') as f:
        up_num = 0
        up_right = 0
        i = 0
        for m in cnn_result: #3位 时间是字符串
            # print('find', m)
            for n in dnn_result: #5位 时间是int
                if m[0][0] == n[0][0] and int(m[0][1][:10].replace('-', '')) == n[0][1]:
                    print('AND', m, n)
                    f.write(str(m) + '\n')

                    if n[1][0] == 1:
                        up_right = up_right + 1
                    elif n[1][1] == 1:
                        up_right = up_right + 0.2
                    up_num = up_num + 1
                    i = i + 1

                    break

    print(up_right, up_num, up_right / up_num)

if __name__ == '__main__':
    # and_predict()
    dnn_and_kmeans()