def addData(self, signalList):
     """add data to buffer"""
     if(len(signals.getSignalList()) == len(signalList)):
         for i, s in enumerate(signals.getSignalList()):
             if(s.name == "GPS_Time" or s.name == "VIN" or signalList[i] == None):
                 self._data[s.name].append(signalList[i])
             else:
                 self._data[s.name].append(round(float(signalList[i]),s.roundDigit))
     else:
         raise ValueError("Error: signalList has to have the same shape as signals.getSignalList()")
Beispiel #2
0
    def __init__(self):
        """
        Constructor:
                Initialize attributs.
                Create a dictionary of the signals with the signal names as keys
                and a yet empty list as value.
                Set status to NO_LOGFILE.
        """
        self._filename_raw_data = ""
        self._VIN = ""

        # Create dictionary of signals
        self._data = {}
        for s in signals.getSignalList():
            self._data[s.name] = []

        # Set status
        self._status = LogStatus.NO_LOGFILE

        # File is not broken yet
        self._isBrokenFile = False

        # height profile
        self.height_profile_dict = None
        self._filename_height_profile = ""
    def __init__(self):
        self._filename = ""
        self._data = {

        }
        self._VIN = ""

        for s in signals.getSignalList():    #Get OBD Signals
            # Fill Dictionary with Signals from Class Signals
            self._data[s.name] = []

        self._status = LogStatus.NO_LOGFILE
        self._isBrokenFile = False
    def createLogfile(self, filename):
        """Create logfile to track OBDII data"""
        try:
            with open(path+filename, 'w', newline='') as file:
                wr = csv.writer(file, quoting=csv.QUOTE_MINIMAL)
                # Auto generate Header from signals in Signals.py
                header = [s.name for s in signals.getSignalList()]
                wr.writerow(header)
        except:
            print("Error! Creating File failed")

        self._filename = filename
        self._status = LogStatus.LOG_CREATED
    def test_SQLString(self):
        sql = "INSERT INTO importobd ("
        s = []
        for signal in signals.getSignalList():
            s.append(signal.db_name)
        sql += ", ".join(s)
        sql += ") VALUES ("
        tmp = []
        for i in range(len(s)):
            tmp.append("%s")
        sql += ", ".join(tmp)
        sql += ")"

        print(sql)
    def appendFile(self):
        """save buffered date in csv file"""
        if(not self._status == LogStatus.LOG_CREATED):
            raise ValueError("You have to create LogFile first!")

        try:
            with open(path+self._filename, 'a', newline='') as file:
                wr = csv.writer(
                    file, quoting=csv.QUOTE_MINIMAL, quotechar='"')

                for i in range(0, len(self._data["TIME"])):
                    buffer = []

                    for s in signals.getSignalList():
                        buffer.append(self._data[s.name][i])

                    wr.writerow(buffer)
        except:
            raise FileNotFoundError("Error!: Appending file failed")

        self._data.clear()
        for s in signals.getSignalList():
            # Fill Dictionary with Signals from Class Signals
            self._data[s.name] = []
Beispiel #7
0
    def appendFile(self):
        """
        Save the data from the buffer (dictionary) to the CSV file.
        
        First it is necessary to call createLogfile.
        """

        # If status is not LOG_CREATED, raise an error
        if (not self._status == LogStatus.LOG_CREATED):
            raise ValueError("You have to create LogFile first!")

        try:
            # Open the CSV file for appending new lines
            with open(path + self._filename_raw_data, 'a', newline='') as file:
                # Create a CSV writer without automatic data convertion
                wr = csv.writer(file, quoting=csv.QUOTE_MINIMAL, quotechar='"')

                # Write the data from the buffer (dictionary) to the CSV file
                for i in range(0, len(self._data["TIME"])):
                    buffer = []
                    # Append one row of measurement to the temporary list
                    for s in signals.getSignalList():
                        buffer.append(self._data[s.name][i])

                    # Write the data row to the CSV file
                    wr.writerow(buffer)

        # If any error occured, raise a customized error
        except:
            raise FileNotFoundError("Error!: Appending file failed")

        # Clear the buffer (dictionary)
        self._data.clear()
        # Fill the dictionary with the keys as signals and yet empty lists as values
        for s in signals.getSignalList():
            self._data[s.name] = []
Beispiel #8
0
    def addData(self, signalList):
        """
        Add the recorded signal data to the buffer.
        The buffer is the dictionary of the signals in the attributs (_data).
        """

        # If the given signal list has the correct size, iterate over the signals
        if (len(signals.getSignalList()) == len(signalList)):
            for i, s in enumerate(signals.getSignalList()):
                # If it one of the specified signals, append the value from the
                # list to the buffer
                if (s.name == "GPS_Time" or s.name == "VIN"
                        or signalList[i] == None):
                    self._data[s.name].append(signalList[i])
                # If it is another signal, append its float value, rounded in
                # consideration of the signals defined round digit
                else:
                    self._data[s.name].append(
                        round(float(signalList[i]), s.roundDigit))
        # If the signals list has the wrong size, raise an error
        else:
            raise ValueError(
                "Error: signalList has to have the same shape as signals.getSignalList()"
            )
Beispiel #9
0
    def createLogfile(self, filename):
        """
        Create a logfile (CSV) to track the signal data.
        """
        try:
            # Create the file with the file name in the basic path
            with open(path + filename, 'w', newline='') as file:
                # Create an CSV writer without automatic data convertion
                wr = csv.writer(file, quoting=csv.QUOTE_MINIMAL)
                # Auto generate Header from signals in Signals.py (which column
                # for which signal)
                header = [s.name for s in signals.getSignalList()]
                # Write the header to the file
                wr.writerow(header)

        # If file could not be created, print error
        except:
            print("Error! Creating File failed")

        # Set the file name as attribut and change the status to LOG_CREATED
        self._filename_raw_data = filename
        self._status = LogStatus.LOG_CREATED
 def test_init(self):
     log = LogFile()
     self.assertEqual(log.status(), LogStatus.NO_LOGFILE)
     #Check wheather alls Signals are in the datadict after initialization
     for sig in signals.getSignalList():
         self.assertEqual(sig.name in log.getDataDict(), True)