use of org.activityinfo.legacy.shared.model.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.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class CalculatedIndicatorsQuery method aggregateSites.
private void aggregateSites(SiteResult result) {
for (int i = 0; i != result.getTotalLength(); ++i) {
SiteDTO site = result.getData().get(i);
// Now loop over each value
for (EntityCategory indicator : indicatorMap.values()) {
Double value = site.getIndicatorDoubleValue(indicator.getId());
if (value != null && !Double.isNaN(value) && !Double.isInfinite(value)) {
Bucket bucket = new Bucket(value);
bucket.setAggregationMethod(indicatorAggregationMap.get(indicator.getId()));
bucket.setCategory(new Dimension(DimensionType.Target), TargetCategory.REALIZED);
if (query.isPivotedBy(DimensionType.Indicator)) {
bucket.setCategory(new Dimension(DimensionType.Indicator), indicator);
}
for (int j = 0; j != dimAccessors.size(); ++j) {
bucket.setCategory(dimAccessors.get(j).getDimension(), dimAccessors.get(j).getCategory(site));
}
queryContext.addBucket(bucket);
}
}
}
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class ImportWithMultiClassRangeTest method testSimple.
@Test
public void testSimple() throws IOException {
setUser(3);
FormTree formTree = assertResolves(locator.getFormTree(NFI_DISTRIBUTION_FORM_CLASS));
FormTreePrettyPrinter.print(formTree);
importModel = new ImportModel(formTree);
importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
// Step 1: User pastes in data to import
PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "nfi.csv"), Charsets.UTF_8));
source.parseAllRows();
importModel.setSource(source);
dumpList("COLUMNS", source.getColumns());
importModel.setColumnAction(columnIndex("Date1"), target("Start Date"));
importModel.setColumnAction(columnIndex("Date2"), target("End Date"));
importModel.setColumnAction(columnIndex("Partner"), target("Partner Name"));
importModel.setColumnAction(columnIndex("Localité"), target("Localité Name"));
importModel.setColumnAction(columnIndex("Province"), target("Province Name"));
importModel.setColumnAction(columnIndex("District"), target("District Name"));
importModel.setColumnAction(columnIndex("Territoire"), target("Territoire Name"));
importModel.setColumnAction(columnIndex("Secteur"), target("Secteur Name"));
importModel.setColumnAction(columnIndex("Groupement"), target("Groupement Name"));
importModel.setColumnAction(columnIndex("Zone de Santé"), target("Zone de Santé Name"));
importModel.setColumnAction(columnIndex("Nombre de ménages ayant reçu une assistance en NFI"), target("Nombre de ménages ayant reçu une assistance en NFI"));
ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
showValidationGrid(validatedResult);
assertResolves(importer.persist(importModel));
GetSites query = new GetSites(Filter.filter().onActivity(33));
query.setSortInfo(new SortInfo("date2", Style.SortDir.DESC));
SiteResult result = execute(query);
// 651 - 8 = 643 (8 records where start date is before end date)
assertThat(result.getTotalLength(), equalTo(643));
// assertThat(result.getTotalLength(), equalTo(313));
SiteDTO lastSite = result.getData().get(0);
// assertThat(lastSite.getDate2(), equalTo(new LocalDate(2013,4,26)));
assertThat(lastSite.getDate2(), equalTo(new LocalDate(2013, 4, 30)));
assertThat(lastSite.getLocationName(), equalTo("Kilimani Camp"));
assertThat(lastSite.getAdminEntity(PROVINCE_LEVEL).getName(), equalTo("Nord Kivu"));
assertThat(lastSite.getAdminEntity(DISTRICT_LEVEL).getName(), equalTo("Nord Kivu"));
assertThat(lastSite.getAdminEntity(TERRITOIRE_LEVEL).getName(), equalTo("Masisi"));
assertThat(lastSite.getAdminEntity(SECTEUR_LEVEL).getName(), equalTo("Masisi"));
assertThat((Double) lastSite.getIndicatorValue(NUMBER_MENAGES), equalTo(348.0));
assertThat(lastSite.getAttributeValue(ECHO), equalTo(false));
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class SiteRendererTest method multipleGroupsRender.
@Test
public void multipleGroupsRender() {
IndicatorDTO indicator1 = new IndicatorDTO();
indicator1.setId(1);
indicator1.setAggregation(IndicatorDTO.AGGREGATE_SUM);
indicator1.setName("First indicator");
indicator1.setCategory("First group");
IndicatorDTO indicator2 = new IndicatorDTO();
indicator2.setAggregation(IndicatorDTO.AGGREGATE_SUM);
indicator2.setId(2);
indicator2.setName("Second indicator");
indicator2.setCategory("Second group");
IndicatorDTO indicator3 = new IndicatorDTO();
indicator3.setAggregation(IndicatorDTO.AGGREGATE_SUM);
indicator3.setType(FieldTypeClass.NARRATIVE);
indicator3.setId(3);
indicator3.setName("Third indicator");
indicator3.setCategory("Second group");
ActivityFormDTO activity = new ActivityFormDTO();
activity.setId(1);
activity.getIndicators().add(indicator1);
activity.getIndicators().add(indicator2);
activity.getIndicators().add(indicator3);
SiteDTO site = new SiteDTO();
site.setIndicatorValue(1, 1000d);
site.setIndicatorValue(2, 2000d);
site.setIndicatorValue(3, "Some help but not a huge amount.\nHowever there was " + "some other information that I'd like to present in " + "second paragraph.");
String html = siteRenderer.renderSite(site, activity, true);
System.out.println(html);
assertTrue(html.contains(indicator1.getName()));
assertTrue(html.contains(indicator2.getName()));
assertTrue(html.contains(indicator3.getName()));
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class SiteDialog method updateSite.
private void updateSite() {
final SiteDTO updated = new SiteDTO(site);
updateModel(updated);
dispatcher.execute(new UpdateSite(site, updated), new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
showError(caught);
}
@Override
public void onSuccess(VoidResult result) {
hide();
callback.onSaved();
}
});
}
Aggregations