コード例 #1
0
ファイル: test_accum.py プロジェクト: yesjpm/weewx
    def test_Accum_getRecord(self):
        """Test extraction of record from an accumulator."""
        accum = weewx.accum.Accum(TimeSpan(start_ts, stop_ts))
        for record in self.dataset:
            accum.addRecord(record)
        extracted = accum.getRecord()

        self.assertEqual(extracted['dateTime'], self.dataset[-1]['dateTime'])
        self.assertEqual(extracted['usUnits'], weewx.US)

        sum_t = 0
        count_t = 0
        for rec in self.dataset:
            if rec['outTemp'] is not None:
                sum_t += rec['outTemp']
                count_t += 1
        self.assertEqual(extracted['outTemp'], sum_t / count_t)

        max_wind = 0
        max_dir = None
        for rec in self.dataset:
            if rec['windGust'] is not None and rec['windGust'] > max_wind:
                max_wind = rec['windGust']
                max_dir = rec['windGustDir']
        self.assertEqual(extracted['windGust'], max_wind)
        self.assertEqual(extracted['windGustDir'], max_dir)

        rain_sum = 0
        for rec in self.dataset:
            if rec['rain'] is not None:
                rain_sum += rec['rain']
        self.assertEqual(extracted['rain'], rain_sum)
コード例 #2
0
ファイル: test_accum.py プロジェクト: timtsm/weewx
 def test_issue_737(self):
     accum = weewx.accum.Accum(TimeSpan(start_ts, stop_ts))
     for packet in self.dataset:
         packet['windrun'] = None
         accum.addRecord(packet)
     # Extract the record out of the accumulator
     record = accum.getRecord()
     self.assertIsNone(record['windrun'])
コード例 #3
0
ファイル: test_accum.py プロジェクト: yesjpm/weewx
    def test_null_wind_gust_dir(self):
        # If LOOP packets windGustDir=None, the accumulator should not substitute windDir.
        # This is a regression test that tests that.
        accum = weewx.accum.Accum(TimeSpan(start_ts, stop_ts))

        # Add the dataset to the accumulator. Null out windGustDir first.
        for record in self.dataset:
            record_test = dict(record)
            record_test['windGustDir'] = None
            accum.addRecord(record_test)

        # Extract the record out of the accumulator
        accum_record = accum.getRecord()
        # windGustDir should match the windDir seen at max wind:
        self.assertIsNone(accum_record['windGustDir'])
コード例 #4
0
ファイル: test_accum.py プロジェクト: timtsm/weewx
    def test_Accum_with_string(self):
        """Test records with string literals in them."""
        for i, record in enumerate(self.dataset):
            record['stringType'] = "AString%d" % i

        # As of V4.6, adding a string to the default accumulators should no longer result in an
        # exception
        accum = weewx.accum.Accum(TimeSpan(start_ts, stop_ts))
        for record in self.dataset:
            accum.addRecord(record)

        # Try it again, but this time specifying a FirstLast accumulator for type 'stringType':
        weewx.accum.accum_dict.extend({'stringType': {'accumulator': 'firstlast', 'extractor': 'last'}})
        accum = weewx.accum.Accum(TimeSpan(start_ts, stop_ts))
        for record in self.dataset:
            accum.addRecord(record)
        # The value extracted for the string should be the last one seen
        rec = accum.getRecord()
        self.assertEqual(rec['stringType'], "AString%d" % (len(self.dataset) - 1))
コード例 #5
0
ファイル: test_accum.py プロジェクト: yesjpm/weewx
    def test_no_wind_gust_dir(self):
        # If LOOP packets do not have windGustDir at all, then the accumulator is supposed to
        # substitute windDir. This is a regression test that tests that.
        accum = weewx.accum.Accum(TimeSpan(start_ts, stop_ts))

        windMax = None
        windMaxDir = None
        # Add the dataset to the accumulator. Null out windGustDir first.
        for record in self.dataset:
            record_test = dict(record)
            del record_test['windGustDir']
            if windMax is None \
                    or (record_test['windSpeed'] is not None
                        and record_test['windSpeed'] > windMax):
                windMax = record_test['windSpeed']
                windMaxDir = record_test['windDir']
            accum.addRecord(record_test)

        # Extract the record out of the accumulator
        accum_record = accum.getRecord()
        # windGustDir should match the windDir seen at max wind:
        self.assertEqual(accum_record['windGustDir'], windMaxDir)