SlickGrid row attribute syntax? - object

<rant>I'm getting downright frustrated with the lack absence of documentation for SlickGrid.</rant>
Sorry -- now that that's out of my system . . .
I'm trying to figure out the correct syntax for returning a value in a cell in a row. For example, let's say I have the following data:
ID Object Color
1 This Red
2 That White
3 OtherThing Blue
I want to do something similar to this (I'll use the onMoveRows event as an example):
grid.onMoveRows = function (rows, insertBefore) {
for (var i = 0; i < rows.length; i++) {
if (rows[i].Color == "Blue") {
// do something
}
}
};
The rows[i].Color == "Blue" is my issue. I don't know the proper syntax for this (or even if this is possible), I can't find it documented anywhere, and I don't want to waste my time trying to figure it out (I've already spent a couple of hours trying to do so).
Can someone clue me in?
Thanks in advance . . .

'rows' is an array of row numbers that are being moved.
For example, if you selected rows 1,2 and 5, the 'rows' will contain [0,1,4] (it's 0-based).

Related

How to use lambda functions in f strings and return the value conditionally?

I've googled a lot but can't seem to find anything about this problem, or maybe since I'm a noob I'm not searching the correct keywords. I did find one question but it was using an f-string inside a lambda function which is the exact opposite of what I need.
So I have a counter flag called tc which checks if the sum of two numbers exceeds a certain predefined constant. The counter flag works fine and gets 1 or 0 correctly. The thing I can't do is the next part of the program.
I want to directly check the condition and return it in an f-string.
Till now I've been able to make this.
timE = f"({(lambda x: x = 'next' if tc==1 else x = 'same')} day)"
print(timE)
What I get is
File "<fstring>", line 1
((lambda x: x = 'next' if tc==1 else x = 'same'))
^
SyntaxError: invalid syntax
What I need is if tc is 1 then the lambda function should return next else same.
And then the final result I need is either (next day) or (same day).
I did try some other thing which does not give me an error but is giving me something else.
timE = f"({(lambda : 'next' if tc==1 else 'same')} day)"
The output I'm getting here is
03:08 AM, (<function add_time.<locals>.<lambda> at 0x7fe5b4660dc0> day)
I know what I'm trying to do is somehow in someway possible in some hacky way, but I can't seem to find it.
Any help is appreciated
Why not just this? You do not need a lambda here.
timE = f"({'next' if tc==1 else 'same'} day)"

Connect string value to a corresponding variable name

This question has somehow to do with an earlier post from me. See here overlap-of-nested-lists-creates-unwanted-gap
I think that I have found a solution but i can't figure out how to implement it.
First the relevant code since I think it is easier to explain my problem that way. I have prepared a fiddle to show the code:
PYFiddle here
Each iteration fills a nested list in ag depending on the axis. The next iteration is supposed to fill the next nested list in ag but depending on the length of the list filled before.
The generell idea to realise this is as follows:
First I would assign each nested list within the top for-loop to a variable like that:
x = ag[0]
y = ag[1]
z = ag[2]
In order to identify that first list I need to access data_j like that. I think the access would work that way.
data_j[i-1]['axis']
data_j[i-1]['axis'] returns either x,y or z as string
Now I need to get the length of the list which corresponds to the axis returned from data_j[i-1]['axis'].
The problem is how do I connect the "value" of data_j[i-1]['axis'] with its corresponding x = ag[0], y = ag[1] or z = ag[2]
Since eval() and globals() are bad practice I would need a push into the right direction. I couldn't find a solution
EDIT:
I think I figured out a way. Instead of taking the detour of using the actual axis name I will try to use the iterator i of the parent loop (See the fiddle) since it increases for each element from data_j it kinda creates an id which I think I can use to create a method to use it for the index of the nest to address the correct list.
I managed to solve it using the iterator i. See the fiddle from my original post in order to comprehend what I did with the following piece of code:
if i < 0:
cond = 0
else:
cond = i
pred_axis = data_j[cond]['axis']
if pred_axis == 'x':
g = 0
elif pred_axis == 'y':
g = 1
elif pred_axis == 'z':
g = 2
calc_size = len(ag[g])
n_offset = calc_size+offset
I haven't figured yet why cond must be i and not i-1 but it works. As soon as I figure out the logic behind it I will post it.
EDIT: It doesn't work for i it works for i-1. My indices for the relevant list start at 1. ag[0] is reserved for a constant which can be added if necessary for further calculations. So since the relevant indices are moved up by the value of 1 from the beginning already i don't need to decrease the iterator in each run.

How to find all maximum value between every i and i + k(some constant) of a given array?

I need to find all maximum values among elements of every possible set {a[i], a[i+1],... a[i + k]} (where i is index and k is some given constant). For this I am using.
loop(b, 1, k) {
rloopl(i, b, n) {
if(a[i] < a[i-1])
a[i] = a[i-1];
}
}
but its too slow for large array. Is there any other more efficient way to do this?
I'm very sorry to tell you that, with the requirement as-presented, the answer would be: "no." If "the largest value could be anywhere," you have no choice but to "look ... everywhere."
If you are "doing this 'once and only once,'" for any particular data-set, then you're basically just gonna have to take your lumps. You're stuck with "brute-force."
However, if you're doing this more than once, and/or if you have some influence on the process by which the array in question gets loaded, the situation might start looking a little better.
For instance, if another piece of code is adding elements to this array one-at-a-time, it's trivial for that piece of code to notice the max/min value that it encounters. Code that loads a two-dimensional array might gather statistics about each row (column). And, so on. Such strategies, which are "free, at the time," can be used to eliminate (or, severely curtail) the need to do specific brute-force searches later.

Swap Date around on a Natural Programming language variable?

I am trying to find a way to flip a date around in the natural programming language.
What I have is a #DOB which is equal to 19700830 yyyymmdd and I need it to be mmddyyyy. Is there an easy way to do this in Natural?
Question: How can I flip the date around to my specific format the easiest and most
efficient way in Natural?
Code:
RESET #NAME(A21/25)
#ROLE(A7/25)
#DOB(A10)
#I(P3)
#ADC(A1/25)
#SSN(A9)
I have tried using the FOR loop to get my results, but it is bulky and won't compile as of yet.. It is bulky at best.
FOR INDEX(P3) FROM 1 TO 8
IF INDEX >= 1 AND INDEX <= 4
#YYYY = #DOB(INDEX)
IF INDEX >= 5 AND INDEX <= 6
#MM = #DOB(INDEX)
IF INDEX >= 7 AND INDEX <= 7
#DD = #DOB(INDEX)
LOOP
This is what I would like to do but I am not completely certain that it will work. I think there is a better way but I do not have any real great books on the language and it is something that I do not do all that often. Once or twice a year so it is new to me.
The easiest way to do this is two redefine your variable and them just move and use the pieces of the redefine.
DEFINE #DOB(A10)
REDEFINE #DOB(#Y(A4) #M(A2) #D(A2))
Then you can just use the piece and move them around the way that you want.
WRITE WORK FILE 2 #M ',' #D ',' #Y

I want Flood Fill without stack and without recursion

I wanted to know how to apply flood fill on array , my array is two dimensional , which contains times new roman font type letter boundry.
The boundry line contains 1's and inside and outside all 0's.
I want to fill all 1's instead 0 in only inside.
But i need a logic which do not required more memory.
So avoid recursion and stack or queue
I don't normally do homework for other people, but I liked the challenge:
int c = -1;
while (c < 0)
{
/* Store breadcrumb trail, look to carry on */
a[x][y] = c--;
if (!hunt(0))
{
/* Nowhere to go, so back-track by looking for breadcrumb */
a[x][y] = 1;
c += 2;
hunt(c);
}
}
bool_t hunt(int v)
{
if (a[x-1][y] == v) { x--; return TRUE; }
if (a[x+1][y] == v) { x++; return TRUE; }
if (a[x][y-1] == v) { y--; return TRUE; }
if (a[x][y+1] == v) { y++; return TRUE; }
return FALSE;
}
Note that this doesn't check for hitting the edges of the array. Also, it assumes your array elements are e.g. ints, and that you're only using the values 0 and 1 in your image.
Your task doesn't make much sense. If you have a typeface, you don't want to fill it with a flood fill, but rather render it directly as filled polygon instead. Determining which parts are in and out of the typeface, especially for a serif font, if not going to give good results reliably.
The typical schematic algorithm for a filled polygon goes like this (no stack or recursion required), and it can be applied to a bitmap as well under certain conditions (I'll come to that):
For each line (or column, whatever suits your data structure better), toggle the fill at each intersection of the virtual line you're following and all polygon lines (boundaries).
Assume this (could be the middle line of an O character):
00010010001001000
^ ^ ^ ^
| | | stop
| | start
| stop
start
Result:
00011110001111000
This works for bitmaps as well, but only if you actually always have two boundaries for start and stop.
function LowMemFloodFill(pixel)
FillPixel(pixel)
Do
didFill = false
For each pixel
If current pixel has been filled
For each adjacent pixel
If adjacent has not been filled
FillPixel(adjacent)
didFill = true
End
End
End
End
While didFill
End
The catch is that you must be able to tell that a pixel has been filled (fill it with an unused color). Also, this would be extremely slow.
You basically can't. You have to store this information somewhere, because you have to know where else to start filling after you're done with your current section. Recursion lets you do it implicitly. Keeping your own stack lets you do it explicitly, with possibly some saving. Oli Charlesworth does a cute thing by keeping an array of the same size as the picture, but that uses even more memory than recursion or keeping a stack of positions.

Resources