# -*- coding: utf-8 -*-
import process_data
from matplotlib import pyplot as plt

file_name = 'test.csv' # Pass på å bruke riktig datasett

analyzer = process_data.PowerConsumptionAnalyzer(file_name)

# analyzer.write_max('test_worksheet')

# analyzer.close_wb()

month = analyzer.get_month(2013, 2)

sorted_month = month.sort_values(ascending=False)

print month.shape # formatet på month (antall dager, antall timer)

print month[1] # dag 1, hver time (24t), format: liste

#print month[1, 5] # dag 1, time 5 


#plt.plot(range(1,25), month[1], label='1')
#plt.plot(range(1,25), month[2], label='2')
#plt.plot(range(1,25), month[3], label='3')




print sorted_month[:15]
target_value = sorted_month[0]*0.8 # 80% av maks
print 'Target value:', target_value

antall=0
for hour in sorted_month:
    if hour < target_value: break 
    print hour    
    antall = antall+1

print 'Antall:', antall

neighbor_hours = analyzer.get_neighbor_hours(sorted_month[:antall], return_single=True)

print neighbor_hours

print "Target value: ", target_value

for nh, top in zip(neighbor_hours, sorted_month[:antall]):
    good_top=False
    diff_top = top-target_value
    diff_0 = target_value-nh[0]
    if diff_0 < 0:
        diff_0 = 0
    diff_1 = target_value-nh[1]
    if diff_1 < 0:
        diff_1 = 0
    if diff_top < diff_0 + diff_1:
        good_top = True
    print nh[0], top, nh[1], good_top

plt.plot(process_data.date_index(month), month, 's-')

#plt.legend()
#plt.suptitle('Januar 2014') # figurtittel
#plt.xlabel('Dato')
plt.ylabel('kWh')
plt.show()