Trying to find the best way to create a tag historian query that will calculate weekly waterflow totals. I currently have a historical tag that calculates total daily flows with a 24 hour rest. Would i need to create a script or can it be done via StartDate and EndDate manipulation?
Will it always be 1 weeks worth of flow data or do you want the start and end date to be variable?
It would be current week of flow data. Like Mondays date TO now() and so fourth. I would need it to reset that data and start fresh Monday morning at 12:01am.
You could probably just use a calculation:
and adjust your start and end dates to go back to "last Monday".
(use system.tag.queryTagCalculations - Ignition User Manual 8.1 - Ignition Documentation if doing this in script)
Is it possible to go back to last monday without doing scripting? "Last Monday" would have to be defined right?
I can't think of a simple way to do this without scripting. Don't shy away from it. Ignitions documentation is quite good and you always have the forums here to help. You can set up a scheduled gateway event every monday and use the current date and current date - 7 days (use the system.date functions) as parameters for your query.
Without scripting, I don't know. Maybe expressions can do it.
Scripting it is not too hard though:
now = system.date.now()
now.setHours(0)
now.setMinutes(0)
now.setSeconds(0)
day = now.getDay()
last_monday_midnight = system.date.addDays(now, day-1)
There might be a way to set the time in one line with setTime
but I couldn't make it work for some reason.
There might also be simpler ways, but frankly I wouldn't spend more than 3 minutes on something like this.