I have a dataset (.csv) with no timestamp in it and I need to store this data in PI at exactly midnight. I tried manipulating NOW() but it's not working.
Hi Raja Sekhar Gudibandi,
I think there's a better way than hard coding the timestamp, or scheduling the scan once a day. I agree, you should be able to scan more frequently, and easily write the values in the .csv to today's midnight.
The following .ini should do the trick. It will parse out the output of NOW() and make sure a timestamp of midnight is applied. Note, the MSG processing assumes the columns are comma separated.
[FIELD]FIELD(1).NAME="Tag"FIELD(1).TYPE="String"FIELD(2).NAME="Value"FIELD(2).TYPE="Int32"FIELD(3).NAME="DD"FIELD(3).TYPE="Int32" FIELD(4).NAME="MMM"FIELD(4).TYPE="Int32" FIELD(5).NAME="YYYY"FIELD(5).TYPE="Int32" Field(6).NAME="Timestamp"Field(6).TYPE="DateTime"FIELD(6).FORMAT="d-M-yyyy hh:mm:ss" [MSG]MSG(1).NAME="MSG_1" [MSG_1]MSG_1.FILTER=C1=="*"Tag=["(*),*"]Value=["*,(*)"] DD=DAY(NOW())MMM=MONTH(NOW())YYYY=YEAR(NOW()) Timestamp=CONCAT(TOSTRING(DD),"-",TOSTRING(MMM),"-",TOSTRING(YYYY)," 00:00:00") StoreInPI(Tag,,Timestamp,Value,,)
Hope this helps!
Dear Raja Sekhar,
Could you please provide the sample data format.
Thanks & Regards
You can provide date format as mentioned in UFL designer.
Ex: 26-feb-20 00:00:00
I am sure that there will be better solution than the below one.
Here is my solution for achieving your requirement. In the .ini file you have update the Time_Stamp of your interest.
My assumption here is that the tag name and value are separated by a (,) coma and there is no extra header information available in the input file.
I run this interface once every day. My Time_Stamp cannot be a static. Any idea to get make the Time_Stamp dynamic ?
You can give exact time stamp whenever you upload data in CSV file.
Ex: 26-feb-20 00:00:00 or 26-feb-20 14:30:00
You can also update the Field(2). Format according to your requirement. If you update only time format as dd-mm-yyyy then by default tag will tag value at 12:00:00 AM.
I want it to be automatic with no manual interaction and this update has to happen midnight every day.
You no need to run interface whenever you are uploading csv file. Interface will refresh and upload data to tags whenever new csv file added into shared path which is mentioned in UFL designer based on scan frequency.
If you are uploading csv file once a daily then give data in below format. If you would like to add value to the tags with specific timestamp then provide timestamp in csv file else just give date so that by default it will take 12:00:00 AM.
Tag name, timestamp , value
My .csv doesn't have a TimeStamp column. Is it possible to for the interface to store events at current day's midnight ?
For example, we have now() to store events at the interface run time. Can i do something similar to store data at midnight ?
Along with the below .ini file settings please set the Scan frequency to 24:00:00,00:00:00 as shown below and configure the same scan class for the UFL tags. This will execute the UFL interface every 24hrs at 00:00 hours and the same time stamp will be written to the UFL tags.
It's not recommending to give scan class as 24 hrs since UFL process manual data. If someone upload data today at 12:00:30 AM then UFL will process at tomorrow at 12:00:00 AM since scan class is 24 hrs. This is valid only when manually uploading CSV file. We can give scan as 24 hrs can when it is a scheduled job.
If you don't provide timestamp in CSV file then UFL interface will process current timestamp as like below. Hope this helps you.
Are you uploading data manually or do you have any schedule?
Thanks for the help Mallesh.
It all depends on the requirement and till date I haven't seen any recommendation not to keep scan frequency of 24 hrs.
And Input file can be from any other application schedule, or from FTP or a manual file drop.
In this case, since the input file doesn't have the timestamp, and he wants to store date with a midnight time stamp, I feel there is no harm in setting the scan class to 24 hrs.
Thanks Ramesh Reddy ! I think i can do use scan class as 24 hours since it's a schedule job.
Note: I feel like they should provide a function like now() to get timestamp at midnight.
This is definitely a much better approach.
Scan class scheduling cannot guarantee the time of execution, so it would not fully satisfy your end goal. For example, if a scan is missed, it will attempt to scan again.
I never though you can assign a string to Timestamp variable.
Retrieving data ...