Ignition Reporting Dynamic Start and Stop

INTRO: I do apologize if my wording is going to be slightly off due to me still learning the lingo. I am trying to create a report that based on a tag that becomes (PROD START) and for it to be finalized when a different tag becomes true (PROD COMPLETE).

GOAL: I need each of these tags to also be represented as a time stamp for when they were last made true. along with a duration timer. to execute as a .pdf file in the C drive with the proper time for my time charts.

WHAT WAS DONE: I have created two memory tags with a date/time, but I do not know if I am missing something or just straight up doing it wrong. I have them both set up as historian and included on my data source, but I have not had any luck when it comes to the execution of said report. It is still a time-based schedule, running once at midnight. I have tried a few videos that mentions gateway event tags but to no avail… now if i can get the start and end time to work properly and execute as a .pdf file to my folder on the C drive…. will the graphs show the duration of that snippet or does that involve other shenanigans….

CONCLUSION: Please be patient with me and thank you for your support.

Welcome to the forums.

I highly recommend going through all of inductive university.

If you want help - it’s good to show what you tried, not just describe it. Show your scripts, tag setups, your gateway event change scripts etc. Otherwise we are just guessing on what you did and how to help you.

From what I can decipher, you are attempting to limit the span of a report to the start and end times of some production process.

My approach (knowing nothing else about your system) would be to use a database table, write the production start and end times in separate columns, along with possibly some other related/important information.

What is driving when the production 'starts' or 'stops'? I would use that to write the timestamp to either the start or stop column in the db table. Along with the start time, I would include some other identifying data (batch/serial number maybe). This would allow you to execute on demand reports for older runs.

If you are absolutely stuck on using those two tags, a gateway tag change event monitoring when the tags change to true and writing the timestamp to the appropriate db table column when it happens would be sufficient. It's also simple enough that you could make do with transaction groups, if you have the module on your gateway.

From there, when executing the report, pull the most recent row from the db table that has non-null start and end times. Use the start and end times to drive the span of the data fetched for the graphs in the report.

I certainly appreciate it and I have been going through the university and watched a few of the videos going over the reporting. But the videos I had found on the University wasn’t specific enough for me, thank you

Thank you, Ryan. I haven’t tried an event monitoring so I will try that. But yeah, there are other bits of information as well that i was pulling to the report like statuses and graphs for temp and pressure. But I’ll let you all know if I am able to do it successfully or not with the dynamic action of the report

If you need to comb through the historian to obtain what you're looking for, this is the pattern I use to iterate the history data and record when cycles start and end. The final result is a list of dictionaries, each of which has the relevent details of a single cycle.

It is important to note that you will first need to clean your data to get the best results. That means ensuring no NULL results, among other things. Often, the first one or more records are NULL becuause there was no change in value until the first non-NULL point.

I have other code that uses QueryCalculations or queryAggregatedPoints to get the LAST value of each tag BEFORE the time window I'm looking at, then applies that value to the initial NULL values.

It should also be noted that this is generally not a "fast" process and should not be done on a Vision GUI thread.

# pds = piDataSet from queryTagHistory or queryRawPoints
# Preumption: t_stamp = col 0, PROD START = col 1, PROD COMPLETE = col 2
events = []
event = None
for i,row in enumerate(pds):
    if event is None:
        if row[1] == 1 and row[2] == 0:
            event = {"tstart":row[0],"start_index":i}
        continue
    else:
        if row[2] == 1:
            event["tend"] = row[0]
            event["end_index"] = i
            event["duration"] = round(system.date.millisBetween(event["tstart"],event["tend"])*0.001,3)
            events.append(event)
            event = None
else:
   if event is not None:
       event["tend"] = pds[-1][0]
       event["end_index"] = pds.rowCount-1
       event["duration"] = round(system.date.millisBetween(event["tstart"],event["tend"])*0.001,3)
       events.append(event)

Hope this helps.