Skip to content

Commit

Permalink
fix crash where results arrive in same timestamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
anarkiwi committed Jan 23, 2024
1 parent e94d9c2 commit 9fa7af0
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(

Check warning on line 1096 in gamutrfwaterfall/gamutrfwaterfall/waterfall.py

View check run for this annotation

Codecov / codecov/patch

gamutrfwaterfall/gamutrfwaterfall/waterfall.py#L1094-L1096

Added lines #L1094 - L1096 were not covered by tests
'<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))

Check warning on line 1100 in gamutrfwaterfall/gamutrfwaterfall/waterfall.py

View check run for this annotation

Codecov / codecov/patch

gamutrfwaterfall/gamutrfwaterfall/waterfall.py#L1100

Added line #L1100 was not covered by tests

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")

Check warning on line 1110 in gamutrfwaterfall/gamutrfwaterfall/waterfall.py

View check run for this annotation

Codecov / codecov/patch

gamutrfwaterfall/gamutrfwaterfall/waterfall.py#L1110

Added line #L1110 was not covered by tests

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(

Check warning on line 1149 in gamutrfwaterfall/gamutrfwaterfall/waterfall.py

View check run for this annotation

Codecov / codecov/patch

gamutrfwaterfall/gamutrfwaterfall/waterfall.py#L1149

Added line #L1149 was not covered by tests
f"<p>{datetime.datetime.now().isoformat()}</p>" + "".join(images)
)
time.sleep(0.1)
Expand Down

0 comments on commit 9fa7af0

Please sign in to comment.