Tuesday, November 29, 2011

Issue Driven Management, Cooperation and the WattDepot CLI

There's little use to a good API if there isn't an easy way to interact with it. Enter the most l33t way of interacting with computers, the command-line interface. Having stood the test of time (I still find SVN management via the command-line to be the best way to do so) we were tasked to implement a CLI for the WattDepot server. And by "we", I mean the newly formed team of David Wilkie, Yong Hong Hsu and myself, or Team Cybernetic Cucumber (cycuc, for short.) To try to streamline development and ensure that not just one person is tasked with doing everything, we were encouraged (with our grades no less) to incorporate Issue-driven Development, Continuous Integration and Google Project Hosting into our development process. The product of which can be found at http://code.google.com/p/hale-aloha-cli-cycuc/.

Issue Driven Management

The most important new aspect of this development was the concept of Issue-driven Development. Instead of verbal planning, the team outlines Issues for tasks to be done, whether it be debugging, extending/enhancing the system, or just plain doing the documentation. In this digital age, to have anything less descriptive and concrete is a detriment to efficiency. Google Project Hosting incorporates Issues right into their client, making it easy for any person to file an Issue with the system and for the owners to comment and coordinate easily to make sure of its resolution. In terms of the project, we split up tasks with Issues, each of which corresponded to a task for the system. The way we split up the work was for me to focus on the Processor and DailyEnergy command, David to focus on the main CLI, documentation and the CurrentPower command, and for Yong Hong to focus on the RankTowers and EnergySince command. This is easily reflected in the Issues page, (with added Issues corresponding to defects throughout the development process.) All in all, I definitely would recommend Issue-Driven Management to any project with any amount of coordination; text is a great medium especially for coordination (even though the Internet is distracting and impersonal.)

The WattDepot CLI

Our command-line was a simple one implemented in Java. Consisting of a tiered hierarchy, it incorporates a User Interface, several classes that corresponds to queries to the WattDepot server, and a helper class to parse arguments. The hierarchy is listed as such:


| edu.hawaii.halealohacli.Client
|-> edu.hawaii.halealoha.Processor
|-> edu.hawaii.halealoha.Command


The Client was the main loop that interacts with the user. As such, it prompts the user to input a command and passes it to the subclasses depending on the command given. David was genius to implement an Enum to handle both the Operations as we well as the arguments, which made passing data to both of the subclasses extremely easy.

Once done with determining the client, the rest of the string passed to the Processor class to determine if the sources and timestamps are valid. Source validation was implemented by using the getSource(String string) method from the WattDepot API and timestamps were validated simply by checking if the string given was in the form of YYYY-MM-DD and that all values were valid to get information from the WattDepot Server. The Source and XMLGregorianCalendars required by the queries to the WattDepot server were then stored locally and passed to the main Client based on what was needed.

The Command class contains an interface with one method that contains one method, printResults, that all Commands are to implement. The interface ensured a common method that one could use to extend the system.  Each class queries the client and prints out the results of that query.  The following Commands were implemented:


current-energy [source]: The current energy usage of the given source.
energy-since [source] [date]: The energy usage of the source from the date provided to now.
daily-energy [source] [date]: The total amount of energy used by the source on that day.
rank-towers [date] [date]: List out the energy sources in ascending order by the amount of energy used between the two dates.


Each Command comes with a JUnit test that provides 94% coverage, meaning that most of the instructions are tested.

There are several flaws with the implementation as it stands now. Reporting errors to the user is hit and miss since we use ordinary Exception classes to throw with custom messages, which may or may not be descriptive. A more thorough implementation would incorporate custom Exceptions that would be thrown for a respective error (Invalid source, timestamp, timed out, etc). Another bug (though it could be seen as a feature) is that the sources aren't cleared when an error occurs, so if one were to input, say, "current-power Lehua", the Lehua source will stay in the processor until it's changed. This makes it easier for the user to make multiple queries to the same source without specifying it all the time, but also means for weird actions if a source is wrong (if one were to input "current-power foo" after the last command, it would throw an error and print out the energy usage for Lehua again, for instance.) More rigorous testing and reviews would certainly be beneficial for the system.

In all, it was a good challenge to work with a group for project development. Throughout our scholastic career, we were expected to churn out code on our own and by doing so we never really learn how to write for anyone but ourselves. With some help with Automatic Quality Assurance and Issue Driven Development, I've learned a few ways that I could use in the future when I'm not just developing for myself and a grade, but for a system that will be seen and modified by others both in this current development cycle as well as future ones.

Tuesday, November 8, 2011

Energy, APIs and the Internet.

As mentioned in my last post, we can only go so far in regards to producing enough energy from alternative resources. In this power-hungry world, it's an unfortunate truth. The fortunate truth is that the state of technology has grown exponentially in the past century and we now have the power to look at our energy consumption in ways like never before. Simple meters can be installed and maintained to keep track of how much energy we use, meaning that we can know what we need to change in order to use less energy.


The WattDepot Client is one such technology. Produced by Professor Philip Johnson of University of Hawaii at Manoa, WattDepot is easily configurable to accept input from a variety of energy meters and relay it to those who need to analyze them. As a proof, the current implementation keeps track of energy in one of the most chaotic environments known to man: the college dorm. All kidding aside, the result of such a system is an system that can easily be queried, returning up-to-the-minute information about the energy consumption and production of a particular area.

Energy data manipulation made easy


Using the WattDepot Client API is made incredibly easy. Since it uses the xml-based REST protocol, one can easily use any xml-parsing language to read and generate data. An already-working implementation (in Java) could be found at the wattdepot-simpleapp Google Code page. The included file is a shell app that simply gets the first source returned by the client and calculates its latency. One can easily consult the WattDepot API to find out how to request data from the sources. The basics of it is in the Source and SensorData classes. Each source holds data about its Energy (mW produced/consumed) and Power (energy / time).


One can attain the data of a particular source by passing in the source name and a timestamp (the manipulation of which the included Tstamp class under utils is incredibly helpful with) getting a precise measurement from the source. The result is a huge resource of data that can be queried and sorted according to its energy use, which is used by the Kukui Cup to keep track of which dorm area is most eco-friendly. This technology can be easily applicable to any area be it residential, collegiate or business, meaning that we as a human race can effectively know what and where our energy consumption is going to and how we can change for the better.

Tuesday, November 1, 2011

Hawaii's Unique Energy Situation

Hawai'i is the most isolated piece of land in the world. You can go to outer space 8 times and back in the same distance that it takes for you to go from here to the nearest major land-mass. It would come to no surprise that it takes a considerable amount of effort to get things here. Whether by plane or by ship, the cost it takes is reflected in our cost of living. Since we as an island have a limited amount of resources in coal and oil, we have to import the majority of our energy from elsewhere, resulting in energy costs double or triple the cost of the Mainland. As such, we have a growing incentive to partake in converting our lifestyle to that of which is a more energy-efficient one.

As oil prices rise, this initiative is starting to become a more and more feasible one. So much so that ex-Governor of Hawaii, Linda Lingle, signed a bill to make 70% of our current energy needs renewable by 2030. This entails becoming 30% more energy-efficient while converting 40% of our current energy needs to that of renewable energy. While this may seem like a lofty goal, our unique location and resources, as well as the ever-increasing state of technology, make it seem like a realistic one.

Being in the middle of the ocean, we don't have much in the way of traditional carbon-based fuel. We do, however, have a majority of renewable energy that has been popularized the past decade. Solar, wind, wave, geothermal, you name it, we have it. As the price in investment in these technologies goes down, along with the rise of oil prices, we have a noticeable and realistic incentive to convert our energy into renewable energy. As a state, we have a already started to invest in wind farms, solar energy as well as research into alternative energy like Kukui Nut Oil, that makes us well on the way to renewable energy.

Being a new investment, our renewable energy would only amount to so much of our current energy needs. Our power plants generate far more electricity than the current efficiency of our renewable energy can cover. We, therefore, have to learn how to cut our energy needs to better make use of our renewable energy. This would come in the form of energy auditing and regulations. The majority of energy use in Hawai'i comes from the business and industrial sector. With current technology, a business can easily tell just how much energy electricity is being used and from where. A feasible plan for cutting our energy consumption would be to offer incentives, be it fines for excessive energy use or tax-cuts for sufficient reduction, to businesses to spur them to undergo energy audits and reconstruction. Whether by installing new technology or altering their energy policies, a business would stand to reason to use less energy under this plan.

These strategies would almost definitely cut our dependence on foreign oil and act as a blueprint for the rest of the world in transitioning to alternative energy.