Search in sources :

Example 1 with HistogramChartGenerator

use of ambit2.db.chart.HistogramChartGenerator in project ambit-mirror by ideaconsult.

the class ChartResource method createImage.

protected BufferedImage createImage() throws ResourceException {
    BufferedImage image = null;
    Connection connection = null;
    try {
        DBConnection dbc = new DBConnection(getContext());
        connection = dbc.getConnection();
        ambit2.base.data.Template profile = new ambit2.base.data.Template();
        ProfileReader reader = new ProfileReader(getRequest().getRootRef(), profile, getApplication().getContext(), getToken(), getRequest().getCookies(), getRequest().getClientInfo() == null ? null : getRequest().getClientInfo().getAgent(), getRequest().getResourceRef().toString());
        reader.setCloseConnection(false);
        reader.setConnection(connection);
        for (String p : property) reader.process(new Reference(p));
        switch(mode) {
            case pie:
                {
                    Iterator<Property> i = profile.getProperties(true);
                    while (i.hasNext()) {
                        PieChartGenerator<ISourceDataset> chart = new PieChartGenerator<ISourceDataset>();
                        chart.setProperty(i.next());
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        image = chart.process(dataset);
                        // ChartUtilities.writeImageMap(writer, name, info, useOverLibForToolTips)
                        break;
                    }
                    break;
                }
            case histogram:
                {
                    Iterator<Property> i = profile.getProperties(true);
                    while (i.hasNext()) {
                        HistogramChartGenerator chart = new HistogramChartGenerator();
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        chart.setMinX(minX);
                        chart.setMaxX(maxX);
                        chart.setPropertyX(i.next());
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        image = chart.process(dataset);
                        // ChartUtilities.writeImageMap(writer, name, info, useOverLibForToolTips)
                        break;
                    }
                    break;
                }
            case xy:
                {
                    Property[] p = new Property[2];
                    int i = 0;
                    Iterator<Property> it = profile.getProperties(true);
                    while (it.hasNext()) {
                        p[i] = it.next();
                        i++;
                        if (i >= 2)
                            break;
                    }
                    PropertiesChartGenerator chart = new PropertiesChartGenerator();
                    chart.setLogX(logX);
                    chart.setLogY(logY);
                    chart.setThumbnail(thumbnail);
                    chart.setPropertyX(p[0]);
                    chart.setPropertyY(p.length < 2 ? p[0] : p[1]);
                    chart.setConnection(connection);
                    chart.setWidth(w);
                    chart.setHeight(h);
                    chart.setLegend(legend);
                    image = chart.process(dataset);
                    break;
                }
            case bar:
                {
                    Property[] p = new Property[2];
                    int i = 0;
                    Iterator<Property> it = profile.getProperties(true);
                    while (it.hasNext()) {
                        p[i] = it.next();
                        i++;
                        if (i >= 2)
                            break;
                    }
                    if (i == 0) {
                        FingerprintHistogramDataset chart = new FingerprintHistogramDataset();
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setParam(param);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        image = chart.process(dataset);
                    } else {
                        BarChartGeneratorDataset chart = new BarChartGeneratorDataset();
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        chart.setPropertyX(p[0]);
                        chart.setPropertyY(p.length < 2 ? p[0] : p[1]);
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        image = chart.process(dataset);
                    }
                    break;
                }
            default:
                {
                    image = null;
                }
        }
    } catch (Exception x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
    } finally {
        try {
            connection.close();
        } catch (Exception x) {
        }
    }
    if (image == null)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
    return image;
}
Also used : DBConnection(ambit2.rest.DBConnection) ProfileReader(ambit2.rest.property.ProfileReader) Reference(org.restlet.data.Reference) Connection(java.sql.Connection) DBConnection(ambit2.rest.DBConnection) BufferedImage(java.awt.image.BufferedImage) ResourceException(org.restlet.resource.ResourceException) IOException(java.io.IOException) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) Template(org.restlet.routing.Template) PropertiesChartGenerator(ambit2.db.chart.PropertiesChartGenerator) ISourceDataset(ambit2.base.data.ISourceDataset) BarChartGeneratorDataset(ambit2.db.chart.BarChartGeneratorDataset) Iterator(java.util.Iterator) PieChartGenerator(ambit2.db.chart.PieChartGenerator) ResourceException(org.restlet.resource.ResourceException) HistogramChartGenerator(ambit2.db.chart.HistogramChartGenerator) FingerprintHistogramDataset(ambit2.db.chart.FingerprintHistogramDataset)

Example 2 with HistogramChartGenerator

use of ambit2.db.chart.HistogramChartGenerator in project ambit-mirror by ideaconsult.

the class PieChartGeneratorTest method testMetricPlot.

/*
	public Image testPropertyHistogramPlot() {
		Connection c = null;
		try {
			initDatasource();
			c = datasource.getConnection();
			IStoredQuery q = new StoredQuery(6);//this is dataset now
			q.setName("Skin sensitisation (LLNA)");
			HistogramChartGenerator gen = new HistogramChartGenerator();
			gen.setBinWidth(0.1);
			gen.setConnection(c);
			gen.setPropertyX(Property.getInstance("LLNA EC3 %", ""));
			
			//gen.setPropertyY(Property.getInstance("Cramer Class", ""));
			gen.setPropertyY(Property.getInstance("Reaction domain (verbose)", ""));
			
			
			return gen.process(q);

		} catch (Exception x) {
			x.printStackTrace();
			return null;
		} finally {
			try {c.close(); } catch (Exception x) {}
		}
	}	
	*/
/*
	public Image testPropertyHistogramPlot() {
		Connection c = null;
		try {
			initDatasource();
			c = datasource.getConnection();
			IStoredQuery q = new StoredQuery(9);//this is dataset now
			q.setName("CPDBAS: Carcinogenic Potency Database Summary Tables - All Species");
			HistogramChartGenerator gen = new HistogramChartGenerator();
			gen.setBinWidth(10);
			gen.setConnection(c);
			gen.setPropertyX(Property.getInstance("TD50_Mouse_mg", ""));
			
			//gen.setPropertyY(Property.getInstance("Cramer Class", ""));
			gen.setPropertyY(Property.getInstance("toxTree.tree.cramer.CramerRules", ""));
			
			
			return gen.process(q);

		} catch (Exception x) {
			x.printStackTrace();
			return null;
		} finally {
			try {c.close(); } catch (Exception x) {}
		}
	}	
	*/
/*
	public Image testPropertyHistogramPlot() {
		Connection c = null;
		try {
			initDatasource();
			c = datasource.getConnection();
			IStoredQuery q = new StoredQuery(1);//this is dataset now
			q.setName("Munro dataset");
			HistogramChartGenerator gen = new HistogramChartGenerator();
			gen.setBinWidth(0.15);
			gen.setConnection(c);
			gen.setPropertyX(Property.getInstance("NOEL", ""));
			
			//gen.setPropertyY(Property.getInstance("Cramer Class", ""));
			gen.setPropertyY(Property.getInstance("toxTree.tree.cramer.CramerRules", ""));
			
			
			return gen.process(q);

		} catch (Exception x) {
			x.printStackTrace();
			return null;
		} finally {
			try {c.close(); } catch (Exception x) {}
		}
	}	
	*/
public Image testMetricPlot() {
    Connection c = null;
    try {
        initDatasource();
        c = datasource.getConnection();
        IStoredQuery q = new StoredQuery(2);
        Numeric2SimilarityChartGenerator gen = new Numeric2SimilarityChartGenerator();
        gen.setConnection(c);
        gen.setProperty(Property.getInstance("XLogP", ""));
        return gen.process(q);
    } catch (Exception x) {
        x.printStackTrace();
        return null;
    } finally {
        try {
            c.close();
        } catch (Exception x) {
        }
    }
}
Also used : IStoredQuery(ambit2.db.search.IStoredQuery) StoredQuery(ambit2.db.search.StoredQuery) IStoredQuery(ambit2.db.search.IStoredQuery) Numeric2SimilarityChartGenerator(ambit2.db.chart.Numeric2SimilarityChartGenerator) Connection(java.sql.Connection)

Aggregations

Connection (java.sql.Connection)2 ISourceDataset (ambit2.base.data.ISourceDataset)1 BarChartGeneratorDataset (ambit2.db.chart.BarChartGeneratorDataset)1 FingerprintHistogramDataset (ambit2.db.chart.FingerprintHistogramDataset)1 HistogramChartGenerator (ambit2.db.chart.HistogramChartGenerator)1 Numeric2SimilarityChartGenerator (ambit2.db.chart.Numeric2SimilarityChartGenerator)1 PieChartGenerator (ambit2.db.chart.PieChartGenerator)1 PropertiesChartGenerator (ambit2.db.chart.PropertiesChartGenerator)1 IStoredQuery (ambit2.db.search.IStoredQuery)1 StoredQuery (ambit2.db.search.StoredQuery)1 DBConnection (ambit2.rest.DBConnection)1 InvalidResourceIDException (ambit2.rest.error.InvalidResourceIDException)1 ProfileReader (ambit2.rest.property.ProfileReader)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 Reference (org.restlet.data.Reference)1 ResourceException (org.restlet.resource.ResourceException)1 Template (org.restlet.routing.Template)1