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