Saturday, November 12, 2011

Watts Up? : Working with WattDepot!

In an earlier post, I noted that in order to become an avid programmer practice would surely make perfect. Continuing on with that valuable, but often overlooked piece of information, I have had another chance to practice my skills on a more challenging systems, WattDepot.
For those unfamiliar to WattDepot, simply put, it is a system for acquiring and storing data from electricity meters for smart grid research and experimentation. For the past few days, I have been working with the system by learning the basics. And, I must say working with the system was a unique challenge. Never have I ever spent such a large amount of time coding and testing, coding and testing, and, did I forget to say,testing!? There were so many new things about Java that I had to learn on the fly such as working with XML timestamps and Calendar events(specifically, conversion) that I often ended up confused, but I pushed my way through to a successful completion of all my katas.
By the end of programming my katas (which took hours,as I stated earlier!), I, in addition to feeling stressed out, felt that WattDepot offered a great service especially for Hawai'i. Since Hawai'i has some of the most expensive costs of energy in the nation, the WattDepot can serve as a library of information that can be used to understand what changes need to be made to our current energy habits and how those changes may affect the costs if energy in the years to come. In fact, I was often surprised at about how much energy is consumed at the University (since the data WattDepot collects and maintains is only from the freshman towers at UHM).
For those interested in getting some practice with WattDepot, it is available to download at: http://code.google.com/p/wattdepot/downloads/list and you can take on the same challenge that I had!:
Kata 1: SourceListing

Implement a class called SourceListing, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and their descriptions, sorted in alphabetical order by source name. Use the System.out.format method to provide a nicely formatted list. For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source Description
Bar Represents the energy consumed by the Bar building.
Baz Represents the energy consumed by the Baz floor of the Bar building.
Foo Energy generated by the Foo power plant.
Qux The energy meter associated with the Qux household.


Kata 2: SourceLatency

Implement a class called SourceLatency, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and the number of seconds since data was received for that source, sorted in ascending order by this latency value. If no data has every been received for that source, indicate that. Use the System.out.format method to provide a nicely formatted list. For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source Latency (in seconds, as of 12-Oct-2011 14:32:12)
Baz 9
Bar 10
Foo 14
Qux No data received.

Kata 3: SourceHierarchy

Implement a class called SourceHierarchy, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a hierarchical list of all sources defined on that server. The hierarchy represents the source and subsource relationship between sources. For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source Hierarchy
Baz
Bar
Zob
Zob-A
Zob-B
Foo
Qux

Thus, the source Baz has two subsources, Bar and Zob. The source Zob has two subsources, Zob-A and Zob-B. Foo and Qux have no subsources. The hierarchy is represented by two space indentation.

Kata 4: EnergyYesterday

Implement a class called EnergyYesterday, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and the amount of energy in watt-hours consumed by that source during the previous day, sorted in ascending order by watt-hours of consumption. If no energy has every been consumed by that source, indicate zero. Use the System.out.format method to provide a nicely formatted list. For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source Energy consumed in watt-hours (19-Oct-2011)
Baz 932
Bar 1025
Foo 1436
Qux 2357

Kata 5: HighestRecordedPowerYesterday

Implement a class called HighestRecordedPowerYesterday, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and the highest recorded power associated with that source during the previous day, sorted in ascending order by watts. Also indicate the time when that power value was observed. If no power data is associated with that source, indicate that. Use the System.out.format method to provide a nicely formatted list. For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source Highest recorded power in watts (12-Oct-2011)
Baz 10,034 10:30am
Bar 10,456 2:45pm
Foo 14,876 12:30pm
Qux 23,578 4:15pm

This is a little tricky due to the presence of both virtual and non-virtual sources. For non-virtual sources, you could retrieve all of the sensor data and just iterate through to find the maximum power value. However, virtual sources represent an aggregate of non-virtual sources, so there is no sensor data associated with them directly, and it is unlikely that the sensor data timestamps for its constituent sources will be synchronized exactly.

One reasonable way to deal with this is to request the computed power at (say) 15 minute intervals for the entire day, which provides 96 data points per source whether it is virtual or non-virtual.

Kata 6: MondayAverageEnergy

Implement a class called MondayAverageEnergy, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and the average energy consumed by that source during the previous two Mondays, sorted in ascending order by watt-hours. Use the System.out.format method to provide a nicely formatted list. For example:

Server: http://server.wattdepot.org:8190/wattdepot/

Source Average energy for last two Mondays in watt-hours (24-Oct-2011, 17-Oct-2011)
Baz 10,034
Bar 10,456
Foo 14,876
Qux 23,578

Tuesday, October 25, 2011

Update: The Journey Traveled So Far...

There never seems to be quite enough time in the day anymore to solve all of the problems when faced with the challenge of examining the intrinsic techniques of being a great software engineer. Despite that feeling, I feel that there have been several things that I have learned up to this point that will bring me that much closer to an understanding to what it means to be such from the techniques I have both examined and applied so far. These questions are only a few in number but they are representative of how far I have traveled and also just a hint at the direction that I will be traveling in.

1. What are some of the common types of problems that Configuration Management are good at solving?
If you have problems such as (but not limited to): (a) Not being able to reproduce a bug that was witnessed in your own copy of the system, (b) Unable to determine what happened to your fix of the code, although it was fixed at a time prior to your being unable to determine and (c) If you wonder if a bug you saw is fixed within the copy of the system you have, then configuration management will be useful!

2. How does CVS solve the three classical problems that configuration management faces?
For issues with double maintenance,CVS has a centralized repository with a single master copy of each file.
For issues with shared data, CVS allows multiple developers to create local copies of that master copy to work on.
For issues with simultaneous updates, CVS allows multiple developers the ability to edit files simultaneously and CVS creates a "merged" file with all the changes.

3. What are three scalability issues build systems face?
Modularity, Incrementality, and Coupling

4. What is the responsibility of the *.build.xml file?
The *.build.xml file is responsible for implementing support for single functions such as checkstyle,jar,Javadoc,PMD, and Distribution?

5. In a version control system, what is a "delta" representative of?
"Deltas" are a representation of the difference in the versions of files.

Thursday, October 20, 2011

Sharing Files...It's just THAT simple!

When it comes to collaborating with teammates by sharing software projects, believe me, I would love to say gone are the days where emailing each other is a requirement. Alas, it is not something that is completely true, however, the task has become easier thanks in part to Google Project hosting and configuration management software clients such as Subversion and Git. Subversion, or SVN for short, is a software versioning and a revision control system distributed that developers use in order to provide current and historical versions of files such as source code, web pages, and documentation.
With the combination of Google's project hosting service and Subversion's configuration management capabilities, project developers are able to create a centralized repository where pertinent documentation, for example, the project's user & developers guide, summaries and also the project itself, can be found and downloaded. Moreover, with the subversion capabilities teammates are able(granted, they must have commit privileges) once downloaded to commit any changes they have made to the project. It really makes sharing projects widespread and simple.
Thanks to that, sharing my Robocode project, DaRumble, was as easy as one, two, three. The only difficulty that I encountered was in creating the pages with the specific documentation (the user & developer guides)due in part to the wiki markup syntax (it took me about five minutes to get the page to display an underscore!), but aside from that, giving a partner commit-access to the project and creating a trunk folder where that partner can commit changes did not take much time to do. In fact,when I was setting the trunk folder up for access, I cleared up the misconception that I had earlier when I thought that any user must download the project first and then re-upload any changes made. I learned,however, that if the user has any configuration management system client, they are able to visit the repository of the project and commit any changes even without downloading the project.
All in all, I think from working with this configuration system, I have gained another useful tool in working with software systems and, to a larger extent another perspective that will being me closer to understanding to what being a great software engineer is.

If at all curious, please feel free to visit my project's page at:
http://code.google.com/p/robocode-wch-darumble/

Tuesday, October 11, 2011

The End All Be All : Top Robot!

Have you ever wondered what it must be like for those contestants that compete on shows like Top Chef or Iron Chef America. The competition is completely maddening and with the added pressure of making top gorumet meals in sometimes less than an hour surely makes it worse, I would think.

Thursday, September 29, 2011

Oh nooo! We're going to have Ants!

Without a doubt, ants are some of the world's most determined creatures. Despite their sometimes small sizes, they are some of the most hardworking insects in the sense that they work together to build massive systems, or colonies, that are deeply layered in order to survive. In fact, as a result of their work, ants have colonized almost every landmass on Earth. They have come thrive in nearly all ecosystems,representing almost 15-25% of all land animals. I guess this is one good reason why Apache decided to rely on an ant symbol for their own Ant build system tool.
Apache Ant, or Ant("another neat tool") is a tool for automating software build process. It does draw parallels to the way ants build their so called "system", relying on scripting that is compilable,creates documentation, package, test and deploy code (thought, not necessarily in that order). Each piece plays a role in helping to neatly manage and export Java programs for both aspiring and long-time software developers.
Often one of the most noticeable differences between Ant and other build system tools (and yes, there are many others! Take Maven, for example) is that Ant relies on XML (frankly, a language that I lack the necessary experience in). Despite my unpreparedness, I dove right into the deep, practicing with Ant-Katas (you saw this coming, didn't you?). I managed to complete each kata, however not unscathed, having to go review my code on multiple occasions for forgetting symbols like "/" or ">" and even for getting to declare variables like "system.name" with a value (all of which almost drove me to the brink of insanity!). But thanks to these katas, I have learned some of the most important ANT basics like the immutabilities of properties, how dependencies work (in that, avoiding the dreaded circular dependency!) and how to interact with the console. With the help of some of my fellow classmates, the Ant API, and a nights supply of red bull (since it really does give you wings!), I was able to create some simple programs that were complete time savers.

Tuesday, September 20, 2011

r..r..r...Robocode!

Ever wonder what it takes to become an avid programmer? If you have just started programming or have even been doing it for some amount of time, this is one question that will often appear from time to time in the depths of your subconscious (or in my case, usually while I'm programming!). There is no doubt that a study of the formal techniques of programming (which you can find in any book) will have an important role to play in any programming career. However, the most vital task in becoming an avid programmer, I believe, is practice (a task,sadly, we often don't have much time to do with our busy schedules).Practice, indeed, does makes perfect. In fact, it is often the detail that distinguishes great programmers from the not so great, since programmers who practice understand the need to challenge themselves by taking on tasks that take them beyond their usual comfort level.

And to both my surprise and satisfaction, I was able to get a good amount of practice in using Robocode. Robocode is an open source programming game that was originally developed by IBM, which was later picked up by Flemming N. Larsen and Parvel Savara. The goal of Robocode is two folded; Sticking to their motto, the first, "build the best to destroy the rest", alludes to the ability to create, manipulate, and destroy Robots in a no holds bard, fight to the death, battlefield. The second, which is my favorite, is to enhance the users knowledge of Java since the game involves writing code in Java and having the created robot(s) battle one other by moving around, shooting at enemies, or just following enemies around on the battlefield. Specifically, I worked with implementing 13 katas, or simply, 13 robots that that helped me to see where I am as a Java programmer. At first I thought with my previous experience in Java ( and Java robots) this project would be very easy, but as I soon found out, it was not as simple as I thought. Take a gander at the 13 katas:

Position01: The minimal robot. Does absolutely nothing at all.
Position02: Move forward a total of 100 pixels per turn. When you hit a wall, reverse direction.
Position03: Each turn, move forward a total of N pixels per turn, then turn right. N is initialized to 15, and increases by 15 per turn.
Position04: Move to the center of the playing field, spin around in a circle, and stop.
Position05: Move to the upper right corner. Then move to the lower left corner. Then move to the upper left corner. Then move to the lower right corner.
Position06: Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
Follow01: Pick one enemy and follow them.
Follow02: Pick one enemy and follow them, but stop if your robot gets within 50 pixels of them.
Follow03: Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
Boom01: Sit still. Rotate gun. When it is pointing at an enemy, fire.
Boom02: Sit still. Pick one enemy. Only fire your gun when it is pointing at the chosen enemy.
Boom03: Sit still. Rotate gun. When it is pointing at an enemy, use bullet power proportional to the distance of the enemy from you. The farther away the enemy, the less power your bullet should use (since far targets increase the odds that the bullet will miss).
Boom04: Sit still. Pick one enemy and attempt to track it with your gun. In other words, try to have your gun always pointing at that enemy. Don't fire (you don't want to kill it).

While I was able to successfully implement all 13, by no means was it an easy feat. In fact, I had the help of two of my fellow classmates, Marifel Barbasa and Hansen Cheng. In the implementations, the most difficult portions (and I mean mind-numbingly difficult!) were the Positions 04,05, and 06. I was completely taken off by the amount of trigonometry needed (or the amount of trigonometry that I had forgotten) in these implementations in order for the robots to function as intended. I must say, if it wasn't for the help of my classmates, Java's helpful (and sometimes helpless) Math class, and the, what I thought were endless, hours of drawing out angles and directions on paper, then I probably would have not have finished these particular katas.

After having finished them however, I still feel that there is so much more for me to learn (and yes, trig is on the list!). The katas were great insightful tools that let me know where some of my comfort levels are and what I need to do in order to push past them. While I do have an idea about how to build a "good" competitive robot, in respect to positioning in a way to make escape easy and constant targeting a must, it is far from "great". I will still have to iron out some of the kinks.

Wednesday, August 31, 2011

Back to the Basics: Eclipse & Java

After a lengthy hiatus from programming in Java, I was given the task of implementing the Fizz Buzz program in Java (using Eclipse as my IDE) as a refresher to get me back into the swing of programming in the language. For those whom the Fizz Buzz program eludes, it is a program that should print out all of the numbers from 1 to 100, one per line, except that when the number is a multiple of 3, it prints "Fizz", when a multiple of 5, it prints "Buzz", and when a multiple of both 3 and 5, it prints "FizzBuzz". No doubt an easy program for a refresher, no?


I'll admit while it was easy to implement, it took me quite some time to do it, 14 minutes to be exact! Here are some screenshots of my code, the first being from within my workbench in Eclipse:
Despite both the ease of the program and the time it took for me to implement it, most of the time I spent was using the JUnit tool to verify my program's correctness. Of course I could have written another class, perhaps naming it something intuitive like FizzBuzzTest, that would ensure the behavior of my program to be correct under the set conditions, but I wanted to be adventurous and try to use JUnit to create a JUnit testcase to check my program's correctness. After never having the experience of using it and seeing a demonstration of it and how it can be used in a class of mine, I was determined to use it, even for such a small task as this one. I convinced myself this would be just a sample, an experience I could look back on and say, "Oh, that where I got my feet wet." Here is another screenshot of my code, this time of the test the I created using JUnit to check if my getResult() method of my FizzBuzz class worked correctly:




I was glad to see that my code worked as intended and that my JUnit test case verified this. In spite of that, the most difficult experience I had was following the model of using JUnit from the demonstration I mentioned earlier since what I could recall of the model was hazy on the details. Specifically, I was having difficulty remembering things like what return type I should make my getResult() method so that it would be easier to test using the assertEquals() method in my FizzBuzzTester class and also the parameter types of the assertEquals() method. But after some note taking, I was able to fill in the missing gaps from my recollection of the model and successfully implemented my FizzBuzzTest program with desired results. All in all, I had a fun time playing around in Java again and learning a few new tricks while doing so. I wonder what is next for Java and me in the future?