'''
Test dataset to determine what values to use in simulations
'''

fdIn = open('SReadings_corrected.txt', 'r')
#fdIn = open('subsetSensors_remMiss.txt', 'r')
attNames = []
mini = None
maxi = None
firstLine = True
nIDs = {}
readings = {}
someMiss = [] #Stations where someof the samples are missing

for line in fdIn:
    l = line.split('\t')
    if firstLine == True:
        attNames = l
        firstLine = False
        mini = [99999999] * len(l)
        maxi = [-2] * len(l)
        continue

    if l[0] not in readings: readings[l[0]] = l
    else:
        if l[2] == '-1' and readings[l[0]][2] != '-1' or l[2] != '-1' and readings[l[0]][2] == '-1': 
            if l[0] not in someMiss: someMiss.append(l[0])
        if l[3] == '-1' and readings[l[0]][3] != '-1' or l[3] != '-1' and readings[l[0]][3] == '-1':
            if l[0] not in someMiss: someMiss.append(l[0])
        if l[4] == '-1' and readings[l[0]][4] != '-1' or l[4] != '-1' and readings[l[0]][4] == '-1':
            if l[0] not in someMiss: someMiss.append(l[0])
        if l[5] == '-1' and readings[l[0]][5] != '-1' or l[5] != '-1' and readings[l[0]][5] == '-1':
            if l[0] not in someMiss: someMiss.append(l[0])
        if l[6] == '-1' and readings[l[0]][6] != '-1' or l[6] != '-1' and readings[l[0]][6] == '-1':
            if l[0] not in someMiss: someMiss.append(l[0])
        if l[7] == '-1' and readings[l[0]][7] != '-1' or l[7] != '-1' and readings[l[0]][7] == '-1':
            if l[0] not in someMiss: someMiss.append(l[0])
        if l[8] == '-1' and readings[l[0]][8] != '-1' or l[8] != '-1' and readings[l[0]][8] == '-1':
            if l[0] not in someMiss: someMiss.append(l[0])
        if l[9] == '-1' and readings[l[0]][9] != '-1' or l[9] != '-1' and readings[l[0]][9] == '-1':
            if l[0] not in someMiss: someMiss.append(l[0])
        readings[l[0]] = l

    t = int(l[1])
    if l[0] in nIDs:
        td = t - nIDs[l[0]][0]
        if td not in nIDs[l[0]][1]: nIDs[l[0]][1].append(td)
        nIDs[l[0]][0] = t
    else: nIDs[l[0]] = [t, []]
    for i in range(len(l)):
        if not l[i].strip(): continue
        if i == 19 or i == 20: continue
        v = float(l[i])
        if v < mini[i]: mini[i] = v
        if v > maxi[i]: maxi[i] = v
fdIn.close()

for i in someMiss:
    print '--', i

print '\n\n'
for i in range(len(attNames)):
    print 'xx', attNames[i], mini[i], maxi[i] 

print '\n\n'
for i in nIDs:
    print '**', i, nIDs[i][1]
