Sunday, March 13, 2011

Bug Fixes

I spent most of both days this weekend in Concord watching my daughter and her fellow dancers do a great job at a competition. It was a fun time being proud of my daughter, but I didn't make a lot of progress on this project.

I did manage to fix a few bugs with the interaction of the combo boxes to narrow down the accounts by categories. The major one was that when you double click on an item in the table or chart the corresponding combo box is selected. But, the list of available categories to group by was losing too many items. It was just supposed to lose the item that was just selected. It turns out that the first update to the list was causing a nested update that removed the wrong item. During the initial update I set a flag that I already had to prevent redundant updates and that made it work much better.

I also fixed a performance bug when the model RDF files were opened. I had added a cache for the Jena models, but it turned out I wasn't putting the models in the cache. That was an easy fix once I realized the cause. I found it when I added better logging using SLF4J. I've used log4j almost exclusively in prior projects, but Jena uses SLF4J so I looked into it. It allows the logging to be switched at deploy time, which is cool, and I am still using log4j underneath.

I fixed the sorting of the table column of budget amounts. I had rendered floats from Jena using NumberFormat into Strings that were added to the table. But, as I've seen countless times before, sorting numbers as Strings sorts the first digit, not by place value. I fixed this by using BigDecimal consistently so I can get numeric sorting, control over the decimal places so they always show cents, and I added a simple renderer to the table to add commas to separate the thousands.

Lastly, I started adding unit tests based on UISpec4J. I haven't used this before, but I've done a lot of unit testing of non-GUI code before and from what I read on the web, UISpec4J seems like a great framework for Swing applications like this. I have very basic tests working, but my first substantive test that opens an RDF file is stuck trying to capture the heavyweight FileDialog that is recommended for Mac OS X. Or, maybe I just don't have the window interceptors initialized properly. I added a menu item to open an RDF model from a file for faster and more targeted testing, but I still don't have this test working. Still a few bugs to work out....

Sunday, March 6, 2011

Untethered

This week I have continued to work on the Budget Viewer application. I have focused on 2 main areas: 1) make it run anywhere, 2) make it start up faster. Making it run anywhere - untethering it - is a bigger step than you might think. At the start of this week, it would only run from a single directory on my computer. That directory had to have the SPARQL query files and RDF files. Both of these had to be changed so you could run the application, too. I also explored the next step of packaging the application to make it easier for you to install.

My first step actually fell out of some exploring into making the application work under either Windows or Mac OS X. Even though Java is billed as a cross platform environment, it is really more Windows-centric than neutral. So, there are several articles on how to make Java applications fit better under Mac OS X. One of those articles included an adapter for Mac OS X that included a build.xml file for Ant. I replaced my BASH script to build with a heavily-edited copy of this build.xml. The real advantage of this build.xml file is it has tasks to build the Java program as a double-clickable Mac OS X application. (Here's another extended article.) Beyond the Mac OS X application packaging I think I'll just create a DMG disk image and copy the application onto it for distribution. In other words, I don't think a Mac OS X installer is needed.

For Windows, I think an installer is needed since I need to create start menu shortcuts and registry entries. I found the Nullsoft Scriptable Install System (NSIS) which is an open-source full-featured tool to create Windows installers. I found a bunch of examples on the web that I was able to mash together for a simple installer.

The Java runtime is another big question for installers. For Mac OS X, at least for now, Java is already installed with the base system. I can't rely on that for Windows, but I don't really want to include the full Java runtime since that will more than double the size of my application. So, for now I just check that the compatible version of Java is installed and if not report an error and quit. I don't like it, but for now I hope it is good enough.

Returning to the SPARQL query files, I handled them through the build.xml file. I put all my Java files in reasonable Java package directories and embedded a query subdirectory where I moved all the SPARQL files. I then use a Classloader to read in the files. This allows me to package them in the Jar file that the build.xml file builds so now that part no longer ties the application to my environment.

The RDF files will come from the ORCSD data web site. I've been focusing on this application to verify that the RDF files are OK, but I really need them there so I can test the application in different environments. So, I've copied the first few files "as is" to the web site. If you'd like to take a peek, here they are with the caveat they are very likely to change:

With these RDF files minimally available on the web, the Budget Viewer application can now run from anywhere.

A noticable downside of moving the RDF files to the web is the time it takes for the application to start up. It was slow before, but now it is very slow. I had sped up the normal operation after start up by caching the models. During start up, though, it is still bogged down by reading the models.

The application was reading the models as part of constructing the GUI components. So, it wouldn't display anything until it was all ready. This clearly wasn't going to work. I first tried starting with a dialog to ask for the URL for the budget RDF file. This was clunky and I struggled a bit to figure out how to go from the budget RDF file to the account lines and accounting categories RDF files. While I eventually figured out how to extract the resource prefixes and convert them to URLs using Jena, I also switched to constructing the basic GUI without the parts that depend on the models and added an Open menu item. This GUI starts up in a few seconds, which will work fine. It lets the user know it is working and gives a palette to display a busy cursor and "Loading..." status message. I still think it is a bit rough, but it is progress.

Here's the initial window:



When you select the Open menu item, this dialog comes up with the ORCSD budget URL already filled in:



While the budget is loading, the cursor changes to a spinning ball and the window displays a simple status:



And, then when it is done, you get the full Budget Viewer that you've seen before, but with a few additional properties for more categories in the bottom right:



That's it for this week. I hope very soon to be at a point where it is good enough for you to try out.

Monday, February 28, 2011

Jena Models

I made a little more progress tonight on the Budget Viewer application. No new pictures since it looks the same as yesterday. The interaction is a bit less buggy, though still not quite correct.

The biggest change is in how I use the Jena API. I now read the RDF and query files only once and then query them repeatedly. This makes the application much faster. It was painfully slow before, and now it is quite reasonable. I was previously concerned whether I could use SPARQL repeatedly or just once to get the original data and then troll the results as needed. With this speed I think I can stick with SPARQL. That makes the application much easier to write.

Another advantage of this change in the API calls is that the queries now have no references to the specific RDF files or prefixes. Only the budget vocabulary, SKOS, RDFS and RDF which are all quite generic. This means it will be easy to use any set of budget data, whether from ORCSD or anywhere else. That's great!

This also brings back the issue of finding budget data. I need to add a way for the application to ask for the budget data to view, probably using a form. But, that's for another night....

Sunday, February 27, 2011

Budget Viewer Selection

This weekend I have made more progress on the Budget Viewer application. I am using this application to validate the RDF files, and I am still finding problems. For example, the ORCSD account categories RDF file includes an intermediate category called Object Categories like Supplies and Salaries. I had them defined so they were related to Object using the skos:broader property just like the individual items like Object 51010 for Administrator Salaries. The effect of this was that when the Budget Viewer application grouped by Object, the total was doubled. I fixed this by defining an Object Category directly under Account Classification and then each individual item is related by skos:broader to both Object and a specific Object Category. A bit confusing, I know, but this is the kind of things I am finding.

This week I added a feature to Budget Viewer so you can double click on a line in the table or a wedge of the pie chart and that item is used to narrow down the accounts to those that match the category. I also added combo box controls for each category. They take up a lot of room and still don't interact quite correctly, but it is still a work in progress. Here's a recent snapshot:



In this snapshot, the Salaries Object Category and Teacher Salaries Object is selected to limit the accounts. They are then grouped by Location. I'm sure you also see what I mean about the selection taking up too much space.

Friday, February 18, 2011

It's Alive!

Thanks to Sonja Gonzalez, the IT Director at ORCSD, we have a live web site to serve the RDF data for this project. She emailed late last night that it was available and we worked through some issues today to make sure I could use it, and tonight I replaced the "Hello, World" page she used to try it out with a slightly better welcome page. Try it out!

I have to warn you that I don't have any real RDF data published yet. As I have been exploring it over the last few weeks, I realized that my simplistic versioning scheme wasn't going to work well. Originally, I proposed just appending the date to the end of each file name. Each new version of a file would get the date replaced. But, since the file name is part of the URL, and the URL is part of the identifier for the RDF resources, if I changed the file name each time I tweaked a file, I would have to edit and rename a lot of files that used the URLs to keep them current.

Further, I don't think this level of versioning is really necessary. A lot of changes can be done without requiring the file to be versioned. If new data is added without "breaking" any old data, then it doesn't need a new version. For example, if new properties are added to old resource descriptions, or new resource descriptions are added, then it doesn't need a new version. Removing data, or worse, redefining the vocabulary of the data, would need a new version. Changes that didn't warrant a new version could simply be indicated by updating the last modified property of the file.

Before I publish any RDF data on the new web site, I want to make sure I get this versioning correct and also make sure my queries work when using data from the web site instead of files on my computer. My goal is to have the first RDF files ready later this weekend. Stay tuned!

Wednesday, February 16, 2011

Exploded Pie

I played a bit more with jFreeChart and my budget viewer application today. I interconnected the spreadsheet, pie chart and properties panels. When the mouse is clicked over the table, then the corresponding pie section is exploded (increased in size and shifted out from the center). The properties are also updated to match the selection. Similarly, when the mouse is clicked over a pie section, that section is exploded, the table row is selected, and the properties are updated. Here's a picture with all 3 panels showing the corresponding selection and properties:

Tuesday, February 15, 2011

More Small Steps

I haven't updated in over a week, mostly because I've been very busy with other things, but there are a few little things that have happened on this project. The biggest is this last weekend I made some progress on a Java application to view budget data. I decided the application should be a window with 4 panels: 1) a top "toolbar" of controls, 2) a main "spreadsheet" table in the bottom left, 3) a smaller graph panel in the middle right and 4) a smaller "properties" panel in the bottom right. The table and graph give 2 perspectives on the same data. When you select a line in the table, details on that line are shown in the properties panel. The toolbar lets you select what level of detail or groupings are shown in the table and graph as well as filter that data. Here's a picture of the prototype:



I also explored jFreeChart a bit more. Here's a bar chart of the same locations data:



On a related note, a colleague at work emailed me a link to a PBS article on budget visualizations.

My son sent me a note that the New Hampshire state government is also starting a move toward open data. While it is not quite RDF, it is good to see some compatriots near to home.

Lastly, I got a note last week from Sonja Gonzales saying she is still working on getting a URL on the ORCSD web site for the RDF data.