Linking a history tag to multiple history tags in easy chart

Hi!

I have 3 tags that i obtain through modbus registers. One tag contains the value. Another tag contains a part of the device location and the third tag contains the remaining part of the device location.

Eg Tag1 : Level of tank
Tag2 : tank number
Tag3 : Area location.

The PLC that i communicate with dynamically changes these tags to reflect the tank with the lowest level.
I need to plot the history of this. i.e. for a given time frame i should know which tanks went to low level.
I can link the Tag 1 to the easy chart. I would like to know if it is possible to link tag2 and tag 3 to the same chart, such that when i use the x trace and scroll, i could see the tank level as well as the information about the location of the tank. ( tag2 and tag3 plot should not be visible in the chart)
I could use cell binding of the name and get the desired format, but the name would only give me the instantaneous value of tag 2 and tag3. So it will not work.
The next thing that i could do is plot both tag 3 and tag2 and use xtrace while making the pen the same color as the background. This too doesn’t materialize because the x-trace feature displays the value in the same color as the tag. So if i make it the same as background I can;t see the value through x-trace.

Looking forward to a solution.

Are tag 2 and tag 3 string tags?

Tag2 and Tag3 are integer tags. i have to derive the string from these two tags.

I don’t know if this is the easiest way, but I tried doing it by passing the xtrace value as a parameter and running a script.

def id(value): import system import calendar import time x = time.strp(value,"%Y-%m-%d %H:%M:%S") # the xtrace only return time in yyyy-mm-dd HH:MM:SS (no milliseconds) y = calendar.timegm(x) #gateway and database installed in Ubuntu, and database time stamp is in posix query = "SELECT intvalue FROM mytable WHERE t_stamp = %f AND id = 151 "%(y) results = system.db.runQuery(query) z = results[0][0] # some calculation will be done to derive location, but i'll leave it for now return z

the problem is that the database stores the value in posix format in milliseconds :13 digits .
however the xtrace value sent is till seconds, thus posix is 10 digits.
so i am unable to read from the table.
if xtrace could send value with millisecond resolution then posix - 13 digits.
but that is not the case here.

Looking forward to a solution or perhaps a better method of tackling the problem

I am not sure if I have exactly what you want. Anyways, the easy chart and the classic chart have a property called “Selected X Value” which is a date. You can use the date they select to lookup in another dataset somewhere on the window for tag2 and tag3 values. You can then do a switch statement to turn the number into a string. You won’t be able to display it inside of the chart but you can make labels below the chart. I have attached a small example. Go into preview mode and do the x-trace and you will see labels below fill in.

Chart_Example.proj (25.4 KB)

I need to access the historical data of tag2 and tag3 corresponding to the selected timestamp(SelectedXValue).
This can be linked to a label outside the chart.
Eg :

when i select a particular time stamp through the xtrace. I should be able to access the value of tag2 and tag3 for that timestamp. In my tank example, tag 1 is the level of the tank with the lowest level, that is displayed on the chart. Tag2 and tag3 corresponds to the location of that tag and keeps changing. there are about 150 such locations.
So when I use the xtrace the value of the lowest level is displayed on the chart itself. But i would like to display the location of the tank with the lowest level for the selected timestamp.
tag2 and tag3 keep changing as the tank with the lowest level (tag1) changes.

Looking forward to a solution

Right now you can’t display the text for tag 2 and tag 3 when using x-trace. The chart only displays numeric data. You can only display it in a label on the window. Once you have the selected date/time, like in my example, you should be able to derive the value of tag 2 and tag 3.

I want to display it in a label only. But i am facing a problem while accessing the data for tag2 and tag3 for a given selectedxvalue.
tag 2 and tag3 store historical data related to the area and location for a particular time instant.
Eg : if at 4 PM the the lowest level is 10m , for a tank in location B10 and Area C6.
Tag1 = 10
Tag2 = 20
Tag3 = 18

    at 4:40 PM the lowest level is 8m for a tank in location C10 and Area D6
     Tag1 = 8 
     Tag 2 = 30 
      Tag 3 = 24

I plot tag1 on the chart. I have a label below the chart. when i have selected the xvalue at any time, the label below should show the area location corresponding to tank with lowest level.
Eg when my selected value on chart is 4:30 PM,
the label below should read D6C10.
I believe historical access may be required.

I use the label text and write the following code expression linked to the label text:

runScript("app.mac.id({'''SelectedXvalue"'})",0)

in the script module i have defined a module mac which contains the following code.

def id(value): import system import calendar import time x = time.strp(value,"%Y-%m-%d %H:%M:%S") # the xtrace only return time in yyyy-mm-dd HH:MM:SS (no milliseconds) y = calendar.timegm(x) #gateway and database installed in Ubuntu, and database time stamp is in posix query = "SELECT intvalue FROM mytable WHERE t_stamp = %f AND id = 151 "%(y) results = system.db.runQuery(query) z = results[0][0] # some calculation will be done to derive location, but i'll leave it for now return z

I encounter a problem with this.

the problem is that the database stores the value in posix format in milliseconds :13 digits .
however the xtrace value sent is till seconds, thus posix is 10 digits.
so i am unable to read from the table.
if xtrace could send value with millisecond resolution then posix - 13 digits.
but that is not the case here.

I hope my problem is cleared

I can’t test this out right now but I would start with something like this if you were using MySQL -

def id(value): import system import calendar import time x = time.strp(value,"%Y-%m-%d %H:%M:%S") #gateway and database installed in Ubuntu, and database time stamp is in posix query = "SELECT intvalue FROM mytable WHERE FROM_UNIXTIME(t_stamp/1000) = %s AND id = 151 "%(x) results = system.db.runQuery(query) z = results[0][0] # some calculation will be done to derive location, but i'll leave it for now return z
You can find more information on converting the Historian Timestamps here - inductiveautomation.com/support/kb/142

If that doesn’t work you could always give your query a range of time to search through, i.e. WHERE t_stamp > (myTime - 1 second) AND t_stamp < (myTime + 1 second)

Hi!

I m using postgresql. the time sent by selectedxvalue is without millisecond resolution. the database stores the values with time stamp in posix with 13 digits (with milliseconds).
when i converted the selectedxvalue (timestamp) to posix i get the value in seconds 10 digits considering any date in January. I can’t multiply this with 1000 to convert to millisecond and query for data. The reason is that the database time stamp is not in such multiples.

I got to solve the problem in an easier way. I used the method shown in Mr Travis.Cox’s reply with the attachment, with a slight modification. I linked the history chart start date and end date to a calendar component. The other dataset(tag2 and tag3) was also configured with the same calendar component.Using the ‘selectedxvalue’ and ‘lookup’ function i passed the tag2 and tag3 as parameter to a script where i evaluated the location and sent the result to a label.
problem solved. Thank you Mr Travis. :thumb_right: