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

fdIn = open('selectedAttribs.txt', 'r')
#fdIn = open('resources_raw_01_14.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')
fdOut65 = open('snapshot_6.5days.txt', 'w')
fdOut7 = open('snapshot_7days.txt', 'w')
fdOut14 = open('snapshot_14days.txt', 'w')
fdOutPeak = open('snapshot_peak.txt', 'w')

time0 = 0
time6 = 3600 * 6
time12 = 3600 * 12
time18 = 3600 * 18
time24 = 3600 * 24
time36 = 3600 * 36
time65 = 86400 * 6.5
time7 = 86400 * 7
time14 = 1209300.0
timePeak = 155100.0
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)
        fdOut65.write(line)
        fdOut7.write(line)
        fdOut14.write(line)
        fdOutPeak.write(line)
        continue
    tmp = line.split('\t')
    tmpTime = int(float(tmp[1]))
    #tmpTime = int(float(tmp[2]))
    tmpTime = int(round(tmpTime/300) * 300) #Round to nearest interval
    #Use following to extract all attributes
    if tmpTime == time0: 
        fdOut0.write(line)
        #fdOut0.write(str(float(tmp[9]) * float(tmp[10])/100) + '\n')
    elif tmpTime == time6: 
        fdOut6.write(line)
        #fdOut6.write(str(float(tmp[9]) * float(tmp[10])/100) + '\n')
    elif tmpTime == time12: 
        fdOut12.write(line)
        #fdOut12.write(str(float(tmp[9]) * float(tmp[10])/100) + '\n')
    elif tmpTime == time18: 
        fdOut18.write(line)
    elif tmpTime == time24: 
        fdOut24.write(line)
        #fdOut24.write(str(float(tmp[9]) * float(tmp[10])/100) + '\n')
    elif tmpTime == time36: 
        fdOut36.write(line)
        #fdOut36.write(str(float(tmp[9]) * float(tmp[10])/100) + '\n')
    elif tmpTime == time65: 
        fdOut65.write(line)
        #fdOut6.write(str(float(tmp[9]) * float(tmp[10])/100) + '\n')
    elif tmpTime == time7: 
        fdOut7.write(line)
        #fdOut7.write(str(float(tmp[9]) * float(tmp[10])/100) + '\n')
    elif tmpTime == time14: 
        fdOut14.write(line)
        #fdOut14.write(str(float(tmp[9]) * float(tmp[10])/100) + '\n')
    elif tmpTime == timePeak: 
        fdOutPeak.write(line)
        #fdOutPeak.write(str(float(tmp[9]) * float(tmp[10])/100) + '\n')

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