Wednesday, February 18, 2009

My First Hackystat Data Retrieval Program

We are about to start coding for the Devcathlon system. If you do not know, the devcathlon system is a “game” my software development class is going to make. The game consists of matches against software programmers. Before we can start coding for the devcathlon, we have to learn how to retrieve information from the Hackystat server (http://dasha.ics.hawaii.edu:9879/projectbrowser/). Our professor, Dr. P. Johnson, gave step-by-step tutorials on how to retrieve information from the server (http://code.google.com/p/hackystat/wiki/Screencasts).

With all that resources available, I code my first basic hackystat program. This program will retrieve the total number of data instances for each day of November, 2008 that was submitted to hackystat server. A data instance can be coding time, number of commits to main repository, and etc. My program will retrieve data instances from November 1, 2008 to November 30, 2008. Then it prints out the total number of data instances for each day, and the total for November 2008.

import javax.xml.datatype.XMLGregorianCalendar;
import org.hackystat.sensorbase.client.SensorBaseClient;
import org.hackystat.sensorbase.resource.sensordata.jaxb.SensorDataIndex;
import org.hackystat.sensorshell.SensorShellException;
import org.hackystat.sensorshell.SensorShellProperties;
import org.hackystat.utilities.tstamp.Tstamp;

/**
* My first Hackystat program to get information from U. of Hawaii Hackystat server.
*
* @author Ka Hung Phillip
*
*/
public class HackystatTask1 {

/**
* Get the total number of data instances for each day of November 2008.
*
* @param args
* @throws SensorShellException
*/
public static void main(String[] args) throws Exception {
String host = "http://dasha.ics.hawaii.edu:9876/sensorbase";

SensorShellProperties properties = new SensorShellProperties();

String user = properties.getSensorBaseUser();
String password = properties.getSensorBasePassword();
System.out.println(user + "\n");

SensorBaseClient client = new SensorBaseClient(host, user, password);
client.authenticate();

String project = "Default";
XMLGregorianCalendar startTime = Tstamp.makeTimestamp("2008-10-31");
int total = 0;

for (int i = 0; i < 30; i++){
XMLGregorianCalendar endTime = Tstamp.incrementDays(startTime, 1);
SensorDataIndex index = client.getProjectSensorData(user, project, startTime, endTime);

System.out.println("Total # of instances for " + endTime + " is: " + index.getSensorDataRef().size());
total = index.getSensorDataRef().size() + total;
startTime = endTime;
}

System.out.println("---------------------------");
System.out.println("Total instances for November is: " + total);
}

}


I am still working on my second basic program that will retrieve data instances on any given month. My for loop that program is giving me funky results, fixing it and will have that code up probably later in the day.

This is cool that I can get instances from the Hackystat server; maybe in the future I can create plug-ins for other IDEs (jokes). My first problem I ran into was getting to the right command to retrieve data. I used the APIs on hackystat wikis to solve it. The second problem was getting the XML Gregorian Calendar date for correct retrieval. I forgot to put in the new date after each retrieval, fixed that and I got it to work. Right now, I am fine with Hackystat APIs, there is no problem for me as of now.

No comments: