import tensorflow as tf
import numpy as np
import pandas as pd
from sklearn.cross_validation import train_test_split



X=pd.read_excel('Raw.xlsx',header=None)
X=np.array(X)



def weight_variable(shape):
    initial=tf.truncated_normal(shape,stddev=0.1)
    return tf.Variable(initial)

def bias_variable(shape):
    initial=tf.constant(0.1,shape=shape)
    return tf.Variable(initial)

def conv1d(x,W):
    #strides=[1,x_movement,y_movement,1]
    
    return tf.nn.conv1d(x,W,stride=1,padding='SAME')

def pool(x):
    #strides=[1,x_movement,y_movement,1]
    return tf.nn.pool(x,window_shape=[2],pooling_type='MAX',padding='SAME',strides=[2])

#define placeholder for inputs to network
xs=tf.placeholder(tf.float32,[None,25])
ys=tf.placeholder(tf.float32,[None,1])
keep_prob=tf.placeholder(tf.float32)
x_image=tf.reshape(xs,[-1,25,1])
#print(x_image.shape)#[n_samples,7,1]


##conv1 layer
W_conv1=tf.Variable(np.zeros([6,1,16]),dtype=tf.float32)
b_conv1=tf.Variable(np.zeros([16]),dtype=tf.float32)
h_conv1=tf.nn.relu(conv1d(x_image,W_conv1)+b_conv1)
h_pool1=pool(h_conv1)

##conv2 layer
W_conv2=tf.Variable(np.zeros([4,16,32]),dtype=tf.float32)
b_conv2=tf.Variable(np.zeros([32]),dtype=tf.float32)
h_conv2=tf.nn.relu(conv1d(h_pool1,W_conv2)+b_conv2)
h_pool2=pool(h_conv2)
##conv3 layer
W_conv3=tf.Variable(np.zeros([4,32,64]),dtype=tf.float32)
b_conv3=tf.Variable(np.zeros([64]),dtype=tf.float32)
h_conv3=tf.nn.relu(conv1d(h_pool2,W_conv3)+b_conv3)
h_pool3=pool(h_conv3)
##func1 layer
W_fc1=tf.Variable(np.zeros([4*64,1024]),dtype=tf.float32)
b_fc1=tf.Variable(np.zeros([1024]),dtype=tf.float32)
#[n_sample,7,7,64]->>[n_sample,7*7*64]
h_pool2_flat=tf.reshape(h_pool3,[-1,4*64])
h_fc1=tf.nn.relu(tf.matmul(h_pool2_flat,W_fc1)+b_fc1)
h_fc1_drop=tf.nn.dropout(h_fc1,keep_prob)

##func2 layer
W_fc2=tf.Variable(np.zeros([1024,1]),dtype=tf.float32)
b_fc2=tf.Variable(np.zeros([1]),dtype=tf.float32)
prediction=tf.matmul(h_fc1_drop,W_fc2)+b_fc2


saver=tf.train.Saver()

with tf.Session() as sess:
    saver.restore(sess,"SyncScreener/saver_bet.ckpt")
    
    s=np.zeros((1009,1),dtype=float)          
    for i in range(1009):       
   
            b=np.zeros((25,1),dtype=float)
            
            dd=np.zeros((1,25),dtype=float)
            #b=X[:,i]
            b=X[i,:]
            
                        #print(b)

            
            
            #bb([i,])=np.array(b[i,:])
            dd=b.reshape((1,25))
            #print(dd)
            print(sess.run(prediction,feed_dict={xs:dd,keep_prob:1}))

            
    
            
            s[i]=sess.run(prediction,feed_dict={xs:dd,keep_prob:1})

np.savetxt("Prediction.txt",s)

