Search in sources :

Example 6 with CDateRange

use of com.bakdata.conquery.models.common.daterange.CDateRange in project conquery by bakdata.

the class CDateSetSerializer method serialize.

@Override
public void serialize(CDateSet value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    gen.writeStartArray(value.asRanges().size());
    for (CDateRange range : value.asRanges()) {
        gen.writeStartArray(2);
        gen.writeNumber(range.getMinValue());
        gen.writeNumber(range.getMaxValue());
        gen.writeEndArray();
    }
    gen.writeEndArray();
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange)

Example 7 with CDateRange

use of com.bakdata.conquery.models.common.daterange.CDateRange in project conquery by bakdata.

the class CDateSet method add.

public void add(CDateRange rangeToAdd) {
    checkNotNull(rangeToAdd);
    int lbToAdd = rangeToAdd.getMinValue();
    int ubToAdd = rangeToAdd.getMaxValue();
    Entry<Integer, CDateRange> entryBelowLB = rangesByLowerBound.lowerEntry(lbToAdd);
    if (entryBelowLB != null) {
        CDateRange rangeBelowLB = entryBelowLB.getValue();
        // left neighbor would be connected
        if (rangeBelowLB.getMaxValue() >= lbToAdd - 1) {
            lbToAdd = rangeBelowLB.getMinValue();
            // left neighbor encloses new range
            if (rangeBelowLB.getMaxValue() > ubToAdd) {
                ubToAdd = rangeBelowLB.getMaxValue();
            }
        }
    }
    Entry<Integer, CDateRange> entryBelowUB = rangesByLowerBound.floorEntry(ubToAdd + 1);
    if (entryBelowUB != null) {
        CDateRange rangeBelowUB = entryBelowUB.getValue();
        if (rangeBelowUB.getMaxValue() >= ubToAdd) {
            ubToAdd = rangeBelowUB.getMaxValue();
        }
    }
    // Remove ranges which are strictly enclosed.
    rangesByLowerBound.subMap(lbToAdd, IntMath.saturatedAdd(ubToAdd, 1)).clear();
    putRange(CDateRange.of(lbToAdd, ubToAdd));
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange)

Example 8 with CDateRange

use of com.bakdata.conquery.models.common.daterange.CDateRange in project conquery by bakdata.

the class CDateSet method remove.

public void remove(CDateRange rangeToRemove) {
    checkNotNull(rangeToRemove);
    Entry<Integer, CDateRange> entryBelowLB = rangesByLowerBound.lowerEntry(rangeToRemove.getMinValue());
    if (entryBelowLB != null) {
        CDateRange rangeBelowLB = entryBelowLB.getValue();
        // left neighbor intersects removed range => shorten it to everything before removed range
        if (rangeBelowLB.getMaxValue() >= rangeToRemove.getMinValue()) {
            putRange(CDateRange.of(rangeBelowLB.getMinValue(), rangeToRemove.getMinValue() - 1));
            // left neighbor reaches beyond removed range => have to add cut of right part
            if (rangeBelowLB.getMaxValue() > rangeToRemove.getMaxValue()) {
                putRange(CDateRange.of(rangeToRemove.getMaxValue() + 1, rangeBelowLB.getMaxValue()));
            }
        }
    }
    Entry<Integer, CDateRange> entryBelowUB = rangesByLowerBound.floorEntry(rangeToRemove.getMaxValue());
    if (entryBelowUB != null) {
        CDateRange rangeBelowUB = entryBelowUB.getValue();
        // if reaches beyond removed range => have to add cut of right part
        if (rangeBelowUB.getMaxValue() > rangeToRemove.getMaxValue()) {
            // { > }
            putRange(CDateRange.of(rangeToRemove.getMaxValue() + 1, rangeBelowUB.getMaxValue()));
        }
    }
    rangesByLowerBound.subMap(rangeToRemove.getMinValue(), IntMath.saturatedAdd(rangeToRemove.getMaxValue(), 1)).clear();
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange)

Example 9 with CDateRange

use of com.bakdata.conquery.models.common.daterange.CDateRange in project conquery by bakdata.

the class DateContextTest method rangeAbsQuarterTestWithoutCoarse.

@Test
public void rangeAbsQuarterTestWithoutCoarse() {
    CDateRange mask = CDateRange.of(LocalDate.of(2001, 5, 23), LocalDate.of(2003, 4, 21));
    List<DateContext> contexts = DateContext.generateAbsoluteContexts(mask, List.of(ExportForm.ResolutionAndAlignment.of(QUARTERS, QUARTER)));
    assertThat(contexts).extracting(DateContext::getDateRange).containsExactly(CDateRange.of(LocalDate.of(2001, 5, 23), LocalDate.of(2001, 6, 30)), CDateRange.of(LocalDate.of(2001, 7, 1), LocalDate.of(2001, 9, 30)), CDateRange.of(LocalDate.of(2001, 10, 1), LocalDate.of(2001, 12, 31)), CDateRange.of(LocalDate.of(2002, 1, 1), LocalDate.of(2002, 3, 31)), CDateRange.of(LocalDate.of(2002, 4, 1), LocalDate.of(2002, 6, 30)), CDateRange.of(LocalDate.of(2002, 7, 1), LocalDate.of(2002, 9, 30)), CDateRange.of(LocalDate.of(2002, 10, 1), LocalDate.of(2002, 12, 31)), CDateRange.of(LocalDate.of(2003, 1, 1), LocalDate.of(2003, 3, 31)), CDateRange.of(LocalDate.of(2003, 4, 1), LocalDate.of(2003, 4, 21)));
    assertThat(contexts).extracting(DateContext::getFeatureGroup).containsOnly(FeatureGroup.OUTCOME);
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange) DateContext(com.bakdata.conquery.models.forms.util.DateContext) Test(org.junit.jupiter.api.Test)

Example 10 with CDateRange

use of com.bakdata.conquery.models.common.daterange.CDateRange in project conquery by bakdata.

the class DateContextTest method rangeAbsCompleteTestWithCoarse.

@Test
public void rangeAbsCompleteTestWithCoarse() {
    // Because COMPLETE_ONLY is the most coarse subdivision mode this has the same output as DateContextTest#rangeAbsCompleteTestWithoutCoarse
    CDateRange mask = CDateRange.of(LocalDate.of(2001, 5, 23), LocalDate.of(2005, 4, 21));
    List<DateContext> contexts = DateContext.generateAbsoluteContexts(mask, List.of(ExportForm.ResolutionAndAlignment.of(COMPLETE, NO_ALIGN)));
    assertThat(contexts).containsExactly(new DateContext(mask, FeatureGroup.OUTCOME, null, null, COMPLETE));
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange) DateContext(com.bakdata.conquery.models.forms.util.DateContext) Test(org.junit.jupiter.api.Test)

Aggregations

CDateRange (com.bakdata.conquery.models.common.daterange.CDateRange)25 Test (org.junit.jupiter.api.Test)8 DateContext (com.bakdata.conquery.models.forms.util.DateContext)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 CDateSet (com.bakdata.conquery.models.common.CDateSet)3 ArrayList (java.util.ArrayList)3 ExportForm (com.bakdata.conquery.apiv1.forms.export_form.ExportForm)2 LocalDate (java.time.LocalDate)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Column (com.bakdata.conquery.models.datasets.Column)1 Table (com.bakdata.conquery.models.datasets.Table)1 CBlock (com.bakdata.conquery.models.events.CBlock)1 ParsingException (com.bakdata.conquery.models.exceptions.ParsingException)1 DateAggregator (com.bakdata.conquery.models.query.queryplan.DateAggregator)1 EntityResult (com.bakdata.conquery.models.query.results.EntityResult)1 MultilineEntityResult (com.bakdata.conquery.models.query.results.MultilineEntityResult)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1