mirror of
https://github.com/Rhinemann/IoT-Systems.git
synced 2026-03-14 20:50:39 +02:00
feat: start read file again if got to the end of file
This commit is contained in:
parent
550d29c48c
commit
11c590cf25
@ -24,12 +24,20 @@ class FileReader:
|
||||
self.z_idx = file_header.index('Z')
|
||||
|
||||
def getNextValue(self):
|
||||
row = next(self.file_reader)
|
||||
row = next(self.file_reader, None)
|
||||
if row is None:
|
||||
self._rewind_file()
|
||||
row = next(self.file_reader)
|
||||
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)
|
||||
|
||||
def _rewind_file(self):
|
||||
self.file.seek(0)
|
||||
self.file_reader = reader(self.file)
|
||||
next(self.file_reader)
|
||||
|
||||
def stopReading(self, *args, **kwargs):
|
||||
if self.file:
|
||||
self.file.close()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user