Hi all,
I have a task that I am struggling to come up with the best solution.
Basically I capture a machine start time each day. I then need to display the information as days of the week. Then average for current week, avg for previous week....to the last 4 weeks. I currently store the tag value historically but can use transaction groups.
stopCode (what was the first-out alarm that caused the machine to stop)
countGood
countTotal
productCode
That gives a pile of useful information for OEE, etc. with fairly simple queries and scripting.
Finding the machine start time would be something like a scalor query,
SELECT timestamp
FROM ProductionLog
WHERE runStatus = 1
AND timestamp >= :dayStartTime
AND timestamp < :dayEndTime
ORDER BY timestamp DESC
LIMIT 1
(Assuming MySQL / MariaDB)
If your day runs from 06:00 to 06:00 then you would feed in the relevant datetime values to the named query parameters.
I highly recommend making your countGood and countTotal as never-resetting counters rather than batch counters. This makes it very easy to calculate production numbers over any period of minutes to months.
Thank you for your reply.
I already have the time of day the machine starts. What I need to achieve is to display the start time for the days. eg displayed with a header for Monday Tuesday ...Sunday.
If is is Monday then the start time would show, and Tuesday would have N/A or similar.
Then when is it Tuesday both Monday and Tuesday will be filled.
I think I will need to do a day of the week script on the page. Then have a date for Monday, a date arithmetic plus a day for Tuesday etc.
Then I will average the data for each week.
I imagine another method would be to use a transaction group and load the Day of the week into the table and then query based on the stored data.
I can't follow the description of your desired view and that makes me think it's overly complicated and there might be a better, clearer way to display the information.
For example, why are you showing a week as seven columns with one header and one data row? It would be much simpler to show two columns, day and start time with a row for each day. Vertical rows of numbers or times are easier to compare. (They're usually closer and most significant digits can be scanned quickly.)
Day
Start time
Monday
06:25
Tuesday
06:43
Wednesday
07:18
Thursday
08:23
Friday
-
Saturday
09:14
Sunday
-
If your database is structured correctly it may be possible to generate this in SQL directly with no script manipulation.
If you want further assistance then please provide details of the data table structure and a mockup of the report layout.
Sorry I didn't explain.
The reason I showed it that way is there are actually many lines in different locations.
The header of the day works better visually. Down the Left side would be the location and line number.
The Start time is current captured with tag historian on change and stored in MySql.
I can export a couple of lines if you think it will help.
Thanks