Tuesday, November 8, 2011

WattDepot

Continuing on with the electricity and energy rant from the previous blog post, I started doing some katas on something called WattDepot.  It's a program that centralizes a lot of different monitors and sources to easily look at data and keep track of things.  Because the main program doesn't really care about what the actual monitors use, someone like me is able to connect to the servers and start working with data even though I don't even know how they're getting the information, which makes it really convenient for a lot of reasons.  Not being stuck to one standard that a company decides on is good and lets developers focus on other aspects. Like katas :P

They actually took longer than I thought they would.  There were about five and it took me at least five hours.  But the time spent on each one wasn't equal, and I took breaks. 

The first kata asked to merely print a list of sources that the server is getting information and give a description of them, which is also conveniently provided.  Not only that, there was a sample program with the distribution of WattDepot which showed the basics, basically, I didn't have to do anything for the first one. 

The next one asked for some data manipulation to determine latency based on the given timestamp which was a little more complicated but not too much.  I tried to make a helper class implementing comparable, which seemed to work ok but i'm not sure if there's a better way to do it easily. One thing interesting here though, is that this is basically my first time working with a server that doesn't always transfer in the blink of an eye.  So the way I had it set up first, with a bunch of nested loops, took forever to do and really made me think about how to structure my code to get things working as smoothly as possible, I'm sure i didn't do as well as i could have, but my end results were certainly better than what i started with.  You don't really notice these things when it's the difference between a fourth of a second and a fifth, but because the server was bottle necking things, it helped me out.

The third and fourth were just more complicated forms of the second problem, involving using time and averaging or looking at a bunch of data points.  Again, they took a long time to finish, so instead of just leaving things blank until the output spewed out, I put little messages telling you where the program was, which is something I haven't really had to do before.

The fifth gave me some problems because it involved knowing when the last monday was, given only the current date! Turns out it's a pretty simple problem of using java's implementation of a calendar.  The only tricky thing is that the months seem to go from 0 to 11, so for the longest time, the calendar was giving me the wrong day and i didn't know why.  The day of the month (8th) and the month itself (11th) looked ok, but only when i made it print the actual name did i see that 11 was equivalent to December.  After I figured that part out, the rest was pretty simple, though I saw some areas where i could make my code more efficient.

Overall, these katas were a good learning experience for more real world tasks where things don't just finish super fast.  I haven't really had much practice with optimization and structure so it was especially helpful.  Also, being able to so easily pull up data on the energy and power usage of an actual set of buildings was pretty cool, and probably also helped keep me more interested in katas.  They're pretty fun, and if you want to look at the program, here it is.

Of course, looking at the API for the thing, I see that there are a lot more of advanced features that I didn't even touch, but from a beginner's point of view, even just this is pretty good. That's all for today.

No comments:

Post a Comment