コード例 #1
0
 def taf_status(self, taf, latest_metar):
     taf_colour = metar_tools.get_colourstate_nbr(taf)
     metar_colour = metar_tools.get_colourstate_nbr(latest_metar)
     print('TAF colour=')
     print(taf_colour)
     print('METAR colour=')
     print(metar_colour)
コード例 #2
0
    def update_icao_data(self, icao, metar_time, new_metar, taf_time, new_taf,
                         icao_dict):
        """Method to update station dictionary with new report info.
         icao_dict represents the previous state of the stations data.
         New/updated data is placed into station_dict"""

        self.station_dict['METAR'] = ''
        self.station_dict['TAF'] = ''

        taf_colour = metar_tools.get_colourstate_nbr(new_taf)
        metar_colour = metar_tools.get_colourstate_nbr(new_metar)
        print('TAF colour=')
        print(taf_colour)
        print('METAR colour=')
        print(metar_colour)

        if icao is not '':

            try:
                self.metar = new_metar
                self.metar_time = metar_time
                self.taf = new_taf
                self.taf_time = taf_time
                self.taf_cnl = False

                if self.metar is not '':
                    start_icao = icao_dict['ICAO']
                    start_time = icao_dict['METAR_TIME']
                    new_time = self.metar_time
                    current_colour = icao_dict['LATEST_COLOUR']

                    self.station_dict['ICAO'] = icao
                    self.station_dict['METAR_TIME'] = self.metar_time
                    self.station_dict['METAR'] = self.metar
                    self.station_dict['LATEST_COLOUR'] = \
                        metar_tools.get_colourstate_nbr(self.metar)

                    if new_time != start_time and start_icao == icao:
                        """Message times are different, put the old latest 
                        colour state into PREV_COLOUR If ICAO has been 
                        changed, don't swap over the PRE and LATEST colour 
                        states If message times are different change the 
                        NEW_METAR attribute to 1 - used for colour state
                        change alerts"""
                        self.station_dict['PREV_COLOUR'] = current_colour
                        self.station_dict['NEW_METAR'] = True

                    else:
                        """Take account of icao being changed in one of the 
                        input fields. In effect we are starting
                        again with monitoring this icao so set 
                        previous colour state to zero (grey)"""

                        if start_icao != icao:
                            self.station_dict['PREV_COLOUR'] = 0
                            self.station_dict['NEW_METAR'] = False

                        self.station_dict['NEW_METAR'] = False

                    if self.taf is not '':
                        self.station_dict['TAF'] = self.taf
                        self.station_dict['TAF_TIME'] = self.taf_time
                        self.station_dict['TAF_MIN_COLOUR'] = \
                            metar_tools.get_colourstate_nbr(self.taf)
                        if 'CNL' in self.taf:
                            self.taf_cnl = True

                    # Check if the METAR colour state is lower than the
                    # lowest TAF colour state and flag appropriately
                    # 2 if no TAF available, 1 if TAF bust, 0 if TAF
                    # is available and covers minimum colour state in
                    # latest METAR. If TAF is cancelled set status to 2.
                    if self.taf is '' or self.taf_cnl:
                        self.station_dict['TAF_STATUS'] = 2
                    elif self.station_dict['LATEST_COLOUR'] \
                            < self.station_dict['TAF_MIN_COLOUR']:
                        self.station_dict['TAF_STATUS'] = 1
                    else:
                        self.station_dict['TAF_STATUS'] = 0
                else:
                    """If no metar is found for the specified ICAO, just set 
                    the ICAO field of the object. Need to do this
                    otherwise the ICAO disappears from the window field"""
                    self.station_dict['ICAO'] = icao

            except AttributeError:
                self.station_dict['ICAO'] = icao

        else:
            """If the ICAO has been removed from the window field, set a 
            blank dictionary for this ICAO fields object"""
            self.station_dict = {
                'ICAO': '',
                'METAR_TIME': '',
                'METAR': '',
                'PREV_COLOUR': 0,
                'LATEST_COLOUR': 0,
                'TAF_TIME': '',
                'TAF': '',
                'TAF_MIN_COLOUR': 0,
                'TAF_STATUS': 2,
                'NEW_METAR': True
            }
コード例 #3
0
 def test_GRN(self):
     colour = metar_tools.get_colourstate_nbr(report8)
     self.assertEqual(colour, 5)
コード例 #4
0
 def test_WHT(self):
     colour = metar_tools.get_colourstate_nbr(report9)
     self.assertEqual(colour, 6)
コード例 #5
0
 def test_YL01(self):
     colour = metar_tools.get_colourstate_nbr(report2)
     self.assertEqual(colour, 4)
コード例 #6
0
 def test_AMB(self):
     colour = metar_tools.get_colourstate_nbr(report7)
     self.assertEqual(colour, 2)
コード例 #7
0
 def test_RED(self):
     colour = metar_tools.get_colourstate_nbr(report3)
     self.assertEqual(colour, 1)
コード例 #8
0
 def test_CAVOK(self):
     colour = metar_tools.get_colourstate_nbr(report5)
     self.assertEqual(colour, 7)
コード例 #9
0
 def test_BLU(self):
     colour = metar_tools.get_colourstate_nbr(report1)
     self.assertEqual(colour, 7)