'''
Take sanpshop of attributes at given times
use to find correlation
'''

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')
fdOut24 = open('snapshot_24hour.txt', 'w')
fdOut7 = open('snapshot_7days.txt', 'w')
fdOut14 = open('snapshot_14days.txt', 'w')
fdOutAll = open('selectedAttribs.txt', 'w')
considerAll = True

time0 = 0
time6 = 3600 * 6
time12 = 3600 * 12
time24 = 3600 * 24
time7 = 86400 * 7
time14 = 1209300.0
firstLine = False
for line in fdIn:
    if firstLine == False:
        firstLine = True
        tmpStr = 'nid\ttime\tCSp\tNCore\tCFree\t1mLd\t5mLd\t15mLd\tMSize\tMFree\tMFree%\tDSize\tDFree\tTx\tRx\tRspT\n'
        fdOut0.write(tmpStr)
        fdOut6.write(tmpStr)
        fdOut12.write(tmpStr)
        fdOut24.write(tmpStr)
        fdOut7.write(tmpStr)
        fdOut14.write(tmpStr)
        fdOutAll.write(tmpStr)
        continue
    tmp = line.split('\t')
    tmpTime = int(float(tmp[2]))
    if tmpTime == time0 or tmpTime == time6 or tmpTime == time12 or \
            tmpTime == time24 or tmpTime == time7 or tmpTime == time14 or considerAll:
        data = [tmp[0], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7], tmp[8], tmp[9],\
        #MFree in GB
           str(float(tmp[9]) * float(tmp[10])/100), \
           tmp[10], tmp[11], tmp[12], tmp[13], tmp[14], tmp[19]]
        useful = True
        tmpStr = ''
        for i in range(len(data)): #Skip missing data
            if '-' in data[i]: 
                useful = False
                break
            if i == len(data) -1: #Last one
                tmpStr += data[i]
            else: tmpStr += data[i] + '\t'
        tmpStr += '\n'
    
        if useful == False: continue
        if tmpTime == time0: fdOut0.write(tmpStr)
        elif tmpTime == time6: fdOut6.write(tmpStr)
        elif tmpTime == time12: fdOut12.write(tmpStr)
        elif tmpTime == time24: fdOut24.write(tmpStr)
        elif tmpTime == time7: fdOut7.write(tmpStr)
        elif tmpTime == time14: fdOut14.write(tmpStr)
        fdOutAll.write(tmpStr)

fdIn.close()
fdOut0.close()
fdOut6.close()
fdOut12.close()
fdOut24.close()
fdOut7.close()
fdOut14.close()
fdOutAll.close()
