Search in sources :

Example 36 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class CoincidentPointsClusterTest method testRealData.

@Test
public void testRealData() throws Exception {
    // Define projection for the test case
    TiledMap map = new TiledMap(492, 690, new AiLatLng(2.293492496, 30.538372993), 9);
    // Read data
    BufferedReader in = new BufferedReader(new InputStreamReader(GraphTest.class.getResourceAsStream("/distribscolaire-points.csv")));
    double originalSum = 0;
    List<PointValue> points = new ArrayList<PointValue>();
    while (in.ready()) {
        String line = in.readLine();
        String[] columns = line.split(",");
        double lat = Double.parseDouble(columns[0]);
        double lng = Double.parseDouble(columns[1]);
        PointValue pv = new PointValue();
        pv.setPx(map.fromLatLngToPixel(new AiLatLng(lat, lng)));
        pv.setValue(Double.parseDouble(columns[2]));
        pv.setSymbol(new MapSymbol());
        pv.setSite(new SiteDTO());
        originalSum += pv.getValue();
        points.add(pv);
    }
    // Now build the graph
    MarkerGraph graph = new MarkerGraph(points, new BubbleIntersectionCalculator(15));
    // make sure nothing was lost in the merging of coincident points
    double nodeSum = 0;
    for (MarkerGraph.Node node : graph.getNodes()) {
        nodeSum += node.getPointValue().getValue();
    }
    Assert.assertEquals("values after construction of graph", originalSum, nodeSum, 0.001);
    saveGraphImage("clusterTest2", graph, 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.001);
    Assert.assertEquals(15, clusters.size());
    saveClusters(graph, "clusterTest-solution", clusters);
}
Also used : InputStreamReader(java.io.InputStreamReader) MarkerGraph(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph) PointValue(org.activityinfo.shared.report.model.PointValue) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) MapSymbol(org.activityinfo.shared.report.model.MapSymbol) GeneticSolver(org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver) BufferedReader(java.io.BufferedReader) BubbleFitnessFunctor(org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Test(org.junit.Test)

Example 37 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class PiechartMapLayerGeneratorTest method testSomething.

@Test
public void testSomething() {
    SiteDTO siteData = new SiteDTO();
    siteData.setId(42);
    siteData.setX(15.0);
    siteData.setY(0.0);
    siteData.setIndicatorValue(1, 50.0);
    siteData.setIndicatorValue(2, 10.0);
    siteData.setIndicatorValue(3, 20.0);
    siteData.setIndicatorValue(4, 40.0);
    PiechartMapLayer pcml = new PiechartMapLayer();
    pcml.setMinRadius(10);
    pcml.setMaxRadius(50);
    pcml.addIndicatorId(1);
    pcml.addIndicatorId(2);
    pcml.addIndicatorId(3);
    pcml.addIndicatorId(4);
    pcml.setClustering(new NoClustering());
    TiledMap map = new TiledMap(500, 600, new AiLatLng(15.0, 0.0), 6);
    Map<Integer, Indicator> indicators = Maps.newHashMap();
    indicators.put(1, new Indicator());
    indicators.put(2, new Indicator());
    indicators.put(3, new Indicator());
    indicators.put(4, new Indicator());
    PiechartLayerGenerator gen = new PiechartLayerGenerator(pcml, indicators);
    gen.setSites(Arrays.asList(siteData));
    MapContent mc = new MapContent();
    gen.generate(map, mc);
    assertThat(mc.getMarkers().size(), equalTo(1));
    assertThat(((PieMapMarker) mc.getMarkers().get(0)).getSlices().size(), equalTo(4));
}
Also used : MapContent(org.activityinfo.shared.report.content.MapContent) NoClustering(org.activityinfo.shared.report.model.clustering.NoClustering) PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) SiteDTO(org.activityinfo.shared.dto.SiteDTO) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) Test(org.junit.Test)

Example 38 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class ColumnModelBuilder method addActivityColumn.

public ColumnModelBuilder addActivityColumn(final SchemaDTO schema) {
    ColumnConfig config = new ColumnConfig("activityId", I18N.CONSTANTS.activity(), 100);
    config.setRenderer(new GridCellRenderer<SiteDTO>() {

        @Override
        public Object render(SiteDTO model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<SiteDTO> store, Grid<SiteDTO> grid) {
            ActivityDTO activity = schema.getActivityById(model.getActivityId());
            return activity == null ? "" : activity.getName();
        }
    });
    columns.add(config);
    return this;
}
Also used : ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) SiteDTO(org.activityinfo.shared.dto.SiteDTO) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Example 39 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class LockedColumnRenderer method render.

@Override
public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore listStore, Grid grid) {
    if (model instanceof SiteDTO) {
        SiteDTO siteModel = (SiteDTO) model;
        StringBuilder builder = new StringBuilder();
        if (siteModel.isLinked()) {
            return IconImageBundle.ICONS.link().getHTML();
        } else if (lockSet.isLocked(siteModel)) {
            // String tooltip = buildTooltip(model, activity);
            // builder.append("<span qtip='");
            // builder.append(tooltip);
            // builder.append("'>");
            builder.append(IconImageBundle.ICONS.lockedPeriod().getHTML());
            // builder.append("</span>");
            return builder.toString();
        }
    }
    return "";
}
Also used : SiteDTO(org.activityinfo.shared.dto.SiteDTO)

Example 40 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class SiteDialog method saveNewSite.

private void saveNewSite() {
    final SiteDTO newSite = new SiteDTO();
    newSite.setId(new KeyGenerator().generateInt());
    newSite.setActivityId(activity.getId());
    if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
        newSite.setReportingPeriodId(new KeyGenerator().generateInt());
    }
    updateModel(newSite);
    dispatcher.execute(new CreateSite(newSite), new AsyncCallback<CreateResult>() {

        @Override
        public void onFailure(Throwable caught) {
            showError(caught);
        }

        @Override
        public void onSuccess(CreateResult result) {
            hide();
            callback.onSaved(newSite);
        }
    });
}
Also used : CreateResult(org.activityinfo.shared.command.result.CreateResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) CreateSite(org.activityinfo.shared.command.CreateSite)

Aggregations

SiteDTO (org.activityinfo.shared.dto.SiteDTO)71 Test (org.junit.Test)32 GetSites (org.activityinfo.shared.command.GetSites)16 SiteResult (org.activityinfo.shared.command.result.SiteResult)11 CreateSite (org.activityinfo.shared.command.CreateSite)9 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)8 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)7 ArrayList (java.util.ArrayList)7 CreateResult (org.activityinfo.shared.command.result.CreateResult)7 Date (java.util.Date)6 OnDataSet (org.activityinfo.server.database.OnDataSet)6 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)6 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)6 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)5 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)5 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)5 UpdateSite (org.activityinfo.shared.command.UpdateSite)5 LocationDTO (org.activityinfo.shared.dto.LocationDTO)5 PointValue (org.activityinfo.shared.report.model.PointValue)5 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)4