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);
}
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));
}
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;
}
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 "";
}
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);
}
});
}
Aggregations