A friend told me about a new program that can monitor energy and power usage for a user and the energy readings from the sensors are updated real-time in about 10 minute intervals. The program did not peak very much interest in me, but when my friend also mentioned that he could show me the source for the program, I started to sound more interested. New programs are interesting and when I'm able to get some source code of the program, I get even more interested. With the source code, I can feel out what the program is trying to do, rather than blindly testing out what certain things the program can do.
The program is called WattDepot and the program sounds interesting in several ways. The program was developed in order to monitor energy usage and to see where energy and power usage can be controlled in order to conserve and reduce waste. It is also being used to offer lessons in energy and power conservation to students by using it to monitor dorms. It is also teaching the students living in those dorms by having them participate in a energy conservation contest. By logging in to a website to access modules on energy conservation and learning about alternative energies, the students can earn tickets that they can use to enter weekly raffles of certain prizes. Although the student might not be guaranteed a prize after entering in the raffles, they are hopefully learning about trying to reduce energy waste and ways to reduce their carbon footprint.
With this new program and source code, there was one thing that I could think of. How could I use this to make robots? Well, maybe two things; that and what could I do to participate in developing this program further? At least for the second answer, I could start another round of programming katas based on some simple functions of servers. For the first question, I'm stumped; so I'll just work on the katas for now.
With this new WattDepot program, there were several interesting thins that I saw while reading through the included JavaDocs. Not only the WattDepot Client can read power and energy ratings at one time, it also stores that data and it ca be access over several days. With this, a general average energy usage over several days can be achieved as well as seeing if that weekly Friday night party busts more than some lamps. With that in mind, I had seen some other things I wanted to try out, so these katas eventually formed out:
1. List all sources that the client monitors.
2. Check out how long since the last server reading has taken place.
3. Find out the source hierarchy.
4. Energy used yesterday.
5. Highest power recorded yesterday.
6. Monday's average energy.
Seems like a breeze through the park and I thought so too as I got started on a new adventure. The first one was quite simple and I breezed through in about 10 or so minutes. The second one was just as easy, although I did have some trouble with formatting the date to display just right, taking be about 30 or so minutes. I looked at the online Java 6 documentation to get a better understanding about formatting the date.
With those two out of the way, glancing over the third seemed like a breeze to finish. Boy, was I wrong! After creating a simple method to look at the sub sources, I thought that the next step was going to be easy. When the sub sources only returned URI addresses, I was starting to think of blanks. I went back over the JavaDocs to find anything that could help me to turn the URI's into source names.
Since the sub sources were returning some sort of list, I could at least separate them into several entries. After looking through the WattDepot API's, I only could find some method that could turn a source into a URI, given the source URL location. It took me a day to finally figure out that using the list I separated and using the method to turn a source into a URI, I had a searchable list. After hitting that brainstorm, it took me about three hours to finally finish debugging all the code so it could produce an easily read listing of sources with their sub sources. All in all, it took me about 8 hours to finish this over two days. (Hey, I do have a life outside of only programming. My friends sometimes wonder where I go when I get into a programming quirk as I'm often gone for several days on end.)
Back to the katas and after my rest, I feel better than ever to tackle the remaining three. With the yesterday energy usage one, I started by figuring out how to get a whole day's energy. It seemed simple to just plug in the starting date and time, ending date and time and the interval over how long the energy usage should be sampled. The only thing I had to figure out was how to insert the dates and times that I wanted, making sure that the date was yesterday no matter what the day was today. Looking at the JavaDocs again, I could see that there was some funny things going on with the calendar. I had to make a new calendar and fool the calendar in thinking that today was yesterday by turning the page back one day. After I figured that out, I could easily proceed with providing yesterday's starting and end times. Before I knew it, I was done in about 2 hours.
As I started on figuring out the highest point of power was used yesterday, I had a problem. The WattDepot client provides a method to get the power used at a specific time, but to identify the time where the most power was in use was starting to get complicated. Java does not like to run when a lengthy process needs to be executed. Running a derivative over an equation that has multiple sampling points reaching infinity is not my idea of Java fun. In order to reduce the number of calculations that Java has to take, I tried to sample over a 15 minute period. I thought that having a sample of 15 minutes should be far enough so that Java won't lag badly but it should still give a good reading. I was wrong, having to wait almost 15 minutes myself for the program to run, just so that I could see an error! I fixed the problem and the program ran fine, but I waited almost 30 minutes for the completed program to run. With the time needed to run the program, this one took me a good 2 hours, with almost one hour devoted to just waiting for the output.
With that turtle out of the way, I was on the home stretch with the last problem. This looked much easier, by just monitoring the energy usage over the two days and getting the average usage of the past few Mondays. With the framework of the fourth kata, I searched to find how the Java calendar reads Mondays. After figuring out how to check the days until Monday, I turned the calendar back twice; once for the past Monday and another for the week before that Monday. I recorded the two Monday's energy usage and found the average of the two Mondays over all the sources. I was quite happy, taking less than 45 minutes to finish and diagnose any problems.
I still was bummed about taking a long time with the third kata. Looking back at it from hindsight, I felt foolish that I did not see what was staring right at me. Oh well, that's what these katas are for, training your mind and critical thinking. Make sure that you know what you are looking for exactly and try not to fit everything to the same mold that you are familiar with. It's like learning a foreign language; don't try to use complicated words and grammar that says what you mean, look for what you can say with what you already know how to use which still mean what you want to say.
WattDepot is an API. You must be referring to the Kukui Cup.
ReplyDelete