import tensorflow as tf
sess = tf.InteractiveSession()

raw_data = [1., 2., 8., -1., 0., 5.5, 6., 13]
spikes = tf.Variable([False] * len(raw_data), name='spikes')
spikes.initializer.run()

"""
Explanation: Ch 02: Concept 06
Saving variables
Create an interactive session and initialize a variable:
End of explanation
"""


saver = tf.train.Saver()

"""
Explanation: The saver op will enable saving and restoring:
End of explanation
"""


for i in range(1, len(raw_data)):
    if raw_data[i] - raw_data[i-1] > 5:
        spikes_val = spikes.eval()
        spikes_val[i] = True
        updater = tf.assign(spikes, spikes_val)
        updater.eval()

"""
Explanation: Loop through the data and update the spike variable when there is a significant increase:
End of explanation
"""


save_path = saver.save(sess, "./spikes.ckpt")
print("spikes data saved in file: %s" % save_path)

"""
Explanation: Now, save your variable to disk!
End of explanation
"""


sess.close()

"""
Explanation: Adieu:
End of explanation
"""


