Exemplo n.º 1
0
    def test_multi_lines(self):
        dataFile = HighlightedFile(DATA_FILE)

        tool = "TOOL"

        # get the set of self-describing lines
        lines = dataFile.lines()

        # check the contents of hte print statement
        lineStr = str(lines[0])
        self.assertEqual("(0+(0, 55), 951212 050000.000 MONDEO_44   @C   269.7   10.0      10)", lineStr)
        

        for line in lines:
            tokens = line.tokens()

            if tokens[0].text() == "//":
                dateToken = tokens[2]
                timeToken = tokens[3]
                messageToken = tokens[4]

                dateVal = self.parse_timestamp(dateToken.text(), timeToken.text())
                dateTimeToken = combine_tokens(dateToken, timeToken)
                dateTimeToken.record(tool, "Event DTG", dateVal, "N/A")

                messageToken.record(tool, "Message", messageToken.text(), "N/A")
            else:
                dateToken = tokens[0]
                timeToken = tokens[1]
                vehicleToken = tokens[2]
                courseToken = tokens[4]
                speedToken = tokens[5]
                tempToken = tokens[6]


                dateVal = self.parse_timestamp(dateToken.text(), timeToken.text())
                dateTimeToken = combine_tokens(dateToken, timeToken)
                dateTimeToken.record(tool, "DTG", dateVal, "N/A")
                vehicleToken.record(tool,"NAME", vehicleToken.text(), "N/A")
                courseToken.record(tool,"Course", courseToken.text(), "Degs")
                speedToken.record(tool,"Speed", speedToken.text(),"M/Sec")
                tempToken.record(tool, "Temperature", tempToken.text(), "Deg C")

                # also send the temperature somewhewre else
                tempToken.record("Third Party Temp Tracker", "Env Tmp", tempToken.text(),"Deg C")


        dataFile.export("track_lines.html", True)
Exemplo n.º 2
0
        dateToken.record(eventImporter, "Date", dateToken.text())
        timeToken = tokens[3]
        timeToken.record(eventImporter, "Time", timeToken.text())
        eventToken = tokens[4]
        eventToken.record(eventImporter, "Event", timeToken.text())


        # and the whole=line record
        thisLine.record(eventImporter, "Whole line")

# output to file, display

for i in dataFile.chars_debug():
    print(i)

dataFile.export("out4.html")

# CSV FILE

dataFileCSV = HighlightedFile('data_highlight/file_comma.txt')

# get the set of self-describing lines
lines = dataFileCSV.lines()

CSV_DELIM = "(?:,\"|^\")(\"\"|[\w\W]*?)(?=\",|\"$)|(?:,(?!\")|^(?!\"))([^,]*?)(?=$|,)|(\r\n|\n)"

for thisLine in lines:

    tokens = thisLine.tokens(CSV_DELIM, ",")  # note we specify delimiter

    # check the type
Exemplo n.º 3
0
    def test_CombineLinesOnMultipleLines(self):
        dataFile = HighlightedFile(NMEA_FILE, 50)

        # get the set of self-describing lines
        lines = dataFile.lines()

        nmea_delim = "([^,]+|(?<=,)(?=,)|^(?=,)|(?<=,)$)"

        lat_tok = None
        lat_hem_tok = None
        long_tok = None
        long_hem_tok = None
        date_tok = None
        time_tok = None
        hdg_tok = None
        spd_tok = None

        date_line = None
        loc_line = None
        hdg_line = None
        spd_line = None

        for line in lines:
            tokens = line.tokens(nmea_delim, ",")
            if len(tokens) > 0:

                msg_type = tokens[1].text()

                if msg_type == "DZA":
                    date_tok = tokens[2]
                    time_tok = tokens[3]
                    date_line = line
                elif msg_type == "VEL":
                    spd_tok = tokens[6]
                    spd_line = line
                elif msg_type == "HDG":
                    hdg_tok = tokens[2]
                    hdg_line = line
                elif msg_type == "POS":
                    lat_tok = tokens[3]
                    lat_hem_tok = tokens[4]
                    long_tok = tokens[5]
                    long_hem_tok = tokens[6]
                    loc_line = line

                # do we have all we need?
                if date_tok and spd_tok and hdg_tok and lat_tok:

                    date_time = self.parse_timestamp(date_tok.text(),
                                                     time_tok.text())

                    loc = self.parse_location(lat_tok.text(),
                                              lat_hem_tok.text(),
                                              long_tok.text(),
                                              long_hem_tok.text())
                    spd = float(spd_tok.text())
                    hdg = float(hdg_tok.text())

                    fStr = "{:8.2f}"

                    msg = "Date:" + str(date_time) + ", Loc:()" + fStr.format(loc[0]) + ", " \
                        + fStr.format(loc[1]) + "), Spd:" +  \
                        fStr.format(spd) + ", Hdg:" + fStr.format(hdg)

                    line_composite = combine_tokens(date_line, loc_line,
                                                    spd_line, hdg_line)

                    line_composite.record("NMEA Import",
                                          "Date:" + str(date_time), msg, "N/A")

                    date_tok = None
                    spd_tok = None
                    hdg_tok = None
                    lat_tok = None

        dataFile.export("nmea2.html")