Mapping a tag output from 1000 input values

Is there a way to get the map transform on a tag so I can map all 1000 variations of a tag I am reading as input to multiple columns of outputs?
And how so I easily access those outputs?

Here is what I am trying to do.

I am working in perspective on some pages.

I have a tag that gives me values 1-1000, a code

I need to interpret those values into either a 1, 2, 3, or 4.

I think that after I have these mapped, I will have to map another 1000 sets of text to the 1000 values.
Might even have to map two sets.

So I thought the transform in the tag bindings is really nice as it has multiple columns for mapping.

I will need to place labels that read the text fields when these codes come up.
I will need toggle some graphic visibilities when the 1-4 numbers come up.

I think I can possibly use the regular binding transform for this mapping.
I just am not sure how it will work, or if there is a better way.
Like I could hit the plus sign 1000 times and type each entry from my spreadsheet to the mapping.
I just would prefer if I could do some copy and pasting instead.
This is just the first of many machines.

I’d probably put all this mapping logic into a script module and then use a script transform to just call those functions and ask for the transformed value.

1 Like

When you say script module, you mean a script in the scripting section?

And I am not sure how that would be structured.
you mean like four long if conditions for the 1-4?
if(code=(1 or 2 or 3…or N) then value =4

I am not sure how it would work for the strings.
1000 if conditions to pair the code number to the text?

Use excel to concat the text all together to make the code fast?

Maybe something like this:

code_map = {
	1 : 1,
	2 : 2,
	3 : 3,
	4 : 4,
	5 : 1,
	...
}

text_map = {
	1 : "text for 1",
	2 : "text for 2",
	3 : "text for 3",
	...
}

fun get_code(v):
	return code_map[v]

fun get_text(v):
	return text_map[v]

I want to test this.

Is this the way to test?
I make a script in the project library with the mapping.
I make a label for the text.
In the label for the text, I bind the text with a script that calls my script with the tag for the code as a parameter.
Then I see if the value is written to the label correct?

I think the spots I will need help with are like where to put the script.
I think it goes in a folder in my project library.

I have many machines, so I am going to watch the script video again.
I don’t see a way to make folders for my scripts to separate them for the machines.
I see script packages, but I don’t know what that means so I will do some research and then test.

Thanks for the help. I will update when I have tested.

I am mucking it up. In the script transform I had typed:

codescript get_code(value)
	return code_map[value]
return value

I named my script “codescript”
in the script I copied

code_map = {
1 : 1,
2 : 2,
3 : 3,
4 : 4,
5 : 1,
}

I am pretty certain that I am doing the call wrong.
going to watch the videos again

It would be codescript.get_code instead of codescript get_code (period vs space), wouldn’t it?

I didn’t make a get_code() method.

I just have a code_map dictionary

I messed it up lol

Okay, I found the most relevant video I think.
https://inductiveuniversity.com/videos/project-scripts/8.0

Now I go back to my project script.

instead of

fun get_code(v)

I instead write like

def get_code(v)

?


then on my call in the script transform for the text of the label it is like:

project.codescript.get_code(value)
return value

?


I realize how silly codescript is as a script name. I promise I am using a different name more relevant to the actual machine.

Capture

I have replaced “get_code” with “get_location”

whoops
still broke though

I am doing multiple things wrong and trying to figure them out

I am pretty sure that my call is wrong, project is not recognized

you can reduce the call to machine1.get_code(v). The ‘project’ is not necessary.

omg it is alive

I was missing a colon and like you said, shortened to machine1.get_location(value)

works now, I think

So I want to ask like when orginally it was said like

fun get_code(v):

the “fun” was just something generic that an experienced ignition implementer would recognize as “def” right away?

or does “def” have certain characteristics and there are alternative keywords used there?

Thanks very much for the help you guys

fun was probably a typo because Kevin usually writes Kotlin, which uses fun where Python uses def.

2 Likes

thanks very much

Is that pattern always consistent? 1:1, 2:2, 3:3, 4:4, 5:1… 9:1, 10:2 … 487:4, 488:1 ?

I think you are asking me specifically about my dictionaries.
I am making a dictionary for each of the different things associated with my code (number that means a lot of things) despite knowing that I could make a dictionary of lists for each code.

I have a code come in.
I use the dictionaries for different sets strings and numbers.
I some strings in different spots.
I use the numbers to then change some images and references associated.
I used some of the numbers different spots.

If you are asking in general, then a dictionary can be a dictionary of dictionaries, integers, strings, or lists.
I think of it is kind of like linked lists.

Did you have some feedback for me or ideas you meant to suggest?
Did I answer the question adequately?

I think what @drastura is getting at is that if your pattern is consistent, you can easily reduce it to a general algorithm; the modulo operator is your friend here, e.g.:

def get_code(i):
	return (i % 4) + 1
>>> for i in range(10):
...   print(i, ":", get_code(i))
0 : 1
1 : 2
2 : 3
3 : 4
4 : 1
5 : 2
6 : 3
7 : 4
8 : 1
9 : 2

Thanks both of you.

That is really cool.

I wish it had been that way.

It is more categorically unique rather than a numeric pattern unfortunately.

1 Like

My script is in the project library.
My call is on an object in the view.

So every client is going to check the condition of the machine and workout how the image on the view should look.

Is there a way to do that to reduce the workload?
Is that something to really worry about or is it more typical?

I am thinking about receiving all my faults as a number and then using a dictionary to produce the text for the fault code.

I need help to understand how this will impact the server. If the dictionaries are in the project library, and the calls are on perspective pages, is that a lot of work for the server compared to another way?

Is it better to set the message to a tag first, and then use the tag in the views?
If so, how do I pull that value from the dictionary into a tag?