Skip to content

Commit e35965c

Browse files
committed
Add argument to reduce progress event frequency
1 parent 92b8ab6 commit e35965c

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

ratapi/utils/matlab.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
eventManager.register(eventTypes.Message, @(x) logger('{msg_log_path}', x));
3232
eventManager.register(eventTypes.Progress, @(x) logger('{progress_log_path}', x));
3333
eventManager.register(eventTypes.Plot, @(x) logger('{plot_log_path}', x));
34+
global RAT_PROGRESS_UPDATE_FREQ RAT_PROGRESS_UPDATE_COUNT
35+
RAT_PROGRESS_UPDATE_FREQ = {progress_event_freq};
36+
RAT_PROGRESS_UPDATE_COUNT = -1;
37+
3438
[project, results] = RAT(project, customControls);
3539
3640
projectToJson(project, '{project}');
@@ -60,15 +64,21 @@
6064
"""
6165

6266
LOGGER = """function logger(logPath, data)
63-
fid = fopen(logPath, "a");
64-
cleanup = onCleanup(@() fclose(fid));
67+
6568
if isstruct(data)
6669
entry = plotDataToJson(data);
6770
elseif iscell(data)
71+
global RAT_PROGRESS_UPDATE_FREQ RAT_PROGRESS_UPDATE_COUNT;
72+
RAT_PROGRESS_UPDATE_COUNT = RAT_PROGRESS_UPDATE_COUNT + 1;
73+
if rem(RAT_PROGRESS_UPDATE_COUNT, RAT_PROGRESS_UPDATE_FREQ) ~= 0
74+
return
75+
end
6876
entry = [data{1}, ',', num2str(data{2})];
6977
else
7078
entry = strip(data, 'right');
7179
end
80+
fid = fopen(logPath, "a");
81+
cleanup = onCleanup(@() fclose(fid));
7282
fprintf(fid, "%s\\n", entry);
7383
end
7484
@@ -126,7 +136,9 @@
126136
"""
127137

128138

129-
def run_matlab_directly(project, controls, matlab_rat_path, ipc_path="", stdout=None, stderr=None):
139+
def run_matlab_directly(
140+
project, controls, matlab_rat_path, ipc_path="", stdout=None, stderr=None, progress_event_freq=10
141+
):
130142
"""Run User provided MATLAB RAT for the given project and controls inputs.
131143
132144
Parameters
@@ -138,11 +150,13 @@ def run_matlab_directly(project, controls, matlab_rat_path, ipc_path="", stdout=
138150
matlab_rat_path : str
139151
The path to MATLAB RAT folder.
140152
ipc_path : str, optional
141-
IPC path for MATLAB to use
153+
IPC path for MATLAB to use.
142154
stdout : io.TextIOBase, optional
143-
Text stream for MATLAB console output
155+
Text stream for MATLAB console output.
144156
stderr : io.TextIOBase, optional
145-
Text stream for MATLAB console error output
157+
Text stream for MATLAB console error output.
158+
progress_event_freq : int, default: 10
159+
Update frequency of the progress event.
146160
"""
147161
if MatlabWrapper.loader is None:
148162
raise ImportError(MatlabWrapper.loader_error_message) from None
@@ -173,6 +187,7 @@ def run_matlab_directly(project, controls, matlab_rat_path, ipc_path="", stdout=
173187
msg_log_path=msg_log_file,
174188
progress_log_path=progress_log_file,
175189
plot_log_path=plot_log_file,
190+
progress_event_freq=progress_event_freq,
176191
)
177192
)
178193

0 commit comments

Comments
 (0)