Example #1
0
def ingestData(data):
    if data is None or data == "":
        return

    tokens = re.split("\s+", data)
    if len(tokens) != 14:
        return

    siteID = tokens[1]
    if tokens[2] != "Min" and tokens[2] != "Max":
        if siteID not in db:
            db[siteID] = nwnformat.nwnformat()
        db[siteID].raw = tokens
        db[siteID].parseLineRT(tokens)
Example #2
0
def ingestData(data):
    if data is None or data == "":
        return

    tokens = re.split("\s+", data)
    if len(tokens) != 14:
        return

    siteID = tokens[1]
    if tokens[2] != "Min" and tokens[2] != "Max":
        if siteID not in db:
            db[siteID] = nwnformat.nwnformat()
        db[siteID].raw = tokens
        db[siteID].parseLineRT(tokens)
Example #3
0
def ingest_data(data):
    """
    I actually ingest the data
    """
    if data is None or data == "":
        return

    tokens = re.split("\s+", data)
    if len(tokens) != 14:
        return

    siteID = tokens[1]
    if siteID not in DB:
        DB[siteID] = nwnformat.nwnformat()
        DB[siteID].sid = int(siteID)
        DB[siteID].nwsli = find_nwsli(int(siteID))
        DB[siteID].network = NT.sts.get(DB[siteID].nwsli, {"network": None})["network"]
        DB[siteID].updated = False

    DB[siteID].parseLineRT(tokens)
    DB[siteID].updated = True
Example #4
0
def test_basic():
    ''' basic test of constructor '''
    n = nwnformat.nwnformat()
    n.sid = 100
    n.parseLineRT(('A 263  14:58 07/16/15   S 09MPH 000K 460F 460F '
                   '100% 29.66F 00.00"D 00.00"M 00.00"R').split())
    n.parseMaxLineRT(('A 263    Max 07/16/15   S 21MPH 000K 460F 460F '
                      '100% 29.81" 00.00"D 00.00"M 00.00"R').split())
    n.parseMaxLineRT(('A 263    Min 07/16/15   S 01MPH 000K 460F 882F '
                      '100% 29.65" 00.00"D 00.00"M 00.00"R').split())
    n.parseLineRT(('A 263  14:59 07/16/15   S 19MPH 000K 460F 460F '
                   '100% 29.66F 00.00"D 00.00"M 00.00"R').split())
    # n.setTS("BAH")
    # self.assertEqual(n.error, 100)
    n.setTS("07/16/15 14:58:50")
    n.sanityCheck()
    n.avgWinds()
    n.currentLine()
    n.maxLine()
    n.minLine()
    assert abs(n.pres - 29.66) < 0.01
Example #5
0
 def test_basic(self):
     ''' basic test of constructor '''
     n = nwnformat.nwnformat()
     n.sid = 100
     n.parseLineRT(('A 263  14:58 07/16/15   S 09MPH 000K 460F 460F '
                    '100% 29.66F 00.00"D 00.00"M 00.00"R').split())
     n.parseMaxLineRT(('A 263    Max 07/16/15   S 21MPH 000K 460F 460F '
                       '100% 29.81" 00.00"D 00.00"M 00.00"R').split())
     n.parseMaxLineRT(('A 263    Min 07/16/15   S 01MPH 000K 460F 882F '
                       '100% 29.65" 00.00"D 00.00"M 00.00"R').split())
     n.parseLineRT(('A 263  14:59 07/16/15   S 19MPH 000K 460F 460F '
                    '100% 29.66F 00.00"D 00.00"M 00.00"R').split())
     # n.setTS("BAH")
     # self.assertEqual(n.error, 100)
     n.setTS("07/16/15 14:58:50")
     n.sanityCheck()
     n.avgWinds()
     n.currentLine()
     n.maxLine()
     n.minLine()
     self.assertAlmostEqual(n.pres, 29.66, 2)
Example #6
0
def test_basic():
    """ basic test of constructor """
    n = nwnformat.nwnformat()
    n.sid = 100
    n.parseLineRT(("A 263  14:58 07/16/15   S 09MPH 000K 460F 460F "
                   '100% 29.66F 00.00"D 00.00"M 00.00"R').split())
    n.parseMaxLineRT(("A 263    Max 07/16/15   S 21MPH 000K 460F 460F "
                      '100% 29.81" 00.00"D 00.00"M 00.00"R').split())
    n.parseMaxLineRT(("A 263    Min 07/16/15   S 01MPH 000K 460F 882F "
                      '100% 29.65" 00.00"D 00.00"M 00.00"R').split())
    n.parseLineRT(("A 263  14:59 07/16/15   S 19MPH 000K 460F 460F "
                   '100% 29.66F 00.00"D 00.00"M 00.00"R').split())
    # n.setTS("BAH")
    # self.assertEqual(n.error, 100)
    n.setTS("07/16/15 14:58:50")
    n.sanityCheck()
    n.avgWinds()
    n.currentLine()
    n.maxLine()
    n.minLine()
    assert abs(n.pres - 29.66) < 0.01
Example #7
0
def ingest_data(data):
    """
    I actually ingest the data
    """
    if data is None or data == "":
        return

    tokens = re.split("\s+", data)
    if len(tokens) != 14:
        return

    siteID = tokens[1]
    if siteID not in DB:
        DB[siteID] = nwnformat.nwnformat()
        DB[siteID].sid = int(siteID)
        DB[siteID].nwsli = find_nwsli(int(siteID))
        DB[siteID].network = NT.sts.get(DB[siteID].nwsli,
                                        {'network': None})['network']
        DB[siteID].updated = False

    DB[siteID].parseLineRT(tokens)
    DB[siteID].updated = True
Example #8
0
    def processFile(self, filename):
        id = self.filedict[filename]
        n = nwnformat.nwnformat()
        cf = configparser.ConfigParser()

        try:
            cf.read(filename)
        except Exception as exp:
            print(exp)
            return

        if len(cf.sections()) != 3:
            log.msg("%s %s %d" % (id, 'Short read', len(cf.sections())))
            return
        try:
            n.sid = id
            n.setTS( cf.get("Current Values", "Time") )
            n.parseWind( cf.get("Current Values", "Wind") )
            n.setRad( cf.get("Current Values", "Solar") )
            p = cf.get("Current Values", "Temperature")
            if (p != "Missing"):
                n.tmpf = int(float(p))
            p = cf.get("Current Values", "Humidity")
            if (p != "Missing"):
                n.humid = int(float(p))
            p = cf.get("Current Values", "Pressure")
            if (p != "Missing"):
                n.pres = float(p)
            n.presTend = "R"

            """ Ugly precip logic, have to do something tho.... """
            # Get value from the datafile
            n.parsePDay( cf.get("Current Values", "RainForDay") )
            pDay = n.pDay
            lastPDay = self.pDayDict[id]
            yyyymm = int( n.ts.strftime("%Y%m") )
            lastYYYYMM = self.monthDict[id]
            if (lastYYYYMM < yyyymm):   # Reset month dict to zero
                self.pMonthDict[id] = 0   #
                self.monthDict[id] = yyyymm
                self.writePMonth()
            # pDay is smaller, then we should add to month dict
            if (pDay < lastPDay):
                self.pMonthDict[id] += lastPDay
                self.writePMonth()

            pMonth = self.pMonthDict[id] + pDay
            self.pDayDict[id] = pDay

            #n.parsePDay( cf.get("Current Values", "RainForDay") )
            n.setPMonth(pMonth)

            p = cf.get("High Values", "HighTemperature")
            if (p != "Missing"):
                n.xtmpf = int(float(p))
            p = cf.get("Low Values", "LowTemperature")
            if (p != "Missing"):
                n.ntmpf = int(float(p))
            p = cf.get("High Values", "HighWind")
            if (p != "Missing"):
                n.xsped = int(float(p))
            n.sanityCheck()
        except Exception as exp:
            n.error = 1000
            print(exp)

        if n.error not in [0, 101]:
            print("ERROR %s IS %s" % (id, n.error))
        if n.error == 0:
            self.sendData(n.currentLine())
            reactor.callLater(1, self.sendData, n.maxLine())
            reactor.callLater(2, self.sendData, n.minLine())