Search in sources :

Example 11 with Partitions

use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.

the class PartitionUtilsTest method getGetPartitionsLongPeriodsPrune.

@Test
public void getGetPartitionsLongPeriodsPrune() {
    Period period = new Period();
    period.setStartDate(new DateTime(2008, 3, 1, 0, 0).toDate());
    period.setEndDate(new DateTime(2011, 7, 1, 0, 0).toDate());
    Partitions expected = new Partitions().add(TBL + "_2008").add(TBL + "_2009").add(TBL + "_2010").add(TBL + "_2011");
    assertEquals(expected, PartitionUtils.getPartitions(period, TBL, null, null));
    Set<String> validPartitions = new HashSet<>();
    validPartitions.add(TBL + "_2008");
    validPartitions.add(TBL + "_2010");
    expected = new Partitions().add(TBL + "_2008").add(TBL + "_2010");
    assertEquals(expected, PartitionUtils.getPartitions(period, TBL, null, validPartitions));
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions) DhisConvenienceTest.createPeriod(org.hisp.dhis.DhisConvenienceTest.createPeriod) Period(org.hisp.dhis.period.Period) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with Partitions

use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.

the class PartitionUtilsTest method testGetTablePeriodMapA.

@Test
public void testGetTablePeriodMapA() {
    ListMap<Partitions, DimensionalItemObject> map = PartitionUtils.getPartitionPeriodMap(getList(createPeriod("2000S1"), createPeriod("2000S2"), createPeriod("2001S1"), createPeriod("2001S2"), createPeriod("2002S1")), TBL, null, null);
    assertEquals(3, map.size());
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2001")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2002")));
    assertEquals(2, map.get(new Partitions().add(TBL + "_2000")).size());
    assertEquals(2, map.get(new Partitions().add(TBL + "_2001")).size());
    assertEquals(1, map.get(new Partitions().add(TBL + "_2002")).size());
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Test(org.junit.Test)

Example 13 with Partitions

use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.

the class PartitionUtilsTest method testGetTablePeriodMapB.

@Test
public void testGetTablePeriodMapB() {
    ListMap<Partitions, DimensionalItemObject> map = PartitionUtils.getPartitionPeriodMap(getList(createPeriod("2000April"), createPeriod("2000"), createPeriod("2001"), createPeriod("2001Oct"), createPeriod("2002Oct")), TBL, null, null);
    assertEquals(5, map.size());
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2001")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000").add(TBL + "_2001")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2001").add(TBL + "_2002")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2002").add(TBL + "_2003")));
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Test(org.junit.Test)

Example 14 with Partitions

use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.

the class EventQueryPlannerTest method testPlanAggregateQueryB.

@Test
public void testPlanAggregateQueryB() {
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 3, 1, 0, 0).toDate()).withEndDate(new DateTime(2010, 9, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouA)).build();
    List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
    assertEquals(1, queries.size());
    EventQueryParams query = queries.get(0);
    assertEquals(new DateTime(2010, 3, 1, 0, 0).toDate(), query.getStartDate());
    assertEquals(new DateTime(2010, 9, 20, 0, 0).toDate(), query.getEndDate());
    Partitions partitions = query.getPartitions();
    assertEquals(1, partitions.getPartitions().size());
    assertEquals("analytics_event_2010_programuida", partitions.getSinglePartition());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) Partitions(org.hisp.dhis.analytics.Partitions) DateTime(org.joda.time.DateTime) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 15 with Partitions

use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.

the class PartitionUtils method getPartitions.

public static Partitions getPartitions(String tablePrefix, String tableSuffix, Set<String> validPartitions) {
    tablePrefix = StringUtils.trimToEmpty(tablePrefix);
    tableSuffix = StringUtils.trimToEmpty(tableSuffix);
    Partitions partitions = new Partitions();
    String name = tablePrefix + tableSuffix;
    partitions.add(name.toLowerCase());
    return partitions.prunePartitions(validPartitions);
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions)

Aggregations

Partitions (org.hisp.dhis.analytics.Partitions)15 Test (org.junit.Test)11 DateTime (org.joda.time.DateTime)6 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)4 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 DhisConvenienceTest.createPeriod (org.hisp.dhis.DhisConvenienceTest.createPeriod)2 Period (org.hisp.dhis.period.Period)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)1 ListMap (org.hisp.dhis.common.ListMap)1