SCRUM-98 file reader #13

Merged
VladiusVostokus merged 11 commits from lab5/kovalenko-SCRUM-98-FileReader into dev 2026-03-08 17:48:13 +02:00
VladiusVostokus commented 2026-03-03 17:28:12 +02:00 (Migrated from github.com)

Add class to read file data.csv that looks like file datasource from agent
Add domain directory to save dataclases(accelerometer dataclass userd in file reader)
File tested via print locally, row can be readed and reading starting again, if got to the end of file
Reader return dataclass of accelerometer as result of reading

Add class to read file data.csv that looks like file datasource from agent Add domain directory to save dataclases(accelerometer dataclass userd in file reader) File tested via print locally, row can be readed and reading starting again, if got to the end of file Reader return dataclass of accelerometer as result of reading
hasslesstech (Migrated from github.com) reviewed 2026-03-03 17:43:10 +02:00
hasslesstech (Migrated from github.com) left a comment

Instead of reformatting and uploading multiple hundreds of updated lines of .csv files it may be a better idea just to work around the file at hand without modifying it

Instead of reformatting and uploading multiple hundreds of updated lines of .csv files it may be a better idea just to work around the file at hand without modifying it
@@ -0,0 +23,4 @@
self.y_idx = file_header.index('Y')
self.z_idx = file_header.index('Z')
def getNextValue(self):
hasslesstech (Migrated from github.com) commented 2026-03-03 17:41:56 +02:00

This function is prone to crashing on unexpected file lines. Instead of trying to adapt to a specific file format, it might be better to use try/catch and deciding what to do based on that. The code may look like so:

while True:
    row = next(self.file_reader, None)

    if row is None:
            self._rewind_file()
            continue
    try:
        x = int(row[self.x_idx])
        y = int(row[self.y_idx])
        z = int(row[self.z_idx])

        return Accelerometer(x=x, y=y, z=z)
    exception Exception as e:
        continue

This way, in case the file is structured differently, has gaps or other mistakes, the function will silently skip over them and return the next valid group of values.

As an improvement, it may be way better to create a custom reader rather than relying on the csv.reader to make the script resilient against any possible .csv file failures

This function is prone to crashing on unexpected file lines. Instead of trying to adapt to a specific file format, it might be better to use try/catch and deciding what to do based on that. The code may look like so: ``` while True: row = next(self.file_reader, None) if row is None: self._rewind_file() continue try: x = int(row[self.x_idx]) y = int(row[self.y_idx]) z = int(row[self.z_idx]) return Accelerometer(x=x, y=y, z=z) exception Exception as e: continue ``` This way, in case the file is structured differently, has gaps or other mistakes, the function will silently skip over them and return the next valid group of values. As an improvement, it may be way better to create a custom reader rather than relying on the csv.reader to make the script resilient against any possible .csv file failures
VladiusVostokus (Migrated from github.com) reviewed 2026-03-03 18:52:57 +02:00
@@ -0,0 +23,4 @@
self.y_idx = file_header.index('Y')
self.z_idx = file_header.index('Z')
def getNextValue(self):
VladiusVostokus (Migrated from github.com) commented 2026-03-03 18:52:57 +02:00

Ok, I'll try it

Ok, I'll try it
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: hasslesstech/IoT-Systems#13