Wednesday, November 30, 2011

Technical Review and Evaluation of the Hale-aloha-cli-grads Open-Source Software Project


In this blog entry I post about my experience reviewing and evaluating the open-source software system named Hale-aloha-cli-grads

Introduction and Background

To understand the system as well as and the evaluation criteria, I will first provide summary data of some background information necessary to understand the issues examined in the review.

Hale-aloha-cli-grads



The Hale-aloha-cli-grads system under review is an open-source project that implements a 
command line interface (CLI) for WattDepot, created by Andrea Connell, Leo DeCandia, and Sergey Negrashov. It retrieves and displays energy and power data for the four Hale Aloha residential towers at the University of Hawaii Manoa campus.

WattDepot

The wattdepot open-source project developed at the University of Hawaii is a collection of technologies and tools for collecting and storing data from electricity meters for smart grid research and experimentation. From the wattdepot Google hosting site: “WattDepot is an open source, RESTful web service that collects electricity data (such as current power utilization or cumulative power utilization) from meters and stores it in a database. The data can then be retrieved by other tools for visualization and analysis. It is designed to provide infrastructure for experimentation and development of "Smart Grid" applications.”




The 3 Prime Directives of open-source Software Development


For the purposes of this evaluation, the three prime directive of open-source software development are summarized as follows:

  1. Does the system accomplish a useful task? 
  2. Can an external user can successfully install and use the system?
  3. Can an external developer successfully understand and enhance the system? 

Issue-Driven Project Management


The basics of Issue Driven Project Management are summarized as follows:
  • Divides work into tasks
  • Tasks take no longer than 2 days
  • Tasks are specified by issues
  • Every person always has an open task
  • Every commit specifies an issue in its log comment 
  • Each person has a task
  • Each person knows what it is
  • Each person knows what the next task is
  • Each person is rarely blocked
  • Completing a task brings the project closer to completion
  • Project state is visible at all times to all team members
  • Breakdowns in PM are recognized by everyone, quickly

Continuous Integration



The basic concepts of Continuous Integration are:
  • The System must be able to be built and tested automatically
  • The System must be under CM
  • Everyone commits every day or two
  • Upon commit, The System is immediately and automatically compiled, tested, and developers notified
Review and Evaluation



My review and evaluation will cover important aspects of open-source software development, as well as answer detailed questions about the system including: build process, developer contribution, documentation, testing, QA, process, software quality, extensiblity, and integration. These elements will be grouped into three main sections that correspond to the three prime directives of open-source software development.


Prime Directive 1: Does the system accomplish a useful task? 

Following the directions which were 'spread out'  among the home page, installation guide, and user guide, I downloaded, installed, and ran the system under Windows 7. 
I exercised the system using various commands and command line arguments.

The functionality that is present in the system corresponds to what is documented on the project home page, and the messages displayed for bad commands and command arguments are informative.

I was surprised to see the entire help menu printed after every command, and the help menu does not specify the valid tower and lounge names. 
The help command does not show that 'help' and 'quit' are available commands. 
Also, there is no command line prompt, just a blinking cursor, and as mentioned above, I don't think 3 pages are necessary to get the information required to download, install and run the system.


However, I conclude that prime directive #1 is satisfied because a useful task is performed and the system basically behaved as outlined in the documentation. There were no difficulties in downloading, installing, and running the system, and it displayed expected output based on input parameters.


Prime Directive 2: Can an external user successfully install and use the system?

I carefully reviewed the project site,  Including the home page, user guide wiki, and downloads page.

The home page provides a clear understanding of what the system is supposed to accomplish, and is accompanied by a list of user commands recognized by the system. The user guide has a screen snap of the program in action, showing both sample input and output. The user guide also explains that both physical and virtual ‘sources’ are supported. However it does not indicate what version of the Java JRE is required to run the system.

The user guide links to an installation page that provides clear details on how to download, install, and execute the system from the perspective of a user, but does not include a link to the downloadable zip file. The downloadable zip file is stamped with a version number, and the zip contains an executable jar file. I did not have to compile and build the system in order to use it. I exercised the system under both valid and invalid inputs as documented below.

Valid commands and command line arguments:

energy-since Ilima 2011-11-28
Total energy consumption by Ilima from 2011-11-28 00:00:00 to 2011-11-30 14:42:26 is: 1616.9 kWh

energy-since Mokihana 2011-11-28
Total energy consumption by Mokihana from 2011-11-28 00:00:00 to 2011-11-30 14:43:01 is: 1616.7 kWh

current-power Ilima
Ilima's power as of 2011-11-30 14:45:12 was 26.0kW

daily-energy Ilima 2011-11-28
Ilima's energy consumption for 2011-11-28 was: 611.7 kWh

daily-energy Ilima-A 2011-11-28
Ilima-A's energy consumption for 2011-11-28 was: 104.7 kWh

rank-towers  2011-11-28 2011-11-30
For the interval 2011-11-28 to 2011-11-30, energy consumption by tower was:
Ilima                            1255 kWh
Mokihana                         1261 kWh
Lehua                            1268 kWh
Lokelani                         1468 kWh

rank-towers  2011-11-24 2011-11-30
For the interval 2011-11-24 to 2011-11-30, energy consumption by tower was:
Lehua                            3364 kWh
Mokihana                         3379 kWh
Ilima                            3464 kWh
Lokelani                         3942 kWh

help
--Available commands are:
energy-since: [tower | lounge] [Start]
Returns the energy used since the date (yyyy-mm-dd) to now.
current-power [tower | lounge]
Returns the current power in kW for the associated tower or lounge.
daily-energy: [tower | lounge] [Date]
Returns the energy in kWh used by the tower or lounge for the specified date (yyyy-mm-dd).
rank-towers:  [start date] [end date]
Returns a list in sorted order from least to most energy consumed between the [start] and [end] date (yyyy-mm-dd)
--Enter a command (type 'quit' to exit):

quit
quitting...


Invalid commands and command line arguments:

"Just pressing the return key"
‘ ‘ is not a valid command

energy-since Ilima 2011-11
Bad xml 400: Range extends beyond sensor data, startTime 2011-11-01T00:00:00.000-10:00, endTime 2011-11-30T15:01:54.660-10:00:   Request: GET http://server.wattdepot.org:8190/wattdepot/sources/Ilima/e
nergy/?startTime=2011-11-01T00:00:00.000-10:00&endTime=2011-11-30T15:01:54.660-10:00&samplingInterval=15

energy-since Mokulua
Not enough arguments.

current-power
Invalid arguments for current-power.


current-power Mokulua
Mokulua is not a valid source name.

daily-energy
Not enough arguments.

daily-energy Ilima 2011-12-99
Argument "2011-12-99" is invalid :Invalid value 99 for Day field.

daily-energy Mokulua
Not enough arguments.

rank-towers  2011-11-28
Invalid arguments for rank-towers.

rank-towers  2011-11-24 2011-11-99
Argument "2011-11-99" is invalid.

rank-towers  2011-11-30 2011-11-24
End date must be greater than start date.


exit
'exit' is not a command!


The system responded in a useful and helpful way under both valid and non-valid commands and command line arguments with a few exceptions.  My conclusion is that the system satisfies prime directive 2 by providing clear, easy to understand instructions and documentation that is basically correct. The system runs as expected, and properly handles both valid and invalid input commands and command line arguments, except in a few cases. I have 'beautified' the output: in reality, the help message is displayed after every command, valid or invalid, and makes it very difficult to see the valid command output or even the error messages among all the help text.


Prime Directive 3: Can an external developer successfully understand and enhance the system?

To answer this question, I began by carefully reviewing the developer's guide wiki. It states that coding standards and quality assurance standards should be followed for this project, and briefly describes tasks a new developer can use. However, it says to use an xml file format for development without noting that the xml file is just an Eclipse code format file. It says to use the Elements of Java Style without saying what it is.

The developer wiki also says to use Issue-Driven Project Management and includes a brief explanation, even though this is clearly optional, just as Eclipse is optional. It says to check the CI build and includes a link, indicating the process followed by the developers.  The developer wiki does not explain how to generate JavaDoc documentation, and although it provides clear instructions on how to verify the system, detailed instructions for obtaining and building the system from source are not explicitly provided.
I checked out the sources from SVN (read only) using Tortoise SVN, generated and reviewed all the JavaDoc pages. They are well-written and informative, providing a basic understanding of the system architecture. Additionally, the names of the system packages, classes, methods, and fields are well chosen, and indicate their underlying purpose.  

Building the system from sources without errors was simple, just invoking a single command, Ant. However, verifying the system (Ant -verify verify.build.xml) failed about half the time while running the JUnit tests. The JUnit tests also printed alot of text to the console, indicating that the test were probably being run manually.
I generated coverage information regarding the system using Jacoco and it reported 80%, 60%, and 0% for the three packages in the system, for a total of 69% coverage. The test cases exercises 1,018 of 3,321 lines of code.

The test case source code should show how the developers are assuring the correctness of the functionality of the system.  Even though documentation is present, I found that in 50% of the test cases, it is difficult to understand exactly what functionality is being tested, and/or the methodology used. I believe more comments, or even better tests, would help. There are also spelling and grammar errors.

Although coverage is 69%, the command and processor test cases clearly do test the system under both valid and invalid input. I believe that in most cases, these existing test cases would prevent a new developer from making changes that break the existing code. Of course this depends on the level of programmer expertise and understanding of how to extend the current system.

A thorough examination of the source code shows that coding standards are followed and the code is commented appropriately.  The code is relatively easy to understand, and although the amount of commenting seems appropriate, some comments are clearly superfluous, and in other cases, insufficient. There are some classes such as FakeCommand and ReallyFakeCommand that seem to have been built for testing purposes. Not only are these the most confusing part of the system, they have the poorest documentation as well.

Examining the issues pages on Google project hosting clearly shows what parts of the system were built by each developer on the team, and it could be used to determine which developer would be the best person to ask questions regarding a particular component of the system. Also it reveals that roughly speaking, an equal amount of work (7,10, and 12 issues) from each of the developers went into the development of the system. Examining the issues pages does not account for the amount of work each issue required.

By inspecting the project page on the Jenkins CI server, it appears that any build failures were corrected promptly; the longest failure between successful builds was only 20 minutes.

From Google project hosting source changes page, I can see that only 5 of about 50 commits was not associated with a specific issue, and the total number of commits was 58 including the editing of wiki pages. By examining the commit log messages, issues page, and CI server, I can observe that the system was built in a consistent, methodical way.

My conclusion is that the system does satisfy prime directive 3, and a new external developer could easily and successfully understand the current system in its current state, and successfully enhance the system in the future.

























Sunday, November 20, 2011

Issue Based Project Management


In this blog entry I summarize an experience with issue-based project management, using and evaluating Google project hosting (GPH) and the Jenkins continuous integration server.

Google Project Hosting

For open source projects, Google project hosting enables anyone a free collaborative development environment. It enables fine-grained control and configuration, choice of repository, features an issue tracker, wiki pages, downloads, and more. I found it relatively simple and very reliable, and it reportedly scales well.

Jenkins

Jenkins is the leading open-source continuous integration server. It monitors executions of repeated jobs, such as building a software project, and in our case specifically, running an Ant script that verifys the system. The script compiles the code, builds the javadoc, runs our Junit tests, and then runs QA tools  checkstyle, PMD, and findbugs. Every time we do a commit, Jenkins assures the system builds by doing all this automatically and reporting failures.

The Process

My partner and I worked in different locations, using the GPH issue management system to effectively create, maintain, and evolve tasks and issues for implementing and managing  this project. It is like a global “white-board”, or can be used that way - as it is very flexible and customizable. Each commit (I used Tortoise SVN for Windows) can be linked to issue(s) using syntactic metadata in the commit log message. There are so many useful features in GPH I cannot possibly cover them all here.
Figure 1. Google Project Hosting Issues Page hale-aloha-cli-jz


Our basic workflow for each issue/task was to apply/change labels at the appropriate time as: new (ownerless), accepted (owner), started (implementing), fixed (finished), and verified (other team member looks at code and agrees). Even non-coding tasks were easy to capture using GPH. It is so effective, we rarely had to email back and forth as you can imagine might be required for collaborating on a software development project. This process really worked well for us. From inception and specification, through implementation, and testing, and verification, it all went smoothly.

The Project

Wattdepot

The wattdepot open-source project developed at the University of Hawaii is a collection of technologies and tools for collecting and storing data from electricity meters for smart grid research and experimentation. From the wattdepot Google hosting site: “WattDepot is an open source, RESTful web service that collects electricity data (such as current power utilization or cumulative power utilization) from meters and stores it in a database. The data can then be retrieved by other tools for visualization and analysis. It is designed to provide infrastructure for experimentation and development of "Smart Grid" applications.”

Hale-aloha-cli-jz

Our project, hale-aloha-cli-jz is a command line interface program written in the Java programming language, that interacts with wattdepot. Using hale-aloha-cli-jz can help those persons interested to understand various aspects of energy use without having to write code against the wattdepot API.

Functionality Implemented

The hale-aloha-cli-jz command line interface provides an interface to a subset of the wattdepot energy and power API .


Available Commands
  • current-power displays the current power in kW for the requested tower or lounge.
  • daily-energy displays the energy in kWh used by the requested tower or lounge for the specified date.
  • energy-since displays the energy used from date specified to now.
  • rank-towers displays a list in sorted order from least to most energy consumed between the start and end dates specified, for the four hale-aloha towers (buildings).
  • quit terminates the program.
  • help displays the available commands and command line options.
The Command Syntax


current-power [tower | lounge]
daily-energy [tower | lounge] [date]
energy-since [tower | lounge] [date]
rank-towers [start date] [end date]
quit

help



Overall quality of software  

I feel the quality of the code we developed is good, and in fact - better that it would have been without using Google Project Hosting and Jenkins. More importantly, I believe we developed the code faster, with less conflict and errors had we not used these project management tools.

Links to more information

Hale-aloha-cli-jz                               http://code.google.com/p/hale-aloha-cli-jz/
Google Project Hosting                     http://code.google.com/hosting/
Jenkins Continuous Integration         http://jenkins-ci.org
WattDepot                                       http://code.google.com/p/wattdepot/
Ant                                                  http://ant.apache.org/
Checkstyle                                       http://checkstyle.sourceforge.net/
Findbugs                                          http://findbugs.sourceforge.net/
PMD                                                http://pmd.sourceforge.net/
Tortoise SVN                                    http://tortoisesvn.net/
Eclipse                                            http://www.eclipse.org/
Jacoco Code coverage tool               http://www.eclemma.org/jacoco/























Tuesday, November 8, 2011

WattDepot Code Katas

I decided to write some code using the WattDepot project open source API. I used the code-kata approach, completing 4 katas in the time I allotted myself.

Electrical energy basics

The katas I wrote served as an introduction to manipulating energy data using WattDepot. I found it interesting and informative. The 4 katas I coded were as follows:

  • SourceListing
  • SourceLatency
  • SourceHierarchy
  • EnergyYesterday

These Katas took about 8 hours to complete in a "fist pass" approach. Given more time, I would do a code walkthrough and make sure the expected output is correct.

Wednesday, November 2, 2011

Overview of Energy in Hawaii


In this short blog entry, I hope to impart both appreciation and insight about energy, exposing important energy-related concepts. Next I discuss the challenges and opportunities for energy in the state of  Hawaii.

Electrical energy basics

In general, people don't have the same intuitive knowledge about electrical energy as we do about other physical things like, speed, distance, time, and perhaps more closely related: horsepower. For example, everyone knows the same car but with a bigger engine will go faster and use more gas, and easily understand the concepts of “how much faster”, “how much more fuel”, as well as “how much more money spent on fuel”. A thorough understanding of the concepts of energy and power as they relate to electricity are not as common.

Below I list some basic facts about electricity, energy, power, and how they are related:

Electrical Energy

  • Energy is what makes thing go, for example, what is stored in a battery.
  • Energy is measured in watt-hours (Wh) or kilowatt-hours (kWh).
  • 1 kWh = 1000 Wh.
  • Energy is what you are billed for each month.
  • Energy = power * time.

Electrical Power

  • Power is the rate at which energy is being used measured in watts (W) or kilowatts (kW).
  • 1 kW = 1000 W.
  • Power = energy/time.
  • Power usage is important because it usually more well-known than energy.
  • For example, the power usage of a fluorescent light bulb is 13 watts, and a microwave oven uses about 1300 watts.
  • Conserving energy requires an awareness of both power usage of a device, and how long devices are turned on.

Building intuition about electrical energy and power by example:

Consuming Electrical Power (examples)
  • Cell Phone: 1-5 W
  • Laptop: 50-100 W
  • Microwave Oven: 1000+ W

Generating Electrical Power
  • Stationary bike: 200 W
  • Single solar panel: 175 W
  • Single large wind turbine: 2 MW
  • Oil-based power plant on O’ahu: 88 MW
  • All power plants on O’ahu: 1.2 GW

Using Electrical Energy in Hawai’i
  • Average home uses 20kWh per day
  • Single solar panel generates about 1 kWh per day, so a house would need about 20 panels
  • Hale Aloha Tower Dorm building uses about 1,500 kWh per day
  • Entire UH Manoa campus uses about 260,000 kWh per day
  • Entire state of Hawaii uses about 27 million kWh per day

Political climate and choices in Hawai’i

In Hawai’I, the cost of 1 kWh is the highest in the nation at about 20 to 30 cents, and up to 60 cents on neighbor islands. As seen in the news and ads about energy, it would seem there are easy options for reducing costs, such as solar and wind power. However, there is controversy about renewable sources of energy on the Hawaiian Islands. Why? On Kaua’i there is a debate centered in large part around the decision to engage a Mainland developer (read more here).

And wind power is not embraced by all residents. For example, on Lana'i people are scared of the impact of the invasion of 170 turbines, each 410’ tall, on one-quarter of the island's land (see video). As can be imagined, there will be people both for and against tax increases to fund renewable energy initiatives.

Energy challenges we face in Hawaii:

Hawaii's set of energy challenges and opportunities are unique. We must find the answers for ourselves, and cannot depend on the mainland to understand our cultural, political, financial, and other factors. Energy costs here are about 3 to 6 times more expensive than the mainland, providing a lot of incentive to find real solutions.

We have two main drawbacks compared to the mainland:

1) Mainland power plants can be much larger and can share energy.
2) Raw materials are more expensive in Hawaii: oil counts for 77% on Hawaii vs 1% on the mainland and this high cost is likely to grow.

But unlike any mainland state, Hawaii has more modest needs, and almost every source of renewable energy: wind, wave, ocean thermal, geothermal, as well as the potential to generate all its power from renewable resources. They become cost effective here long before they become cost effective on the mainland because of the drawbacks stated above. The energy choices we make will also affect climate change. Finally, the current high cost on Hawai’i is a motivating factor.


The Hawaii Clean Energy Initiative

Hawai’i currently sends $6B a year outside Hawaii to purchase oil.
Baseline demand in Hawaii is expected to grow to 1,200MW by 2030.
The HCEI is the most aggressive goal for clean energy in the nation.
The goal is to achieve 70% clean energy by 2030.
The first goal is to obtain 40% of projected energy demand through renewable energy.
The second goal is to save 30% of power needs through conservation and efficiency.

How can we make a difference?

Ideas for personal reduction of energy consumption include: driving a more efficient vehicle, taking the bus, bicycling, skateboarding, or walking, as well as replacing light bulbs with lower watt alternatives.
We can support approaches like: solar, wind energy, ocean thermal, geothermal, and bio-fuels. We can get involved in projects in Hawaii that address any of the issues discussed!