Tag history in database-How to find tag names

Hi,

In my project, tag history is stored in database, using historian concept. However, tags are stored under id and value columns.

I have to export a CSV file of tag history, for the previous month. I’m thinking to create a report with sql query, to fetch the tag values. However, tags are not stored in database using its names.

Please let me know how to find the tag names in database.

Check out docs.inductiveautomation.com/di … TagHistory and below I have provided an example of my use of this.

I am reading from 64 historical tags and based on the timestamp then writing them to a memory tag in a folder with suffix ‘hist’.

The DB connection (in my gateway) is called ‘MySQL’ and you need to specify this in front of the tag path

dataSet = system.tag.queryTagHistory([color=#0040BF]paths=[’[MySQL]’ + path_read], [/color]

[code]import datetime
#startTime = event.source.parent.getComponent(‘Historical Replay’).timeCurrent
#endTime = event.source.parent.getComponent(‘Date Range’).endDate

#use for testing in script console, comment out in designer
startTime = datetime.datetime.now() - datetime.timedelta(days=10)
endTime = startTime + datetime.timedelta(minutes=1)

nests = range(1,9)
stations = [“1a”, “1b”, “2a”, “2b”]
function = [“laser weld”, “leak test”]

#build path

for function in function:
#system.tag.write(‘LW6APLC/script_done’, 0)
if function == “leak test”:
a = "leak "
elif function == “laser weld”:
a = “”
for station in stations:
for nest in nests:
path_read = “LW6APLC/” + "positional " + function + " " + “fails/” + a + station + " " + “nest” + " " + str(nest)
print path_read
dataSet = system.tag.queryTagHistory([color=#0040BF]paths=[’[MySQL]’ + path_read], [/color]startDate=startTime, endDate=endTime, aggregationMode=“Maximum”, returnSize=0, returnFormat=‘Wide’)
print dataSet
y = system.dataset.toPyDataSet(dataSet)
if len(y) > 0:
z = y[0][1]
print z
path_write = “LW6APLC/” + "positional " + function + " " + “fails hist/” + a + station + " " + “nest” + " " + str(nest)
print path_write
system.tag.write(path_write, z)
#system.tag.write(‘LW6APLC/script_done’, 1)[/code]

Thanks a lot for your reply. It was very useful.

Regards
Sudha

Hi,

I have a query here.

Is it possible to get the distinct tag values, using this ‘Tag History’ option? Will ‘Aggregation Mode’ be helpful in this case?