'''
Take sanpshop of attributes at given times
'''

fdIn = open('multipleAttributes.txt', 'r')
fdOut0 = open('snapshot_0hour.txt', 'w')
fdOut6 = open('snapshot_6hour.txt', 'w')
fdOut12 = open('snapshot_12hour.txt', 'w')
fdOut18 = open('snapshot_18hour.txt', 'w')
fdOut24 = open('snapshot_24hour.txt', 'w')
fdOut36 = open('snapshot_36hour.txt', 'w')
fdOut5 = open('snapshot_5days.txt', 'w')
fdOut7 = open('snapshot_7days.txt', 'w')
fdOut14 = open('snapshot_14days.txt', 'w')
fdOutPeak = open('snapshot_peak.txt', 'w')

time0 = 1335139200
time6 = 1335139200 + 3600 * 6
time12 = 1335139200 + 3600 * 12
time18 = 1335139200 + 3600 * 18
time24 = 1335139200 + 3600 * 24
time36 = 1335139200 + 3600 * 36
time5 = 1335139200 + 86400 * 5.5
time7 = 1335139200 + 86400 * 7
time14 = 1335139200 + 86400 * 14 - 60
timePeak = 1335139200 + 527040

firstLine = False
for line in fdIn:
    if firstLine == False:
        firstLine = True
        fdOut0.write(line)
        fdOut6.write(line)
        fdOut12.write(line)
        fdOut18.write(line)
        fdOut24.write(line)
        fdOut36.write(line)
        fdOut5.write(line)
        fdOut7.write(line)
        fdOut14.write(line)
        fdOutPeak.write(line)
        continue
    tmp = line.split('\t')
    tmpTime = int(float(tmp[1]))
    tmpTime = int(round(tmpTime/60) * 60) #Round to nearest interval

    if tmpTime == time0: fdOut0.write(line)
    elif tmpTime == time6: fdOut6.write(line)
    elif tmpTime == time12: fdOut12.write(line)
    elif tmpTime == time18: fdOut18.write(line)
    elif tmpTime == time24: fdOut24.write(line)
    elif tmpTime == time36: fdOut36.write(line)
    elif tmpTime == time5: fdOut5.write(line)
    elif tmpTime == time7: fdOut7.write(line)
    elif tmpTime == time14: fdOut14.write(line)
    elif tmpTime == timePeak: fdOutPeak.write(line)

fdIn.close()
fdOut0.close()
fdOut6.close()
fdOut12.close()
fdOut18.close()
fdOut24.close()
fdOut36.close()
fdOut5.close()
fdOut7.close()
fdOut14.close()
fdOutPeak.close()
