Skip to content

Commit

Permalink
Merge pull request #1119 from anarkiwi/wf
Browse files Browse the repository at this point in the history
fix crash where results arrive in same timestamp.
  • Loading branch information
anarkiwi authored Jan 23, 2024
2 parents e94d9c2 + 9fa7af0 commit 862b64b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions gamutrfwaterfall/gamutrfwaterfall/waterfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ def update_fig(config, state, results):

scan_time = scan_df.ts.iloc[-1]
row_time = datetime.datetime.fromtimestamp(scan_time)
state.scan_times.append(scan_time)
if scan_time not in state.scan_config_history:
state.scan_times.append(scan_time)
state.scan_config_history[scan_time] = scan_configs
while len(state.scan_times) > config.waterfall_height:
remove_time = state.scan_times.pop(0)
Expand Down Expand Up @@ -1089,6 +1090,15 @@ def start(self):
self.process.start()
self.zmq_process.start()

def write_predictions_content(self, content):
tmpfile = os.path.join(self.static_folder, "." + self.predictions_file)
with open(tmpfile, "w", encoding="utf8") as f:
f.write(
'<html><head><meta http-equiv="refresh" content="%u"></head><body>%s</body></html>'
% (self.refresh, content)
)
os.rename(tmpfile, os.path.join(self.static_folder, self.predictions_file))

def poll_zmq(self):
zmq_context = zmq.Context()
socket = zmq_context.socket(zmq.SUB)
Expand All @@ -1097,17 +1107,7 @@ def poll_zmq(self):
DELIM = "\n\n"
json_buffer = ""
item_buffer = []

def write_content(content):
tmpfile = os.path.join(self.static_folder, "." + self.predictions_file)
with open(tmpfile, "w", encoding="utf8") as f:
f.write(
'<html><head><meta http-equiv="refresh" content="%u"></head><body>%s</body></html>'
% (self.refresh, content)
)
os.rename(tmpfile, os.path.join(self.static_folder, self.predictions_file))

write_content("no predictions yet")
self.write_predictions_content("no predictions yet")

while True:
try:
Expand Down Expand Up @@ -1146,7 +1146,7 @@ def write_content(content):
% (style, image, age, style, image)
)
if images:
write_content(
self.write_predictions_content(
f"<p>{datetime.datetime.now().isoformat()}</p>" + "".join(images)
)
time.sleep(0.1)
Expand Down

0 comments on commit 862b64b

Please sign in to comment.