Search in sources :

Example 11 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue in project activityinfo by bedatadriven.

the class PiechartLayerGenerator method generate.

@Override
public void generate(TiledMap map, MapContent content) {
    // create the list of input point values
    List<PointValue> points = new ArrayList<PointValue>();
    List<PointValue> unmapped = new ArrayList<PointValue>();
    // define our symbol scaling
    RadiiCalculator radiiCalculator;
    if (layer.getScaling() == ScalingType.None || layer.getMinRadius() == layer.getMaxRadius()) {
        radiiCalculator = new FixedRadiiCalculator(layer.getMinRadius());
    } else if (layer.getScaling() == ScalingType.Graduated) {
        radiiCalculator = new GsLogCalculator(layer.getMinRadius(), layer.getMaxRadius());
    } else {
        radiiCalculator = new FixedRadiiCalculator(layer.getMinRadius());
    }
    Clusterer clusterer = ClustererFactory.fromClustering(layer.getClustering(), radiiCalculator, new BubbleIntersectionCalculator(layer.getMaxRadius()));
    generatePoints(map, layer, clusterer, points, unmapped);
    // add unmapped sites
    for (PointValue pv : unmapped) {
        content.getUnmappedSites().add(pv.getSite().getId());
    }
    List<Cluster> clusters = clusterer.cluster(map, points);
    // create the markers
    List<BubbleMapMarker> markers = new ArrayList<BubbleMapMarker>();
    for (Cluster cluster : clusters) {
        Point px = cluster.getPoint();
        AiLatLng latlng = map.fromPixelToLatLng(px);
        BubbleMapMarker marker = new PieMapMarker();
        sumSlices((PieMapMarker) marker, cluster.getPointValues());
        for (PointValue pv : cluster.getPointValues()) {
            marker.getSiteIds().add(pv.getSite().getId());
        }
        marker.setX(px.getX());
        marker.setY(px.getY());
        marker.setValue(cluster.sumValues());
        marker.setRadius((int) cluster.getRadius());
        marker.setLat(latlng.getLat());
        marker.setLng(latlng.getLng());
        marker.setAlpha(layer.getAlpha());
        marker.setIndicatorIds(new HashSet<Integer>(layer.getIndicatorIds()));
        marker.setClusterAmount(cluster.getPointValues().size());
        marker.setClustering(layer.getClustering());
        markers.add(marker);
    }
    // number markers if applicable
    if (layer.getLabelSequence() != null) {
        numberMarkers(markers);
    }
    PieChartLegend legend = new PieChartLegend();
    legend.setDefinition(layer);
    content.getMarkers().addAll(markers);
    content.addLegend(legend);
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) Clusterer(org.activityinfo.server.report.generator.map.cluster.Clusterer) AiLatLng(org.activityinfo.model.type.geo.AiLatLng)

Example 12 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue in project activityinfo by bedatadriven.

the class AdminLevelClusterer method updateCenter.

private void updateCenter(Cluster cluster) {
    double count = 0;
    double sumX = 0;
    double sumY = 0;
    for (PointValue pv : cluster.getPointValues()) {
        if (pv.hasPoint()) {
            count++;
            sumX += pv.getPoint().getDoubleX();
            sumY += pv.getPoint().getDoubleY();
        }
    }
    if (count > 0) {
        cluster.setPoint(new Point(sumX / count, sumY / count));
    }
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) Point(org.activityinfo.legacy.shared.reports.content.Point)

Example 13 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue in project activityinfo by bedatadriven.

the class CoincidentPointsClusterTest method testSimpleData.

@Test
public void testSimpleData() throws Exception {
    List<PointValue> points = new ArrayList<PointValue>();
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 7.0, new Point(0, 0)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 2.0, new Point(0, 0)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 41.0, new Point(100, 100)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 9.0, new Point(0, 0)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 39.0, new Point(100, 100)));
    double originalSum = 7 + 2 + 9 + 41 + 39;
    // Now build the graph
    MarkerGraph graph = new MarkerGraph(points, new BubbleIntersectionCalculator(15));
    GeneticSolver solver = new GeneticSolver();
    List<Cluster> clusters = solver.solve(graph, new GsLogCalculator(5, 15), new BubbleFitnessFunctor(), UpperBoundsCalculator.calculate(graph, new FixedRadiiCalculator(5)));
    // check to make sure all values were included
    double sumAfterClustering = 0;
    for (Cluster cluster : clusters) {
        sumAfterClustering += cluster.sumValues();
    }
    Assert.assertEquals(originalSum, sumAfterClustering, 0.0001);
    Assert.assertEquals(2, clusters.size());
    saveClusters(graph, "clusterTest-solution", clusters);
}
Also used : MarkerGraph(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph) PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) MapSymbol(org.activityinfo.legacy.shared.reports.model.MapSymbol) Point(org.activityinfo.legacy.shared.reports.content.Point) GeneticSolver(org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver) BubbleFitnessFunctor(org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Test(org.junit.Test)

Example 14 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue in project activityinfo by bedatadriven.

the class GraphTest method testGraph.

@Test
public void testGraph() throws Exception {
    List<PointValue> points = new ArrayList<PointValue>();
    points.add(new PointValue(null, null, 100, new Point(380, 530)));
    points.add(new PointValue(null, null, 200, new Point(500, 500)));
    points.add(new PointValue(null, null, 50, new Point(650, 550)));
    points.add(new PointValue(null, null, 300, new Point(600, 600)));
    points.add(new PointValue(null, null, 200, new Point(650, 650)));
    points.add(new PointValue(null, null, 30, new Point(500, 1300)));
    points.add(new PointValue(null, null, 150, new Point(200, 200)));
    points.add(new PointValue(null, null, 200, new Point(350, 200)));
    points.add(new PointValue(null, null, 150, new Point(500, 200)));
    points.add(new PointValue(null, null, 30, new Point(700, 200)));
// MarkerGraph graph = new MarkerGraph(points, new
// GraduatedLogCalculator(50, 100), 100);
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) ArrayList(java.util.ArrayList) Point(org.activityinfo.legacy.shared.reports.content.Point) Test(org.junit.Test)

Example 15 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue in project activityinfo by bedatadriven.

the class GraphTest method saveClusters.

protected void saveClusters(MarkerGraph graph, String fileName, List<Cluster> clusters) throws IOException {
    File outputDir = new File("build/report-tests");
    outputDir.mkdirs();
    File outputFile = new File("build/report-tests/" + fileName + ".svg");
    FileWriter svg = new FileWriter(outputFile);
    svg.write("<svg width='100%' height='100%' transform='scale(500)' version='1.1'  " + "xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' >\n");
    for (MarkerGraph.Edge edge : graph.getEdges()) {
        svg.write(String.format("<path d='M%d %d L%d %d' " + "style='stroke:rgb(92,92,92);stroke-width:0.25'/>\n", edge.getA().getPoint().getX(), edge.getA().getPoint().getY(), edge.getB().getPoint().getX(), edge.getB().getPoint().getY()));
    }
    String[] colors = new String[] { "antiquewhite", "blue", "brown", "chartreuse", "cornflowerblue", "crimson", "darkkhaki", "darkorange", "darkorchid", "lightpink", "lightseagreen", "lightskyblue", "lime", "limegreen", "magenta", "mediumaqua" };
    int colorIndex = 0;
    for (int i = 0; i != clusters.size(); ++i) {
        Cluster cluster = clusters.get(i);
        svg.write(String.format("<circle cx='%d' cy='%d' r='%f' " + "style='fill: %s; fill-opacity: 0.5; stroke:none'/>\n", cluster.getPoint().getX(), cluster.getPoint().getY(), cluster.getRadius(), colors[colorIndex]));
        for (PointValue pointValue : cluster.getPointValues()) {
            svg.write(String.format("<circle cx='%d' cy='%d' r='1.5' " + "style='stroke:rgb(92,92,92); stroke-width:0.1; fill: %s' title='%f'/>\n", pointValue.getPx().getX(), pointValue.getPx().getY(), colors[colorIndex], pointValue.getValue()));
        }
        colorIndex++;
        if (colorIndex == colors.length) {
            colorIndex = 0;
        }
    }
    // label subgraphs
    List<List<MarkerGraph.Node>> subgraphs = graph.getSubgraphs();
    for (int i = 0; i != subgraphs.size(); ++i) {
        Point p = findLR(subgraphs.get(i));
        svg.write(String.format("<text x='%d' y='%d'>%d</text>\n", p.getX() + 5, p.getY(), i));
    }
    svg.write("</svg>\n");
    svg.close();
}
Also used : MarkerGraph(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph) PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) FileWriter(java.io.FileWriter) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) List(java.util.List) ArrayList(java.util.ArrayList) Point(org.activityinfo.legacy.shared.reports.content.Point) File(java.io.File) Point(org.activityinfo.legacy.shared.reports.content.Point)

Aggregations

PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)15 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)7 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)7 ArrayList (java.util.ArrayList)6 Point (org.activityinfo.legacy.shared.reports.content.Point)6 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)5 MapSymbol (org.activityinfo.legacy.shared.reports.model.MapSymbol)3 Clusterer (org.activityinfo.server.report.generator.map.cluster.Clusterer)3 MarkerGraph (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph)3 Test (org.junit.Test)3 BubbleFitnessFunctor (org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor)2 GeneticSolver (org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AdminEntityDTO (org.activityinfo.legacy.shared.model.AdminEntityDTO)1 IconLayerLegend (org.activityinfo.legacy.shared.reports.content.IconLayerLegend)1