Well, I was just thinking about a few possibilities. For instance, I have a machine. It calculates the amount of time (in minutes) the machine runs per shift, the total production during that shift, and the average production (total production/minutes ran). I was going to make the log write those values to a file. So, if I'm writing those logs to a file anyway, I figured I could use the last 5/10 values or so to produce weekly averages, without having to write the daily values to memory locations and then calculate it.
It would be far more work to access and parse from the file, than to track it in memory. I would do something similar to the attached image. Small code...but packed...so I'll describe it:
1. The DT2EPOCH converts the current time stamp to seconds since 1970 and stores in D0.
2. The first MATH box converts seconds in D0 to a daily index of 0 to 15 (16 days, including weekends) and stores in V0.
3. The second MATH box would be run every day at the same time to store today's run time (D1) into CachedData[0 to 15]. This is a ring buffer, that just goes CachedData0 to CachedData15, and then wraps. But sure to do this every day, writing 0 on days the machine doesn't run.
4. The third MATH box calculates the average time of all non-zero CachedData values using CountIfNE and SumIfNE. CountIfNE determines the number of elements in CachedData that aren't zero. SumIfNE calcs the sum of those non-zero elements.
In the data view, V0 contains the day index, R0 contains the current average, and CachedData0-15 shows the data.
Pretty easy really and far less code than reading and parsing a log file.