Thursday, December 20, 2007

Analysis with Groovy and AIDA






Groovy SQLGroovy with AIDA makes very good environment for analysis of data in SQL database. User can easily access all data, perform analysis code and plot histograms. What is needed:

  1. Groovy language

  2. Java implementation of AIDA: JAIDA , all its jar-files should be put into your CLASSPATH

  3. Data is SQL database and corresponding JDBC driver (MySQL is used in following example)




// create AIDA histogram from SQL
// ==============================

// This is pure AIDA code
// ----------------------
// Create all needed factories
af = IAnalysisFactory.create()
tree = af.createTreeFactory().create()
hf = af.createHistogramFactory(tree)
// Create your histogram here
histo = hf.createHistogram1D("histo", 50, 0, 1)

// This is pure Groovy code
// ------------------------
// Get driver to your SQL database
sqlDriver = Sql.newInstance("jdbc:mysql://localhost/Tuples",
"test",
"test",
"org.gjt.mm.mysql.Driver")
// Loop over table rows and accumulate histogram
sqlDriver.eachRow("select mycolumn from mytuple") {
histo.fill(it.mycolumn)
}

// This is pure AIDA code
// ----------------------
// Show your histogram in new window
plotter = af.createPlotterFactory().create("SQL Plot")
plotter.createRegions(1, 1, 0)
plotter.region(0).plot(histo)
plotter.show()

Note that you can use any Java library from your Groovy code (you can use ant Groovy library from your Java code too).

No comments:

Post a Comment