Search in sources :

Example 1 with CDateRange

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

the class CBlock method calculateEntityDateIndices.

/**
 * For every included entity, calculate min and max and store them as statistics in the CBlock.
 *
 * @implNote This is an unrolled implementation of {@link CDateRange#spanClosed(CDateRange)}.
 */
private static CDateRange[] calculateEntityDateIndices(Bucket bucket, int bucketSize) {
    CDateRange[] spans = new CDateRange[bucketSize];
    Arrays.fill(spans, CDateRange.all());
    // First initialize to an illegal state that's easy on our comparisons
    Table table = bucket.getTable();
    for (Column column : table.getColumns()) {
        if (!column.getType().isDateCompatible()) {
            continue;
        }
        for (int entity : bucket.getEntities()) {
            final int index = bucket.getEntityIndex(entity);
            final int end = bucket.getEntityEnd(entity);
            // We unroll spanClosed for the whole bucket/entity, this avoids costly
            int max = Integer.MIN_VALUE;
            int min = Integer.MAX_VALUE;
            for (int event = bucket.getEntityStart(entity); event < end; event++) {
                if (!bucket.has(event, column)) {
                    continue;
                }
                CDateRange range = bucket.getAsDateRange(event, column);
                if (range.hasLowerBound()) {
                    final int minValue = range.getMinValue();
                    max = Math.max(max, minValue);
                    min = Math.min(min, minValue);
                }
                if (range.hasUpperBound()) {
                    final int maxValue = range.getMaxValue();
                    max = Math.max(max, maxValue);
                    min = Math.min(min, maxValue);
                }
            }
            spans[index] = createClosed(max, min, spans[index]);
        }
    }
    return spans;
}
Also used : Table(com.bakdata.conquery.models.datasets.Table) Column(com.bakdata.conquery.models.datasets.Column) CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange)

Example 2 with CDateRange

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

the class CountQuartersOfDateRangeAggregator method acceptEvent.

@Override
public void acceptEvent(Bucket bucket, int event) {
    if (!bucket.has(event, getColumn())) {
        return;
    }
    final CDateSet set = CDateSet.create(bucket.getDateRange(event, getColumn()));
    set.retainAll(dateRestriction);
    for (CDateRange subRange : set.asRanges()) {
        // we can sensibly only look at real quarters.
        if (subRange.isOpen()) {
            continue;
        }
        addDateRange(subRange);
    }
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange) CDateSet(com.bakdata.conquery.models.common.CDateSet)

Example 3 with CDateRange

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

the class DateUnionAggregator method acceptEvent.

@Override
public void acceptEvent(Bucket bucket, int event) {
    if (!bucket.has(event, getColumn())) {
        return;
    }
    CDateRange value = bucket.getAsDateRange(event, getColumn());
    // otherwise the result would be something weird
    if (value.isOpen()) {
        return;
    }
    set.maskedAdd(value, dateRestriction);
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange)

Example 4 with CDateRange

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

the class DurationSumAggregator method acceptEvent.

@Override
public void acceptEvent(Bucket bucket, int event) {
    if (!bucket.has(event, getColumn())) {
        return;
    }
    final CDateRange value = bucket.getAsDateRange(event, getColumn());
    if (value.isOpen()) {
        return;
    }
    set.maskedAdd(value, dateRestriction);
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange)

Example 5 with CDateRange

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

the class DateContext method generateAbsoluteContexts.

/**
 * Generates a date context list of sub date ranges from the given dateRangeMask.
 * The generation of the contexts happens for each resolution with their mapped alignment.
 * The returned list is primarily sorted in the order of the given resolutions and secondarily by the temporal
 * succession of the contexts, e.g.: with resolutions YEARS, QUARTERS given the list would first contain the
 * ascending year ranges and than the quarter ranges. The alignment references always the lower bound of the
 * dateRangeMask.
 * @param dateRangeMask The mask in which the contexts are generated
 * @param resolutionAndAlignment The resolutions to produce and their alignment
 * @return A sorted list of all generated contexts
 */
public static List<DateContext> generateAbsoluteContexts(CDateRange dateRangeMask, List<ExportForm.ResolutionAndAlignment> resolutionAndAlignment) {
    List<DateContext> dcList = new ArrayList<>();
    for (ExportForm.ResolutionAndAlignment mode : resolutionAndAlignment) {
        Function<CDateRange, List<CDateRange>> divider = getDateRangeSubdivider(AlignmentReference.START, mode.getResolution(), mode.getAlignment());
        // Start counting index form 0 for every subdivision mode
        int index = 0;
        for (CDateRange quarterInMask : divider.apply(dateRangeMask)) {
            index++;
            DateContext dc = new DateContext(quarterInMask, FeatureGroup.OUTCOME, // For now there is no index for complete
            mode.getResolution().equals(Resolution.COMPLETE) ? null : index, null, mode.getResolution());
            dcList.add(dc);
        }
    }
    return dcList;
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange) ExportForm(com.bakdata.conquery.apiv1.forms.export_form.ExportForm)

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