From 4817d4505ac67a6d6ee7c698fc6ddbdbb86eb490 Mon Sep 17 00:00:00 2001 From: Sunil Shetye Date: Mon, 3 Feb 2025 12:48:10 +0530 Subject: add figure_id as key to lastlogtimes --- blocks/.dockerignore | 3 +++ blocks/simulationAPI/views.py | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/blocks/.dockerignore b/blocks/.dockerignore index 39bccca2..c4d35a5a 100644 --- a/blocks/.dockerignore +++ b/blocks/.dockerignore @@ -24,3 +24,6 @@ Xcos/xcosblocks.py blocks/xcosblocks/xcosblocks.py **/__pycache__ **/__snapshots__ +file_storage/* +!file_storage/uploads +file_storage/uploads/* diff --git a/blocks/simulationAPI/views.py b/blocks/simulationAPI/views.py index 74603a0e..44f19a77 100644 --- a/blocks/simulationAPI/views.py +++ b/blocks/simulationAPI/views.py @@ -161,7 +161,8 @@ def parse_line(line, lineno): return (None, NOLINE) -def get_line_and_state(file, figure_list, lineno, incomplete_line): +def get_line_and_state(file, figure_list, lastlogtimes, + lineno, incomplete_line): ''' Function to get a new line from file This also parses the line and appends new figures to figure List @@ -180,6 +181,7 @@ def get_line_and_state(file, figure_list, lineno, incomplete_line): # New figure created # Add figure ID to list figure_list.append(figure_id) # figure id of block is added to list + lastlogtimes[figure_id] = -1 line = None elif state == ENDING: # End of figure @@ -187,10 +189,11 @@ def get_line_and_state(file, figure_list, lineno, incomplete_line): # Once ending of log file/data is encountered for that block, figure id # will be removed figure_list.remove(figure_id) + del lastlogtimes[figure_id] line = None elif state == NOLINE: line = None - return (line, state) + return (line, figure_id, state) class StreamView(APIView): @@ -252,17 +255,17 @@ class StreamView(APIView): self.duplicatelineno = 0 self.duplicatelines = 0 lastline = '' - lastlogtime = -1 lineno = 0 line = None starttime = time.time() endtime = starttime + SCILAB_INSTANCE_TIMEOUT_INTERVAL log_size = 0 figure_list = [] + lastlogtimes = {} while time.time() <= endtime and log_size <= MAX_LOG_SIZE: - (line, state) = get_line_and_state(log_file, figure_list, - lineno, line) + (line, figure_id, state) = get_line_and_state(log_file, figure_list, lastlogtimes, + lineno, line) # if incomplete line, wait for the complete line if state == NOLINE: time.sleep(LOOK_DELAY) @@ -282,10 +285,10 @@ class StreamView(APIView): if len(words) == 15 and words[-1] == 'CSCOPE': logtime = float(words[8]) totallogtime = float(words[-2]) - if logtime < lastlogtime + 0.001 * totallogtime: + if logtime < lastlogtimes[figure_id] + 0.001 * totallogtime: line = None continue - lastlogtime = logtime + lastlogtimes[figure_id] = logtime interval = starttime + logtime - time.time() - 0.1 if interval > 0: time.sleep(interval) -- cgit