Skip to content

Commit

Permalink
Log last value together f70h
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan committed Aug 13, 2024
1 parent dd2adaf commit a14009c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/f70h/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


F70_INST_NAME: str = "ASRL3::INSTR"
REFRESH_INTERVAL_MS: int = 1000

log = logging.getLogger("F70H")
log.setLevel(logging.INFO)
Expand Down Expand Up @@ -54,6 +55,7 @@ def __init__(self):
self.log_dir = "D:/Logs/Compressor"
self._stopped = multiprocessing.Event()
self.queue = multiprocessing.Manager().Queue()
self._last_logged: datetime.datetime = datetime.datetime.now()
self._content_old: tuple[int, int, int] = (0, 0, 0)

def run(self):
Expand All @@ -76,16 +78,27 @@ def run(self):
newline="",
) as f:
writer = csv.writer(f)
dt_prev = dt - datetime.timedelta(milliseconds=REFRESH_INTERVAL_MS)

# If there is a gap in logging, log the last value
if self._last_logged < dt_prev - datetime.timedelta(
milliseconds=REFRESH_INTERVAL_MS * 0.5
):
writer.writerow([dt_prev, *[str(v) for v in self._content_old]])

writer.writerow([dt.isoformat(), *[str(v) for v in values]])

except PermissionError:
# put back the retrieved message in the queue
# Put back the retrieved message in the queue
n_left = int(self.queue.qsize())
self.queue.put((dt, values))
for _ in range(n_left):
self.queue.put(self.queue.get())
continue

else:
self._content_old = values
self._last_logged = dt

def stop(self):
n_left = int(self.queue.qsize())
Expand Down Expand Up @@ -218,7 +231,7 @@ def __init__(self):

self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.refresh)
self.timer.start(1000)
self.timer.start(REFRESH_INTERVAL_MS)

@property
def current_time_formatted(self) -> str:
Expand Down

0 comments on commit a14009c

Please sign in to comment.