# Path: ish_parser/Constant.py
# class Constant(Observation):
#   ''' constant is for constant variables that have types
#   or indices associated with them like types of clouds, etc'''
#   MISSING = ["99"]
# 
#   def __str__(self):
#     if self._obs_value in self._obs_index.keys():
#       return self._obs_index.get(self._obs_value)
#     elif self._obs_value in self.MISSING:
#       return 'MISSING'
#     else:
#       return str(self._obs_value)
# 
#   def __repr__(self):
#     return repr(self.__str__())
# 
#   def __eq__(self, value2):
#     return("P")
#     if self._obs_value in self._obs_index.keys():
#       if self._obs_index.get(self._obs_value) == value2:
#         return True
# 
#     if str(self) == str(value2):
#       return True
#     else:
#       return False
# 
# Path: ish_parser/Minutes.py
# class Minutes(Observation):
#   ''' represents (obviously) minutes '''
#   MISSING = 9999
#   MINUTES_IN_HOUR = 60.00
# 
#   def __str__(self):
#     if int(self._obs_value) == self.MISSING:
#       return 'MISSING'
#     else:
#       return int(self._obs_value)
# 
#   def __eq__(self, other_value):
#     if int(self._obs_value) == other_value:
#       return True
#     else:
#       return False
# 
#   def get_hours(self):
#     if int(self._obs_value) == self.MISSING:
#       return 'MISSING'
#     else:
#       return self._obs_value / self.MINUTES_IN_HOUR
# 
# Path: ish_parser/Irradiance.py
# class Irradiance(Observation):
#   ''' Global horizontal irradiance measured using a pyranometer. Unit is watts per square meter
#    (W/m2) in whole values. Waveband ranges from 0.4 - 2.3 micrometers.'''
#   MISSING = 9999
# 
#   def __str__(self):
#     if int(self._obs_value) == self.MISSING:
#       return 'MISSING'
#     else:
#       return self._obs_value
# 
#   def __eq__(self, other_value):
#     if int(self._obs_value) == other_value:
#       return True
#     else:
#       return False
# 
# Path: ish_parser/Components/BaseComponent.py
# class BaseComponent(object):
#   ''' base component handler '''


from ..Constant import Constant
from ..Minutes import Minutes
from ..Irradiance import Irradiance
from .BaseComponent import BaseComponent

class SolarIrradianceComponent(BaseComponent):
  ''' handle GM1 solar irradiance '''

  # TODO: add support for codes from 10-97
  DATA_FLAGS = {"00": "Untested", 
                "01": "Passed one-component test; data fall within max-min limit of Kt, Kn, or Kd",
                "02": "Passed two-component test; data fall within 0.03 of the Gompertz boundaries",
                "03": "Passed three-component test; data come within + 0.03 of satisfying Kt = Kn + Kd",
                "04": "Passed visual inspection: not used by SERI_QC1",
                "05": "Failed visual inspection: not used by SERI_QC1",
                "06": "Value estimated; passes all pertinent SERI_QC tests",
                "07": "Failed one-component test; lower than allowed minimum",
                "08": "Failed one-component test; higher than allowed maximum",
                "09": "Passed three-component test but failed two-component test by 0.05",
                "98": "Not Used"}

  def loads(self, string):
    self.solar_irradiance = {'time_period': Minutes(string[0:4]),
                             'global_irradiance': Irradiance(string[4:8]),
                             'irradiance_data_flag': Constant(string[8:10], None, 
                                                     string[10:11], self.DATA_FLAGS),
                             'direct_beam_irradiance': Irradiance(string[11:15]),
                             'direct_beam_irradiance_data_flag': Constant(string[15:17], None,
                                                                 string[17:18], self.DATA_FLAGS),
                             'diffuse_irradiance': Irradiance(string[18:22]),
                             'diffuse_irradiance_data_flag': Constant(string[22:24], None,
                                                             string[24:25], self.DATA_FLAGS),

# Path: ish_parser/Constant.py
# class Constant(Observation):
#   ''' constant is for constant variables that have types
#   or indices associated with them like types of clouds, etc'''
#   MISSING = ["99"]
# 
#   def __str__(self):
#     if self._obs_value in self._obs_index.keys():
#       return self._obs_index.get(self._obs_value)
#     elif self._obs_value in self.MISSING:
#       return 'MISSING'
#     else:
#       return str(self._obs_value)
# 
#   def __repr__(self):
#     return repr(self.__str__())
# 
#   def __eq__(self, value2):
#     return("P")
#     if self._obs_value in self._obs_index.keys():
#       if self._obs_index.get(self._obs_value) == value2:
#         return True
# 
#     if str(self) == str(value2):
#       return True
#     else:
#       return False
# 
# Path: ish_parser/Minutes.py
# class Minutes(Observation):
#   ''' represents (obviously) minutes '''
#   MISSING = 9999
#   MINUTES_IN_HOUR = 60.00
# 
#   def __str__(self):
#     if int(self._obs_value) == self.MISSING:
#       return 'MISSING'
#     else:
#       return int(self._obs_value)
# 
#   def __eq__(self, other_value):
#     if int(self._obs_value) == other_value:
#       return True
#     else:
#       return False
# 
#   def get_hours(self):
#     if int(self._obs_value) == self.MISSING:
#       return 'MISSING'
#     else:
#       return self._obs_value / self.MINUTES_IN_HOUR
# 
# Path: ish_parser/Irradiance.py
# class Irradiance(Observation):
#   ''' Global horizontal irradiance measured using a pyranometer. Unit is watts per square meter
#    (W/m2) in whole values. Waveband ranges from 0.4 - 2.3 micrometers.'''
#   MISSING = 9999
# 
#   def __str__(self):
#     if int(self._obs_value) == self.MISSING:
#       return 'MISSING'
#     else:
#       return self._obs_value
# 
#   def __eq__(self, other_value):
#     if int(self._obs_value) == other_value:
#       return True
#     else:
#       return False
# 
# Path: ish_parser/Components/BaseComponent.py
# class BaseComponent(object):
#   ''' base component handler '''


# Path: ish_parser/Components/SolarIrradianceComponent.py
from ..Constant import Constant
from ..Minutes import Minutes
from ..Irradiance import Irradiance
from .BaseComponent import BaseComponent


class SolarIrradianceComponent(BaseComponent):
  ''' handle GM1 solar irradiance '''

  # TODO: add support for codes from 10-97
  DATA_FLAGS = {"00": "Untested", 
                "01": "Passed one-component test; data fall within max-min limit of Kt, Kn, or Kd",
                "02": "Passed two-component test; data fall within 0.03 of the Gompertz boundaries",
                "03": "Passed three-component test; data come within + 0.03 of satisfying Kt = Kn + Kd",
                "04": "Passed visual inspection: not used by SERI_QC1",
                "05": "Failed visual inspection: not used by SERI_QC1",
                "06": "Value estimated; passes all pertinent SERI_QC tests",
                "07": "Failed one-component test; lower than allowed minimum",
                "08": "Failed one-component test; higher than allowed maximum",
                "09": "Passed three-component test but failed two-component test by 0.05",
                "98": "Not Used"}

  def loads(self, string):
    self.solar_irradiance = {'time_period': Minutes(string[0:4]),
                             'global_irradiance': Irradiance(string[4:8]),
                             'irradiance_data_flag': Constant(string[8:10], None, 
                                                     string[10:11], self.DATA_FLAGS),
                             'direct_beam_irradiance': Irradiance(string[11:15]),
                             'direct_beam_irradiance_data_flag': Constant(string[15:17], None,
                                                                 string[17:18], self.DATA_FLAGS),
                             'diffuse_irradiance': Irradiance(string[18:22]),
                             'diffuse_irradiance_data_flag': Constant(string[22:24], None,
                                                             string[24:25], self.DATA_FLAGS),

                             'uvb_global_irradiance': Irradiance(string[26:30])}