package org.jzy3d.analysis.table;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import org.jzy3d.chart.BigPicture;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.Type;
import org.jzy3d.colors.Color;
import org.jzy3d.demos.drawing.vbo.barmodel.builder.VBOBuilderLineStrip;
import org.jzy3d.demos.drawing.vbo.barmodel.builder.VBOBuilderTableColumnsScatter3d;
import org.jzy3d.io.KeyVal;
import org.jzy3d.maths.Histogram;
import org.jzy3d.maths.Statistics;
import org.jzy3d.plot2d.primitives.Histogram2d;
import org.jzy3d.plot3d.primitives.vbo.drawable.DrawableVBO;
import com.google.common.collect.ArrayListMultimap;
/**
* Given a Table scan scheduler, will build all charts for an analysis and dump
* pictures to disk.
*
* @author martin
*/
public class TableAnalysis {
protected DefaultTableScanScheduler scheduler;
protected boolean black = false;
public TableAnalysis(DefaultTableScanScheduler scheduler) {
this.scheduler = scheduler;
}
/* REPORTING */
/**
* Delete input directory and generate all charts as file.
*
* @throws IOException
*/
public void report(File output) throws IOException {
if (output.exists()) {
output.delete();
}
output.mkdirs();
List>> table = scheduler.getTable();
int imgWidth = 600;
int imgHeight = 600;
StringBuffer html = new StringBuffer();
if (black)
html.append("");
else
html.append("");
// Overview chart
reportOverview(output, table, html, imgWidth, imgHeight);
// Column charts
ArrayListMultimap columns = scheduler.computeColumns();
for (String columnName : columns.keySet()) {
List values = columns.get(columnName);
System.out.println("ADDING COL : " + columnName);
reportColumn(output, columnName, values, html, imgWidth, imgHeight);
}
html.append("
");
writeToFile(new File(output, "0-all.html"), html);
}
private void reportOverview(File output, List>> table, StringBuffer html, int width, int height) throws IOException {
String imageName = "0-overview.png";
File fileOverview = new File(output, imageName);
DrawableVBO drawable = new DrawableVBO(new VBOBuilderTableColumnsScatter3d(table));
offscreen2d(width, height, fileOverview, drawable);
html.append("\n");
html.append("Table Overview
\n");
html.append("
\n");
html.append(" \n");
}
private void reportColumn(File output, String columnName, List values, StringBuffer html, int width, int height) throws IOException {
html.append("Column : " + columnName + "
\n");
html.append(" \n");
html.append("Values
\n");
try {
reportLineChart(output, columnName, values, html, width, height);
} catch (Exception e) {
html.append("" + org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e) + "
\n");
}
html.append(" \n");
html.append("Density
\n");
try {
reportBarChart(output, columnName, values, html, width, height);
} catch (Exception e) {
html.append("" + org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e) + "
\n");
}
html.append(" \n");
}
private void reportLineChart(File output, String columnName, List values, StringBuffer html, int width, int height) throws IOException {
String imageName = "1-column-" + columnName + "-values.png";
File fileLines = new File(output, imageName);
DrawableVBO drawableLine = new DrawableVBO(new VBOBuilderLineStrip(values));
offscreen2d(width, height, fileLines, drawableLine);
html.append("
\n");
}
private void reportBarChart(File output, String columnName, List values, StringBuffer html, int width, int height) throws IOException {
String imageName = "1-column-" + columnName + "-density.png";
File fileBarChart = new File(output, imageName);
float min = Statistics.min(values);
float max = Statistics.max(values);
Histogram hist = new Histogram(min, max, 20);
hist.add(values);
Histogram2d histogram = new Histogram2d(hist);
if (black)
histogram.getDrawable().setWireframeColor(Color.WHITE);
else
histogram.getDrawable().setWireframeColor(Color.BLACK);
Chart chart = BigPicture.offscreen(histogram.getDrawable(), Type.dd, width, height).view2d();
if (black)
chart.black();
histogram.layout(chart);
chart.screenshot(fileBarChart);
html.append("
\n");
}
private void offscreen2d(int width, int height, File file, DrawableVBO drawable) throws IOException {
Chart chart = BigPicture.offscreen(drawable, Type.dd, width, height);
if (black)
chart.black();
chart.screenshot(file);
}
/* */
/** dump html index */
public void writeToFile(File file, StringBuffer text) throws IOException {
BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.write(text.toString());
out.flush();
out.close();
}
public DefaultTableScanScheduler getScheduler() {
return scheduler;
}
public void setScheduler(DefaultTableScanScheduler scheduler) {
this.scheduler = scheduler;
}
}
Ads help maintain this website.