- Posted on
Mon Mar 22, 2010 4:16 pm
- Posts: 2627
- Joined: Nov 18, 2008
- Location: Berkeley, CA, USA & Mougins, France
The problem with on/off state assumption is that unless you go back in history to find the last change for a device, (as Jay noted) you just have to guess. This report is pretty simple, it just issues a SQL query for every record for every device that had usage during a period of 00:00-23:59 for a given date. So, repeating what Jay said, you must start with an assumption that every device is ON or every device is OFF at the start of the data period. I felt that at mid-night it is more likely, on average, that most devices will be OFF, so that was the state I assumed.
However, if you run the AppleScript I submitted to this topic, you can avoid the state assumption issue by recording the actual state of each device just after mid-night. I knocked the script out pretty quickly, so there might be some bugs in the logic, but the concept seems sound. If anyone has some improvements to offer in the script, please post them here.
As to the saved data. I do not have a copy of the code available at the moment. But, all I did was to loop through the array (Ok, dictionary, for you Python lovers) and write out every entry. I seem to recall that for the HTML report the same raw data is sent to the web display script, but it contains logic to trim small amounts. I'll check next time I get a chance, or maybe Jay can confirm. In any case, since the file data will likely be used as input to other processes, I would imagine those processes, just as the web display process, can make their own assumption about what to keep or toss. Also, is someone wants to track usage over a longer period, small amounts of time may become significant, especially for high-wattage devices.