IBM ODM - How Iterate over column rows (like in a given example) - loops

How in IBM ODM to iterate through each row of decision table column and insert each value of row into method for calculations and finally check which values returned by method is the smallest.
For example:
1. Step
For every row of column Bn where A = A1 do:
SomeMethod.calculate(B1) return C1 = 10;
SomeMethod.calculate(B2) return C2 = 40;
SomeMethod.calculate(B3) return C3 = 5;
2. Step
And get minimum of Cn values.
In my example it is 5.
Thanks in advance!

Related

Convert string to variable name in Lua

In Lua, I have a set of tables:
Column01 = {}
Column02 = {}
Column03 = {}
ColumnN = {}
I am trying to access these tables dynamically depending on a value. So, later on in the programme, I am creating a variable like so:
local currentColumn = "Column" .. variable
Where variable is a number 01 to N.
I then try to do something to all elements in my array like so:
for i = 1, #currentColumn do
currentColumn[i] = *do something*
end
But this doesn't work as currentColumn is a string and not the name of the table. How can I convert the string into the name of the table?
If I understand correctly, you're saying that you'd like to access a variable based on its name as a string? I think what you're looking for is the global variable, _G.
Recall that in a table, you can make strings as keys. Think of _G as one giant table where each table or variable you make is just a key for a value.
Column1 = {"A", "B"}
string1 = "Column".."1" --concatenate column and 1. You might switch out the 1 for a variable. If you use a variable, make sure to use tostring, like so:
var = 1
string2 = "Column"..tostring(var) --becomes "Column1"
print(_G[string2]) --prints the location of the table. You can index it like any other table, like so:
print(_G[string2][1]) --prints the 1st item of the table. (A)
So if you wanted to loop through 5 tables called Column1,Column2 etc, you could use a for loop to create the string then access that string.
C1 = {"A"} --I shorted the names to just C for ease of typing this example.
C2 = {"B"}
C3 = {"C"}
C4 = {"D"}
C5 = {"E"}
for i=1, 5 do
local v = "C"..tostring(i)
print(_G[v][1])
end
Output
A
B
C
D
E
Edit: I'm a doofus and I overcomplicated everything. There's a much simpler solution. If you only want to access the columns within a loop instead of accessing individual columns at certain points, the easier solution here for you might just be to put all your columns into a bigger table then index over that.
columns = {{"A", "1"},{"B", "R"}} --each anonymous table is a column. If it has a key attached to it like "column1 = {"A"}" it can't be numerically iterated over.
--You could also insert on the fly.
column3 = {"C"}
table.insert(columns, column3)
for i,v in ipairs(columns) do
print(i, v[1]) --I is the index and v is the table. This will print which column you're on, and get the 1st item in the table.
end
Output:
1 A
2 B
3 C
To future readers: If you want a general solution to getting tables by their name as a string, the first solution with _G is what you want. If you have a situation like the asker, the second solution should be fine.

Compare two arrays in VueJS with their ID

I have two arrays the first array is gulod_transaction and the second is gulod_medicine. I want to compare the two arrays with there id’s to minus the quantity from the medicine table to the quantity of transaction table. The main problem is when I add the second row first from table medicine to the transaction table. And click the Save Transaction button. In my console.log it’s minus the first row which is 40 from my first table to transaction table quantity which is equal to 10 and the result becomes 30. I want to minus both quantity if they have the same id’s.
for(let index = 0; index < this.gulod_transactions.length; index++) {
if (this.gulod_transactions[index].id === this.gulod_medicines[index].medicine_id) {
this.medicine_id = this.gulod_transactions[index].id;
this.medicine_name = this.gulod_transactions[index].name;
this.medicine_quantity = (parseInt(this.gulod_medicines[index].quantity) - parseInt(this.gulod_transactions[index].quantity));
this.medicine_price = this.gulod_transactions[index].price;
this.gulod_medicine_barangay_id = 1;
console.log(this.gulod_medicines[index].quantity);
console.log(this.gulod_transactions[index].quantity);
console.log(this.medicine_quantity);
}
}

loop through arrays in postgresql table return based on condition and array element position

I have the following row in a table in a posgresql db:
INSERT INTO "public"."position" ("id",
"layout_id",
"dining_table_id",
"x_position",
"y_position",
"translate_x",
"translate_y",
"rotation",
"start_timestamps",
"end_timestamps")
VALUES (683, 32, 683, 1288, 0, E'{0,25}', E'{134,-98}', 0, E'{"2019-03-05 10:24:00","2019-04-05 10:24:00"}', E'{"2019-03-05 21:00:00","2019-04-05 21:00:00"}');
I want to make an query, which returns me:
x_position
y_position
rotation
and
translate_x
translate_y
But in those columns only if the following condition is met:
If a given timestamp (which comes from the front end and should be part of the condition of the query) is bigger or equal to the start_timestamps and smaller than the end_timestamps array element, which have the same position in the array as the translate_x and translate_y array elements.
So for example if the given timestamp is: 2019-03-05 12:00:00
the array element of the translate_x column with the value 0 (position 0) and the
array element of the translate_y column with the value 134 (position 0) should be returned, because 2019-03-05 12:00:00 is smaller than end_timestamps columns array element (position 0) and is bigger or equal than the start_timestamps columns array element (position 0).
My question is how can I query the table accordingly? (I hope my table structure makes sense)
My try:
const result = await this.db.query(`
SELECT
p.x_position,
p.y_position,
p.rotation,
FROM POSITION p
DECLARE
s int8 := 0;
x int;
BEGIN
FOR x IN s..p.start_timestamps.length LOOP IF p.start_timestamps[x] <= $1
AND p.end_timestamps[x] > $1 THEN RETURN p.translate_x[x], p.translate_y[x] END LOOP;`
[timestamp]);
If If I understood correctly, you can do something like this:
select * from (
select i,id,layout_id,dining_table_id,x_position,y_position,translate_x[i],
translate_y[i],start_timestamps[i],end_timestamps[i] from (
select generate_subscripts(translate_x,1) i,* from position
) a
) b where start_timestamps<='2019-03-05 12:00:00'::timestamp
and end_timestamps>'2019-03-05 12:00:00'::timestamp
It should work, but if you can change the definition of your database, you should create a new table for example:
position_periods : (id_position integer ,start_timestamp timestamp,end_timestamp timestamp,translate_x integer,translate_y integer)

MATLAB Extract all rows between two variables with a threshold

I have a cell array called BodyData in MATLAB that has around 139 columns and 3500 odd rows of skeletal tracking data.
I need to extract all rows between two string values (these are timestamps when an event happened) that I have
e.g.
BodyData{}=
Column 1 2 3
'10:15:15.332' 'BASE05' ...
...
'10:17:33:230' 'BASE05' ...
The two timestamps should match a value in the array but might also be within a few ms of those in the array e.g.
TimeStamp1 = '10:15:15.560'
TimeStamp2 = '10:17:33.233'
I have several questions!
How can I return an array for all the data between the two string values plus or minus a small threshold of say .100ms?
Also can I also add another condition to say that all str values in column2 must also be the same, otherwise ignore? For example, only return the timestamps between A and B only if 'BASE02'
Many thanks,
The best approach to the first part of your problem is probably to change from strings to numeric date values. In Matlab this can be done quite painlessly with datenum.
For the second part you can just use logical indexing... this is were you put a condition (i.e. that second columns is BASE02) within the indexing expression.
A self-contained example:
% some example data:
BodyData = {'10:15:15.332', 'BASE05', 'foo';...
'10:15:16.332', 'BASE02', 'bar';...
'10:15:17.332', 'BASE05', 'foo';...
'10:15:18.332', 'BASE02', 'foo';...
'10:15:19.332', 'BASE05', 'bar'};
% create column vector of numeric times, and define start/end times
dateValues = datenum(BodyData(:, 1), 'HH:MM:SS.FFF');
startTime = datenum('10:15:16.100', 'HH:MM:SS.FFF');
endTime = datenum('10:15:18.500', 'HH:MM:SS.FFF');
% select data in range, and where second column is 'BASE02'
BodyData(dateValues > startTime & dateValues < endTime & strcmp(BodyData(:, 2), 'BASE02'), :)
Returns:
ans =
'10:15:16.332' 'BASE02' 'bar'
'10:15:18.332' 'BASE02' 'foo'
References: datenum manual page, matlab help page on logical indexing.

Replace first 4 rows with values from rows 5:8 arcpy

I am trying to replace the values in the first 4 rows of a attribute table with the row values from the next 4 rows 5:8 in an attribute table using arcpy.da.UpdateCursor. Is there a simple way to index rows 1:4 (all columns) and replace with values from rows 5:8.
Here is my code thus far:
targetFC = r"D:\ZOC\POLYPGDIS_MASTER_1.shp"
dsc = arcpy.Describe(sourceFC)
fields = dsc.fields
# List all field names except the OID field
fieldnames = [field.name for field in fields if field.name != dsc.OIDFieldName]
with arcpy.da.UpdateCursor(targetFC, fieldnames) as cursor:
for row in cursor:
row[1:4] = row[5:8]
cursor.updateRow(row)
Thanks
I think the easiest way would be to load the data into a list.
Note if you are working with a RDBMS the row order is not certain so this probably would not work unless you sorted by something.
eight_rows = []
k = 0
with arcpy.da.SearchCursor(targetFC, fieldnames) as rows:
for row in rows:
eight_rows.append(row)
k += 1
if k == 8: break
k = 5
with arcpy.da.UpdateCursor(targetFC, fieldnames) as rows:
for row in rows:
row = eight_rows[k]
k += 1
rows.updateRow(row)
if k == 8: break

Resources