import processData
import goodweData
import copy
import processData2
import numpy as np
import matplotlib.pyplot as pl
import pvoutput

class test:
   
   def do_tests( self):
      print "test_1"
      self.test_1()
      print "test_2"
      self.test_2()
      print "test_3"
      self.test_3()
      print "test_4"
      self.test_4()
      print "test_5"
      self.test_5()
      print "test_6"
      self.test_6()
      
   def test_1( self):
      gw1 = goodweData.goodweData('id="tab_big"><tr></tr><tr class=\"DG_Item\"><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0/1.0<c/td><td>1.0/1.0</td><td>1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0/1.0/1.0</td><td>1.0</td><td>1.0</td></tr>')
      s1 = gw1.get_sample()
      
      s1.set_inverter_sn( 1)
      s1.set_vpv(0,  1.0)
      s1.set_vpv(1,  1.0)
      s1.set_ipv(0,  1.0)
      s1.set_ipv(1,  1.0)
      s1.set_vac(0,  1.0)
      s1.set_vac(1,  1.0)
      s1.set_vac(2,  1.0)
      s1.set_iac(0,  1.0)
      s1.set_iac(1,  1.0)
      s1.set_iac(2,  1.0)
      s1.set_fac(0,  1.0)
      s1.set_fac(1,  1.0)
      s1.set_fac(2,  1.0)
      s1.set_pgrid( 1.0)
      s1.set_eday( 1.0)
      s1.set_etotal( 1.0)
      s1.set_htotal( 1.0)
      s1.set_temperature( 1.0)

      s2 = copy.deepcopy(s1)
      s2.set_inverter_sn( 2)
      s3 = copy.deepcopy(s1)
      s3.set_inverter_sn( 3)
      s4 = copy.deepcopy(s1)
      s4.set_inverter_sn( 4)
      s5 = copy.deepcopy(s1)
      s5.set_inverter_sn( 5)
      s6 = copy.deepcopy(s1)
      s6.set_inverter_sn( 6)
      s10 = copy.deepcopy(s1)

      s10.set_inverter_sn( 10)
      s10.set_vpv(0,  10.0)
      s10.set_vpv(1,  10.0)
      s10.set_ipv(0,  10.0)
      s10.set_ipv(1,  10.0)
      s10.set_vac(0,  10.0)
      s10.set_vac(1,  10.0)
      s10.set_vac(2,  10.0)
      s10.set_iac(0,  10.0)
      s10.set_iac(1,  10.0)
      s10.set_iac(2,  10.0)
      s10.set_fac(0,  10.0)
      s10.set_fac(1,  10.0)
      s10.set_fac(2,  10.0)
      s10.set_pgrid( 10.0)
      s10.set_eday( 10.0)
      s10.set_etotal( 10.0)
      s10.set_htotal( 10.0)
      s10.set_temperature( 10.0)

      s11 = copy.deepcopy(s10)
      s11.set_inverter_sn( 11)

      s12 = copy.deepcopy(s10)
      s12.set_inverter_sn( 12)
      
      process = processData.processData(None)
      process.reset()
      print "State:" + process.state_to_string()
      process.processSample( s1)
      print "State:" + process.state_to_string()
      process.processSample( s2)
      print "State:" + process.state_to_string()
      process.processSample( s3)
      print "State:" + process.state_to_string()
      process.processSample( s4)
      print "State:" + process.state_to_string()
      process.processSample( s10)
      print "State:" + process.state_to_string()
      process.processSample( s11)
      print "State:" + process.state_to_string()
      process.processSample( s5)
      print "State:" + process.state_to_string()
      process.processSample( s6)
      print "State:" + process.state_to_string()
      process.processSample( s12)
      print "State:" + process.state_to_string()
      process.reset()
      print "State:" + process.state_to_string()


   def test_2( self):
      with open('OfflineResponse.html', 'r') as f:
         response = f.read()
      
      gw1 = goodweData.goodweData(response)
      s1 = gw1.get_sample()
      print s1.to_string()
      
      if s1.is_online():
	 raise ValueError("Error, inverter should be offline")


   def test_3( self):
      with open('OnlineResponse.html', 'r') as f:
         response = f.read()
      
      gw1 = goodweData.goodweData(response)
      s1 = gw1.get_sample()
      print s1.to_string()
      
      if not s1.is_online():
	 raise ValueError("Error, inverter should be online")


   def test_4( self):
      proc = processData2.processData2(None)

      gw1 = goodweData.goodweData('id="tab_big"><tr></tr><tr class=\"DG_Item\"><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0/1.0<c/td><td>1.0/1.0</td><td>1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0/1.0/1.0</td><td>1.0</td><td>1.0</td></tr>')
      s1 = gw1.get_sample()
      
      s2 = copy.deepcopy(s1)
      s3 = copy.deepcopy(s1)
      s4 = copy.deepcopy(s1)
      s5 = copy.deepcopy(s1)
      s6 = copy.deepcopy(s1)
      s7 = copy.deepcopy(s1)
      s8 = copy.deepcopy(s1)
      s9 = copy.deepcopy(s1)
      s10 = copy.deepcopy(s1)

      s1.set_pgrid( 1.0)
      s2.set_pgrid( 2.0)
      s3.set_pgrid( 3.0)
      s4.set_pgrid( 4.0)
      s5.set_pgrid( 5.0)
      s6.set_pgrid( 6.0)
      s7.set_pgrid( 7.0)
      s8.set_pgrid( 8.0)
      s9.set_pgrid( 9.0)
      s10.set_pgrid( 10.0)
      xx = []
      x = np.array([ 0,0,0,0,0,1.0,1.0,1.0,1.0,2.0,3.0,4.0,4.0,5.0,6.0,6.0,7.0,8.0,9.0,9.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,9.0,8.0,7.0,7.0,6.0,5.0,5.0,4.0,3.0,3.0,2.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0])
      y = np.array([ 1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16,  17,  18,  19,  20,  21,  22,  23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45])
      proc.processSample(s1)
      xx.append(0)
      proc.processSample(s1)
      xx.append(0)
      proc.processSample(s1)
      xx.append(0)
      proc.processSample(s1)
      xx.append(0)
      proc.processSample(s2)
      xx.append(0)
      proc.processSample(s3)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s4)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s4)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s5)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s6)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s6)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s7)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s8)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s9)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s9)
      xx.append(proc.getSample('pgrid'))

      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))

      proc.processSample(s9)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s8)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s7)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s7)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s6)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s5)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s5)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s4)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s3)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s3)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s2)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      xx.append(1.0)
      xx.append(1.0)
      xx.append(1.0)
      xx.append(1.0)
      xx.append(1.0)
      xxx = np.array(xx)
      
      pl.figure()
      pl.plot(y,x)
      pl.plot(y,xxx)
      pl.show()


   def test_5( self):
      proc = processData2.processData2(None)

      gw1 = goodweData.goodweData('id="tab_big"><tr></tr><tr class=\"DG_Item\"><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0/1.0<c/td><td>1.0/1.0</td><td>1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0/1.0/1.0</td><td>1.0</td><td>1.0</td></tr>')
      s1 = gw1.get_sample()
      
      s2 = copy.deepcopy(s1)
      s3 = copy.deepcopy(s1)
      s4 = copy.deepcopy(s1)
      s5 = copy.deepcopy(s1)
      s6 = copy.deepcopy(s1)
      s7 = copy.deepcopy(s1)
      s8 = copy.deepcopy(s1)
      s9 = copy.deepcopy(s1)
      s10 = copy.deepcopy(s1)

      s1.set_pgrid( 15.0)
      s2.set_pgrid( 120.0)
      s3.set_pgrid( 300.0)
      s4.set_pgrid( 49.0)
      s5.set_pgrid( 500.0)
      s6.set_pgrid( 600.0)
      s7.set_pgrid( 70.0)
      s8.set_pgrid( 1800.0)
      s9.set_pgrid( 1900.0)
      s10.set_pgrid( 1054.0)
      xx = []
      x = np.array([ 0,0,0,0,0,15.0,15.0,15.0,15.0,120.0,300.0,49.0,49.0,500.0,600.0,600.0,70.0,1800.0,1900.0,1900.0,1054.0,1054.0,1054.0,1054.0,1054.0,1054.0,1054.0,1900.0,1800.0,70.0,70.0,600.0,500.0,500.0,49.0,300.0,300.0,120.0,15.0,15.0,15.0,15.0,15.0,15.0,15.0])
      y = np.array([ 1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16,  17,  18,  19,  20,  21,  22,  23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45])
      proc.processSample(s1)
      xx.append(0)
      proc.processSample(s1)
      xx.append(0)
      proc.processSample(s1)
      xx.append(0)
      proc.processSample(s1)
      xx.append(0)
      proc.processSample(s2)
      xx.append(0)
      proc.processSample(s3)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s4)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s4)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s5)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s6)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s6)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s7)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s8)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s9)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s9)
      xx.append(proc.getSample('pgrid'))

      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s10)
      xx.append(proc.getSample('pgrid'))

      proc.processSample(s9)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s8)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s7)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s7)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s6)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s5)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s5)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s4)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s3)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s3)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s2)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      proc.processSample(s1)
      xx.append(proc.getSample('pgrid'))
      xx.append(1.0)
      xx.append(1.0)
      xx.append(1.0)
      xx.append(1.0)
      xx.append(1.0)
      xxx = np.array(xx)
      print x
      print xxx
      
      pl.figure()
      pl.plot(y,x)
      pl.plot(y,xxx)
      pl.show()
   
      
   def test_6( self):
      out = pvoutput.pvoutput( "http://testURL", "InvalidSystemID", "NoAPIkey")

      gw1 = goodweData.goodweData('id="tab_big"><tr></tr><tr class=\"DG_Item\"><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0/1.0<c/td><td>1.0/1.0</td><td>1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0/1.0/1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0</td><td>1.0/1.0/1.0</td><td>1.0</td><td>1.0</td></tr>')
      s1 = gw1.get_sample()
      print s1.to_string()
      
      out.post_data(s1)

if __name__ == "__main__":
   t = test()
   t.do_tests()

#---------------- End of file ------------------------------------------------
