Is there a way to include controls of a 'depends' profile based on a regex? And if not, is there a way to include all controls, and overwrite impact with fixed value on all controls?
Code should look something like this, where 'controlname' is the variable that is required to be determined somehow:
include_controls 'depends-profile' do
if controlname.match(/some regex/)
control *controlname*
impact 1.0
end
end
Goal is to prevent having to add all controls individually.
A bit digging delivered me this:
include_controls 'dependent-profile' do
list_of_controls = #conf['profile'].runner_context.rules.keys
list_of_controls.map { |path| path.gsub(#conf['profile'].profile_name+'/','') }
list_of_controls.each do |controlname|
if controlname.match(/some regex/)
control controlname do # include and overwrite impact
impact 0.1
end
end
if controlname.match(/some other regex/)
control controlname # just include
end
end
end
Any ideas how to accomplish this in a neat and future proof way?
A solution might look like:
include_controls '<dependent-profile>' do
# Scan through all the controls we pulled in
profile_context.all_controls.each do |c|
# Grab the control name from control c
handled_control_name = c.instance_variable_get(:#__rule_id)
# If it matches the regex
if handled_control_name =~ /<myRegex>/
# Overwrite the impact and tags
control handled_control_name do
impact 'critical'
tag 'myTag'
end
end
end
end
Related
So I have created a huge screen that essentially just shows the robot status for every robot in this factory (individually)… At the very end of the project, they decided they want one object on the screen that blinks if any of the 300 robots fault. I am trying to think of a way to make this work. Maybe a global script of some kind? Problem is, I do not do much scripting in Cimplicity, so any help is appreciated.
All the points that are currently used on this screen (to indicate a fault) have very similar names… as in, the beginning is the same… so I was thinking of a script that could maybe recognize if a bit is high based on PART of it's string name characteristic. The end will change a little each time, but I am sure there is a way to only look for part of a string and negate the rest. If the end has to be hard coded, that's fine.
You can use a Python script in Cimplicity.
I will not go into detail on the use of python in Cimplicity, which is well described in the documentation indicated above.
Here's an example of what can be done... note that I don't have a way to test it and, of course, this will work if the name of your robots in the declaration follows the format Robot_1, Robot_2, Robot_3 ... Robot_10 ... Robot_300 and it also depends on the Name and the Type of the fault variable... as you didn't define it, I imagine it can be an integer, with ZERO indicating no error. But if you use something other than that, you can easily change it.
import cimplicity
(...)
OneRobotWithFault = False
# Here you get the values and check for fault
for i in range(0, 300):
pointName = f'MyFactory.Robot_{i}.FaultCode'
robotFaultCode = cimplicity.point_get(pointName)
if robotFaultCode > 0:
OneRobotWithFault = True
break
# Set the status to the variable "WeHaveRobotWithFault"
cimplicity.point_set("WeHaveRobotWithFault", OneRobotWithFault)
I have a matlab script, where I would like to dynamically create sections in my matlab publish.
At present, the only way I know to create a section break, is to put code like this in my script:
%% This is a section break
I'd like to run publish on my script, and have the section breaks get added as part of the publish. For instance. Say I had the following script:
breaks(1).name = 'This is section break 1.';
breaks(2).name = 'This is section break 2.';
for ix = 1 : numel(breaks)
functionThatInsertsSectionBreakTitle(breaks(ix).name);
fprintf('Some random processing associated with break %d.\n', ix);
end
I would like to call publish on that script, and end up with a document that looks something like:
This is section break 1.
Some random processing associated with break 1.
This is section break 2.
Some random processing associated with break 2.
Obviously I could do this by writing a script that writes a script that then gets executed by publish. I was hoping for something a bit more direct. Am aware of the report generation toolbox, which I would hope would cleanly handle this type of scenario. Alternatively, if the new (as of R2016a) Live Script handles this use case, that's a fine answer as well.
One way to address this problem is by displaying html code in the command output (documented here).
In your example, the code would look like this:
breaks(1).name = 'This is section break 1.';
breaks(2).name = 'This is section break 2.';
for ix = 1 : numel(breaks)
disp(['<html><h2>' breaks(ix).name '</h2></html>']);
fprintf('Some random processing associated with break %d.\n', ix);
end
This is incredibly useful when you want to get results to be displayed with a custom layout, such as a table. And it avoids the need of having a Matlab Report Generator license...
I'm looking in to a way to improve the autocomplete for GPS ADA
(Version: GPS 6.0.1 with GNAT Pro 6.4.2).
GPS autocomplete searches for matches which begin with the text you entered.
I would like to match my string anywhere in the text.
Currently the regex would be something like:
/myString.*/i
I would like it to be:
/.*myString.*/i
Is there an option I've missed to do this?
Does anyone know of a GPS plugin that does this?
I've also had a look into writing this plugin myself, the documentation at http://docs.adacore.com/gps-docs/users_guide/_build/html/GPS.html#GPS.Completion which references "completion.py" - which i haven't been able to find - i'm guessing this may have only been included with later verisons of GPS.
You could indeed write this yourself (recent developments of GPS do not include this feature, which I believe was never requested before).
The goal is to define an action, which you can then bind to a key shortcut. So for instance the plug-in would start with something like:
import GPS, gps_utils
#gps_utils.interactive(name='My Completion', filter='Source editor'):
def my_completion():
buffer = GPS.EditorBuffer.get() # the current editor
loc = buffer.current_view().cursor() # the current location
start = loc.forward_word(-1) # beginning of word
end = loc.forward_word(1) # end of word
text = buffer.get_chars(start, end) # the text the user is currently typing
# then search in current buffer (or elsewhere) for matching text
match = buffer.beginning_of_buffer().search(text)
if match:
match_start, match_end = match
match_text = buffer.get_chars(match_start, match_end)
# then go back to initial location, remove text and replace with match
buffer.delete(start, end)
buffer.insert(start, match_text)
This is a rough outline, there are likely hundreds of details that I did not look at. It should get your started though.
I need to generate a business report using perl + Template Toookit and LaTeX.
Things are working really well, but I am struggling with the problem of having breaks (for example page breaks, or special headers) and subtotals whenever a field changes.
So, for example, every time the field "category" changes, I'd need to have a total of sales for that category, and a header showing that another category listing is starting; and then do the same when the field "group" - with the added interest that "group" is made up of categories, so the two things should nest.
I guess anyone that has built reports with Microsoft Access (or probably any other business reporting application) should be familiar with the problem.
Ideally this would be solved at a meta-level, so I don't have to rebuild the code every time, but only to specify what fields should generate breaks or subtotals.
I am (voluntarily) constrained to LaTeX and TT: LaTeX because of the control it gives over typography, and the possibility of generating custom graphics, and TT (or anything else that works in perl) because of learning curves.
There's no built-in subtotaling feature in TT, but you could possibly put your data into a Data::Table object, that would give you some ability to handle subtotaling at the 'meta' level, as you say.
Depending on the number of columns involved though, it might be just as simple to create local hashes to maintain running totals: NB: untested, example code only
[%-
MACRO printrow(rowtype, line) BLOCK;
# however you print the row as LaTeX
# rowtype is 'row', 'subtotal' or 'grandtotal' for formatting purposes
END;
SET sumcols = [ 'col3', 'col4', 'col5' ]; # cols to be accumulated
SET s_tot = {}; SET g_tot = {};
FOREACH i IN sumcols;
SET s_tot.$i = 0; # initialise
SET g_tot.$i = 0;
END;
FOREACH row IN data;
IF s_tot.col2 AND s_tot.col2 <> row.col2; # start of new group
printrow('subtotal', s_tot);
FOREACH i IN sumcols;
SET s_tot.$i = 0; #re-init
END;
END;
printrow('row', row);
SET s_tot.col2 = row.col2; # keep track of group level
FOREACH i IN sumcols;
SET s_tot.$i = s_tot.$i + row.$i;
SET g_tot.$i = g_tot.$i + row.$i;
END;
END;
printrow('grandtotal', g_tot);
-%]
Of course, if you have more than a couple of grouping levels, this can get quite messy. You could make s_tot an array of hashes to manage each level, to avoid hard-coding the levels. That's left as an exercise for the reader, as they say.
I have a .m file where I do some actions with Simulink model, and I would like to check if the currently used model is the entire model or a subsystem. Is there a specific syntax or function to check this? I need to be able to perform actions differently depending on Simulink system.
You can always use bdroot to get the name of the top level system and use string comparison to see if you have a subsystem or not:
sysname = 'f14/Actuator Model';
istoplevel = strcmp(bdroot(sysname), sysname);
isEntireModel = isequal( get_param( gcs, 'Type' ), 'block_diagram' );
Can you try this, after opening your model, or replace gcs with system name [make sure load it before using either with load_system or open_system]:
h=find_system(gcs,'FindAll',1,'SearchDepth',1,'BlockType','SubSystem');
if isempty(h)
disp('Has Subsystems');
else
disp('No Subsystems');
end
h=find_system(gcs,'FindAll',1,'SearchDepth',1,'BlockType','ModelReference');
if isempty(h)
disp('Has Models');
else
disp('No Models');
end
easier way would be, say your model name is vdp, then:
bdIsLoaded('vdp')