Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Friday, December 2, 2011

Hale Aloha CLI Technical Review

This is a continuation of the last blog entry I've posted. Essentially the purpose of this blog entry is to detail the findings of a complete review of a software system. The system on hand is the Hale Aloha CLI system developed by Team cycuc

The following is the technical review our team put together, with respect to the three prime directives.


Review Question 1: Does the system accomplish a useful task?
Below is a sample run of team cycuc’s system:

When we initially ran Team cycuc's .jar file there was a slight problem as it could not successfully run. Eventually one of cycuc's team members had updated the system for it to successfully run in console. For the most part, this system provides functionality as described in the assignment specifications. For example, the formatting of both the date and power / energy is not in the same as the sample output given.

> current-power Ilima-A
Ilima-A's power as of 2011-11-07 13:48:56 was 2.3 kW.
> daily-energy Mokihana 2011-11-05
Mokihana's energy consumption for 2011-11-05 was: 89 kWh.
> energy-since Lehua-E 2011-11-01
Total energy consumption by Lehua-E from 2011-11-01 00:00:00 to 2011-11-09 12:34:45 is: 345.2 kWh
> rank-towers 2011-11-01 2011-11-09
For the interval 2011-11-01 to 2011-11-09, energy consumption by tower was:
Mokihana  345 kWh
Ilima     389 kWh
Lehua     401 kWh
Lokelani  423 kWh

This may be an issue for some people depending on how they plan to process the data given. Reporting the data given in units such as kilowatt may be more desired. In the case of the rank-towers command, no units appear next to the output given which may confuse those not familiar with the system. Also, it appears that for the commands daily-energy and energy-since reports the wrong units with respect to the data given. From personal experience with the getData() method, the data returned by this method must be converted correctly to M Wh. In this case, 549 kWh should be 0.549 M Wh.

For example, the formatting under the current system is as follows;

> current-power Ilima-A
Ilima-A's power as of 2011-12-01T22:56:50.337-10:00 was 6756.08 W.

Some of the commands do not successfully return data at all, below is a sample of the code when the rank-towers command was executed.

> rank-towers 2011-11-01 2011-11-09
Connected to server successfully.
Rank Towers by Energy consumed, from 2011-11-01T00:00:00.000-10:00 to 2011-11-09T00:00:00.000-10:00
Caught an exception! Here's the message: 
400: Range extends beyond sensor data, startTime 2011-11-01T00:00:00.000-10:00, endTime 2011-11-09T00:00:00.000-10:00:   Request: GET http://server.wattdepot.org:8190/wattdepot/sources/Ilima/energy/?startTime=2011-11-01T00:00:00-10:00&endTime=2011-11-09T00:00:00-10:00&samplingInterval=60

Sorry, due to technical difficulties, the data from WattDepot has been lost, the current range of datais from 2011-11-24 to the current date. 

> rank-towers 2011-11-25
Connected to server successfully.
Rank Towers by Energy consumed, from 2011-11-25T00:00:00.000-10:00 to null
Caught an exception! Here's the message: 
null

Essentially the system attempts to implement the four commands listed in its help menu. The exact usefulness of this system is debatable as we deem this version of cycuc’s system not ready for distribution.

Review Question 2: Can an external user successfully install and use the system?
In addition to containing the files for hale-aloha-cli-cycuc, the project site provides a very general idea of what the project is and does.  The home page has a brief description of the system and a picture that presumably provides an explanation for the group name.  This does give viewers an idea of what the system does, but not a very clear concept.  There is no User Guide page; instead is a page titled “PageName” that contains most of the information that the User Guide should.  The exception though is how to execute the system, which is not covered.  The distribution file in the Downloads section does include a working version of the system along with an executable .jar file.  The version number is included in the distribution folder name, allowing users and developers to distinguish between different versions.  These version numbers include the timestamp corresponding to the time at which the distribution was created, thus letting users and developers compare versions chronologically.  The numbers that actually indicate major and minor versions appear to have remained at 1.0 since the first downloads became available.

The tests of the system are shown below:

Valid Input:
> current-power Ilima-A
Ilima-A's power as of 2011-12-01T23:11:50.751-10:00 was 6333.76 W.

> daily-energy Mokihana 2011-11-25
Connected successfully to: org.wattdepot.client.WattDepotClient@2be2befa
Mokihana 
509734.840423 MW consumed on 11/25/11 

> energy-since Lehua-E 2011-11-25
Connected successfully to: Lehua-E
Source: Lehua-E      
639210.4079087041 MW consumed since 11/25/11 

> rank-towers 2011-11-25 2011-11-26
Connected to server successfully.
Rank Towers by Energy consumed, from 2011-11-25T00:00:00.000-10:00 to    
2011-11-26T00:00:00.000-10:00
Mokihana-06-telco      15385.932595232502
Lokelani-08-telco      16653.69566474599
Lokelani-12-telco      19451.44859161321
            Lehua-10-telco      19645.025624631904
     

       Invalid Input:
       > current-power Ilima-z
       Caught an exception! Here's the message: 
       Invalid source: Ilima-z
       java.lang.NumberFormatException: For input string: "Ilim"

> daily-energy Mokihana 2011-11-33
Caught an exception! Here's the message: 
Invalid timestamp: Invalid day 33 days are 1 - 31

> daily-energy Mokihana 2011-11-25
Connected successfully to: org.wattdepot.client.WattDepotClient@7114460
Mokihana  
509734.840423 MW consumed on 11/25/11 

> energy-since Lehua-L 2011-11-27
Caught an exception! Here's the message: 
Invalid source: Lehua-L
java.lang.NumberFormatException: For input string: "Lehu"

> rank-towers 2011-1124 alsdjaflakdsf asdlkfjasd;flkajs fklajsdlfk sdf;lkafj k;djf ;akdjf;lkasfajs 
jdkl;asfj s;dlfkjas ;dlkfj asdl;kfj asfl;kasdj fasdl;kf jasl;kdfj as;lkfja sd;lfkajs ;lfkjas f;lkajsdf 
asd;lkfjas l;kdfjas ;dlfkjasd f;lkasjdf;lkas jf;laksjf as;ldkfjasl ;fkjasd;lfkjas
Connected to server successfully.
Rank Towers by Energy consumed, from 2011-11-25T00:00:00.000-10:00 to null
Caught an exception! Here's the message: 
null
//this tests overflows the buffer

Review Question 3: Can an external developer successfully understand and enhance the system?
Next, check out the sources from SVN (read only), and see if you can generate the JavaDoc documentation.  If it can be generated, review all of the JavaDoc pages to see if they are well-written and informative.  Do the JavaDocs provide a good understanding of the system's architecture and how individual components are structured?  Do the names of components (packages, classes, methods, fields) clearly indicate their underlying purpose?   Is the system designed to support information hiding

Next, see if you can build the system from sources without errors.  See if you can generate coverage information regarding the system.   Next, review the test case source code to see how the current developers are assuring the correctness of the functionality of the system.   By combining information from the coverage tool with review of the testing source code, you should come to a conclusion about how well the current set of test cases can prevent a new developer from making enhancements that break pre-existing code. 

Now read through the source code, and check to see if coding standards are followed and if the code is commented appropriately.  Is the code easy to understand, and is there neither too much nor too little commenting? 

Next, check the Issues page associated with this project.  Is it clear what parts of the system were worked on by each developer?  If an external developer had a question regarding a certain part of the system or a certain aspect of its behavior, could the Issues page be used to determine which developer would be the best person to ask? Does the current system appear to result from approximately equal input from all of the developers, or did some developers appear to do much more than other developers? 

Now check the CI server associated with this project.  Apart from Nov 22-24 when there were known outages, did any build failures get corrected promptly?  Was the system worked on in a consistent fashion?  Were at least 9 out of 10 commits associated with an appropriate Issue?  

Carefully document the results of your investigations into each of these issues, and use the results to come to a conclusion regarding the ease with which a new external developer could successfully understand the current system and successfully contribute with the current team to enhancing it in future.

The Developers’ Guide wiki page on the cycuc project site provides clear instructions on how to build the system in Ant.  The guide also includes information on the automated quality assurance tools used on the project.  Specific information about those tools is not given, but developers are informed that the verify task will run all of the automated quality assurance tools.  A link to the formatting guidelines serves to document the stylistic rules that the code is to follow.  The Developers’ Guide does not mention Issue Driven Project Management or Continuous Integration.  Similarly, instructions on how to generate JavaDoc documentation are not available, though the documentation does appear to come with the project in /doc.

JavaDoc documentation, as mentioned above, comes with the project in /doc.  However, developers may still generate JavaDoc files through Ant or Eclipse.  The JavaDoc documentation itself tends to be well-written, though there are some questionable points and the description is somewhat sparse.  Several methods lack descriptions in their JavaDoc documentation.  There are a few contradictions within the documentation, as in CurrentPower.java where the description for the printResults method (line 28) indicates that the text printed is based on days[0] while the parameter tag for days (line 31) states that days is ignored.  However, the JavaDoc documentation did show the organization of the system, and the names of the various components were well matched with their actual purposes.  The system does appear to have been designed to implement information hiding, with the Command interface serving as an example.  

The cycuc system builds without errors in most cases.  A timeout while attempting to access the server will cause the entire build process to stop, which accounts for the instances in which the build fails.  Aside from timeouts, the system builds properly.  

The data that Jacoco provides concerning test coverage does induce some slight concerns about the validity of the testing.  The halealohacli package has no testing at all.  Testing on the halealohacli.processor package covers 67% of the code and 58% of the possible branches.  For halealohacli.command, 94% of the code was executed in testing, while 59% of the branches were taken.  (These values seem to vary upon repeated testing; this may be due to the aforementioned timeouts.)  These low values for branch coverage in particular may stem from a lack of testing for invalid input.  As a result, none of the exceptions are checked.  The tests indicate that parts of the system work for a particular input; however, as there is only one test per test class (with the exception of TestProcessor) it is difficult to be certain that the system does behave correctly.  Thus, the existing testing will not necessarily stop new developers from breaking the system; the testing ensures that developers cannot treat valid input incorrectly, but does nothing to stop invalid input from causing problems.  

With regard to coding standards, there exist several minor deviations from the standards that do not affect the readability of the code.  The amount of comments varies: at times, there is a comment explaining every line of code, while at other points there are entire blocks of code without any documentation.  The deviations from the coding standards are provided below:

EJS-07: Include white space.
There is a lack of whitespace in the test methods of TestRankTowers, TestDailyEnergy, and TestCurrentPower.

EJS-13: Capitalize only the first letter in acronyms.
HaleAlohaClientUI class capitalizes “UI” instead of only capitalizing the first letter.  Admittedly, “HaleAlohaClientUi” might have been confusing to read.

EJS-29: Qualify field variables with “this” to distinguish them from local variables
In HaleAlohaClientUI:
    HaleAlohaClientUI:
        prompt (line 66)
    isFinished:
        finished (line 27)
    promptForOperation:
        scanner (line 130)
In Operation:
    getString:
        string (line 35)
In CurrentPower:
    getPowerConsumed:
        powerConsumed (line 24)
In DailyEnergy:
    printResults:
        energy (line 44)
In TestProcessor:
    testGetSource:
        processor (lines 37, 47, 59, 60, 75, 80, 81)

EJS-30: When a constructor or “set” method assigns a parameter to a field, give that parameter the same name as the field.
In Processor:
    setSource (line 135)
    setTimestamp (line 81)
    Note though that in both of these cases the methods are not actually setting the field to the parameter value.

EJS-31: Use uppercase letters for each word and separate each pair of words with an underscore when naming constants.
In HaleAlohaClientUI: 
    prompt (line 34)
In Operation:
    quit (line 10)
    help (line 12)
    currentPower (line 14)
    dailyEnergy (line 16)
    energySince (line 18)
    rankTowers (line 20)

EJS-33: Keep comments and code in sync.
In HaleAlohaClientUI:
    “When we have the processor class implemented...” (lines 38-39)
        The Processor class is already implemented as of this writing.

EJS-35: Use documentation comments to describe the programming interface.
In HaleAlohaClientUI:
    JavaDoc comments were used repeatedly where single-line comments would have been preferable.

EJS-53: Provide a summary description for each class, interface, field, and method.
In HaleAlohaClientUI: 
    isFinished (line 26)
In DailyEnergy:
    getEnergy (line 48)
In EnergySince:
    getEnergy (line 49)
In RankTowers:
    rankTow (line 56)
In Processor:
    getTimestamp (line 179)
    getBeginningTimestamp (line 187)
    getEndTimestamp (line 195)

ICS-SE-Java-6: Format JavaDoc summary lines correctly.
In TestDailyEnergy:
    test (line 22)
        The first “sentence” in the JavaDoc documentation is “1.”  This does not adequately describe the method.

Overall though, the code is readable; admittedly, the person testing the code had already implemented the project for a separate group and thus might be familiar with the objectives of the code, which would affect the results and opinions of the tester.  

Looking through the Issues page associated with this project, it is clear what parts of the system were worked on by each developer. This team utilized a variety of status options available to better inform an external developer what worked and what didn’t work with respect to project progression. In some cases, clarification in the form of comments show the decision making process this team used when dealing with issues. Since each issue described clearly explains what the task was, it should be easy for an external developer to determine which developer would be the best person to collaborate with. In terms of work input from all of the developers, it appears that some team members did more than others.

Turning to the CI server associated with this project, it appears all build failures were corrected promptly with a maximum latency of roughly 30 minutes. Also, looking through each successful build, this team showed that they were working on this project in a consistent fashion where at least 9 out of 10 commits associated with an appropriate Issue.

Tuesday, October 11, 2011

One robot to rule them all

Alas, my robot project has come to an end. However there is still one more act in this play, the epilogue of my journey of which is called robocode. The name of my competitive robot is called RobotDevil because just like the real devil, you never know what (s)he is going to do, or not do... The inspiration of my robot was the idea of a snowflake. They say that no two snowflakes are alike, and I would like to believe that when a user runs RobotDevil, no two instances will behave the same. Without further ado, whose cuisine robot will reign supreme?

Overview 
If I asked you to pick a number between 1-10 and use that number as some sort of 'random' generated output, how 'random' would that be? The same theory applies to what I had attempted in my robocode project. I had set out to try create a robot that ideally will not win 100% of the time yet not lose 100% of the time either. A rudimentary coin flip of a robot would be my esoteric description. In essence I opted to build a robot that would display 'random' movement behavior, an optimal firing scheme and sophisticated tracking logic.

Design
Movement: Movement is the heart and soul of RobotDevil, since our movement paradigm is limited to the battlefield and 360 degrees of turning options, the 3 factors in movement for RobotDevil was the degree of the turn, length of the turn, and condition of a hit wall. The general strategy for moving the robot was to create unpredictable behavior, since most advance robots will attempt to predict RobotDevil's next movement. The only downside to this approach is that RobotDevil may not make the most logical decisions, such as moving towards an enemy bullet or walls.

Targeting: Targeting is relatively simple in the design of RobotDevil, once an enemy robot has been scanned by our robot, the robot will adjust the firepower to either the MAX_BULLET_POWER or 1. RobotDevil continuously sweeps the area by rotating the radar and gun 360 degrees.

Firing: Firing is simple since once RobotDevil sees another robot it either fires a weak bullet or the strongest bullet. The measure taken to anticipate the movement of an enemy robot was not taken since our movement is not predictable.

Results (Out of 100 rounds)
RobotDevil 2606 (14%) V.S. Walls 16575 (86%)
RobotDevil 17549 (52%) V.S. RamFire 16466 (48%)
RobotDevil 1867 (10%) V.S. SpinBot 17423 (90%)
RobotDevil 10136 (59%) V.S. Crazy 6993 (41%)
RobotDevil 20612 (68%) V.S. Fire 9593 (32%)
RobotDevil 15093 (51%) V.S. Corners 14241 (49%)
RobotDevil 2664 (12%) V.S. Tracker 19446 (88%)
RobotDevil 18020 (100%) V.S. SittingDuck 0 (0%)

As the results show, RobotDevil performed horribly against Tracker, SpinBot and Walls. Partly due to the fact that these robots stay at a distance and attack rather than approach other robots. I suppose one design improvement RobotDevil could use is a better tracking system. 

Testing
Majority of the testing was done to ensure that the movement of RobotDevil was truly random. So jUnit tests to check between two length in distances traveled are not the same. It is suffice to say that the tests were a good indicator of random movement but this brings me back to my original question of how random is random.

Lessons Learned
I felt that this robocode development experience provided myself with invaluable experience in jUnit and simple software development principals. It was a great introduction in testing practices such as behavior in code. Perhaps after seeing some of the robots developed by my fellow software developers, it will provide me with inspiration on possible future implementations in RobotDevil.

Tuesday, September 20, 2011

Robocode Katas

When thinking of katas the first thing that comes to my mind is the next karate kid.  More specifically the scene where Julie-San asks Mr. Miyagi when she was going to start breaking boards.  Mr. Miyagi responds by telling her to continue washing his car, remember 'wax on, wax off.'  This is where the beauty of Katas come in, it might seem repetitive to wash a car, or print a hello world program, however the underlying idea is that you are sharpening specific skills.  Katas are not necessarily easy, some katas may challenge you and bring you to the brink of frustration and insanity.  I welcomed this idea of a programming challenge and applied the code kata idea on building robots.


danger danger will robinson... these aren't the robots you're looking for. In fact these robots are part of an open source game called Robocode.  These robots fight for the user and set out to destroy other robots, until there is only one.  Robocode is a game in Java, where programmers can build their robots to do all sorts of fantastic things. These robots are very intricate, because of all the things the user must account for when building his/her ultimate robot.  Such as the direction the robot is facing, the direction the gun is facing, the enemy robot, and the strength of attack. 



  • 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.
  • 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). 
I've successfully finished the code katas listed above, however I've yet to implement a working version of the following robots
  • Position06: Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
  • 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). 
The main problem I've had with these 2 code katas is that it involves the use of trigonometry and that is a field where I lack in. Although I have gained a lot of knowledge in developing a basic robot that involves moving, firing, and scanning. While doing these katas I found myself looking at the Robocode API since it was a very useful page displaying the functionality of everything in Robocode. Also I've gotten more comfortable reading other people's code. One of the code katas asked for the robot to reach the middle, and a researcher at IBM had posted his code that solves this in an intricate way. Overall my ineptness to use trigonometry haltered the completion of the last two katas.  

My future plans on Robocode would involve building a competitive robot that will incorporate trigonometry. I will focus on the firing aspect on my competitive robot, as this will indefinitely help fire me into robot glory. 

Wednesday, August 31, 2011

FizzBuzz

Recently I implemented the FizzBuzz programmed discussed on our first day within the Eclipse IDE. The task was to implement the FizzBuzz program within the Eclipse IDE. The time it took total was 9 minutes to code the program, in addition it took another 11 minutes to comment and verify the output of the program. JUnit wasn't used for verification and so each output was examined for its validity. The main problem I had faced was cleaning up the code, so it isn't 'messy'.  


Cleaning up the code involved creating a FizzBuzz object that handles the logic portion of the problem. The getOutput method within FizzBuzz will return a string representation of the number taken. There is still more room for improvement in the code, primarily incorporating software engineering principles in the code. Below is the source code for my FizzBuzz implementation.

1:  package edu.hawaii.ics314;  
2:    
3:  /**  
4:   * @author Jason Yeo  
5:   *   
6:   * FizzBuzz program should print out all of the numbers from 1 to 100  
7:   * one per line, except that when the number is a multiple of 3  
8:   * it will print "Fizz", when a multiple of 5, it will print "Buzz"  
9:   * and when a multiple of both 3 and 5, it will print "FizzBuzz"  
10:   */  
11:  public class FizzBuzz {  
12:    
13:       public static void main(String[] args){  
14:            FizzBuzz fb = new FizzBuzz();  
15:            for(int i = 1; i < 101; i++){  
16:                 System.out.println(fb.getOutput(i));  
17:            }  
18:       }  
19:         
20:       /**  
21:        * @param number  
22:        * @return String  
23:        *   
24:        * getOutput will accept an integer ranging from 1 to 100, and   
25:        * will return the respective String output. The String output is  
26:        * based on the requirements set by Professor Johnson in his requirements   
27:        * for the FizzBuzz program.  
28:        */  
29:       public String getOutput(int number){  
30:            if(number % 15 == 0){  
31:                 return "FizzBuzz";  
32:            }  
33:            else if(number % 3 == 0){  
34:                 return "Fizz";  
35:            }  
36:            else if(number % 5 == 0){  
37:                 return "Buzz";  
38:            }  
39:            else{  
40:                 return String.valueOf(number);  
41:            }  
42:       }  
43:  }  

Note that I had modeled my code after the solution created by the class.    

Monday, August 29, 2011

JNetTool: A Handy Networking Tool

Overview
Sourceforge holds a wide array of open source projects and to my surprise I found a Java related project that dealt with networking.  The reason I chose the JNetTool was because I am currently learning the workings of TCP/IP and all of its intricacies.  The description for JNetTool is as follows, "A network tool with gui for whois, ping, traceroute, ns lookup (dig,dns), portscan, network calculator, visual net plan - written in java."  Indeed all of the components in JNetTool makes for a handy networker's 'pocket knife'.


I will demonstrate the features within JNetTool and show that this package satisfies the three prime directives.


1. The system successfully accomplishes a useful task.
The one component within JNetTool that I was very excited to see was the Net-Calc option.  Subnetting is somewhat a tedious task for me and having a subnet calculator makes life much easier.  The Net-Calc option has all your standard subnetting options such as network class/CIDR, subnet mask, number of hosts, network and broadcast address and IP range.  

Example of the Net-Calc tool in JNetTool

What JNetTool does to go above and beyond is the option to 'show next subnet with this number of hosts', which will iterate subnets with the designated number of wanted hosts.  The PortScan option offers a basic portscanning tool.  While it is not as robust as Nmap it does its job.  

Example of a port scan done on uhunix (selected ports for brevity)

2. An external user can successfully install and use the system.
JNetTool's documentation page, holds an up to date change log and links to relevant pages. Unfortunately the developer seems to be have an extensive documentation in German, which I am unable to understand.  However within the JAR file was several .txt files describing his project.  There were no problems downloading and installing JNetTool.  Since the project was packaged as a JAR, it ran as a applet when opening it.  The fact that I was able to run JNetTool on my first try is a good indicator of this system meeting the 2nd prime directive. 

3. An external developer can successfully understand and enhance the system. 
The source code for JNetTool is available on sourceforge and is well written as it is extensively commented.  Since there are several tools within JNetTool (whois, dns, ping, traceroute, etc...) the source code is somewhat large and would take time for me to fully read and understand how it works.  However this is a minor problem since the code is structured and commented well.  

Example of the source code for JNetTool (BrowserLauncher.java)

Overall I feel that running and examining JNetTool was a great way to get my feet wet in the realm in software engineering.  I would love to venture out and possibly create/enhance JNetTool in the future. I believe I'll find motivation in the great words of Captain Jean Luc-Picard... "make it so"