-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/date context alignment fallback #2060
Changes from 8 commits
292ca75
c7c561c
48fa605
f7fbf9c
3042814
33ba59a
aff26e4
47d6000
ed6fa31
370932f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.bakdata.conquery.models.forms.util; | ||
|
||
import com.bakdata.conquery.models.common.daterange.CDateRange; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.OptionalInt; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Specifier for the alignment of {@link DateContext}s of a certain resolution. | ||
* The alignment provides a method to sub divide a dateRangeMask into ranges aligned to the calendar equivalent. | ||
* These sub divisions can then be merged to form the equally grain or coarser desired resolution for the | ||
* {@link DateContext}s. | ||
*/ | ||
@RequiredArgsConstructor | ||
public enum Alignment { | ||
NO_ALIGN(List::of){ | ||
@Override | ||
protected Map<Resolution, Integer> getAmountPerResolution() { | ||
return Map.of(Resolution.COMPLETE, 1); | ||
} | ||
}, // Special case for resolution == COMPLETE | ||
DAY(CDateRange::getCoveredDays) { | ||
@Override | ||
protected Map<Resolution, Integer> getAmountPerResolution() { | ||
return Map.of( | ||
Resolution.YEARS, 365, | ||
Resolution.QUARTERS, 90, | ||
Resolution.DAYS, 1); | ||
} | ||
}, | ||
QUARTER(CDateRange::getCoveredQuarters) { | ||
@Override | ||
protected Map<Resolution, Integer> getAmountPerResolution() { | ||
return Map.of( | ||
Resolution.YEARS, 4, | ||
Resolution.QUARTERS, 1); | ||
} | ||
}, | ||
YEAR(CDateRange::getCoveredYears) { | ||
@Override | ||
protected Map<Resolution, Integer> getAmountPerResolution() { | ||
return Map.of(Resolution.YEARS, 1); | ||
} | ||
}; | ||
|
||
@Getter | ||
@JsonIgnore | ||
private final Function<CDateRange, List<CDateRange>> subdivider; | ||
|
||
@JsonIgnore | ||
protected abstract Map<Resolution, Integer> getAmountPerResolution(); | ||
|
||
/** | ||
* Returns the amount of calendar alignment sub date ranges that would fit in to this resolution. | ||
*/ | ||
@JsonIgnore | ||
public OptionalInt getAmountForResolution(Resolution resolution) { | ||
Integer amount = getAmountPerResolution().get(resolution); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Würde ich über contains machen aber unwichtig There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Habs angepasst |
||
if (amount == null) { | ||
return OptionalInt.empty(); | ||
} | ||
return OptionalInt.of(amount); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.bakdata.conquery.models.forms.util; | ||
|
||
import com.bakdata.conquery.models.common.daterange.CDateRange; | ||
import com.google.common.collect.Lists; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Specifies whether the sub date ranges (which have the maximum length specified by the {@link Resolution}) | ||
* are aligned with regard to beginning or the end of a date range mask. This affects the generated sub date ranges | ||
* only if the {@link Alignment} is finer than the {@link Resolution}. | ||
*/ | ||
public enum AlignmentReference { | ||
START() { | ||
@Override | ||
public List<CDateRange> getAlignedIterationDirection(List<CDateRange> alignedSubDivisions) { | ||
return alignedSubDivisions; | ||
} | ||
|
||
@Override | ||
public int getInterestingBorder(CDateRange daterange) { | ||
return daterange.getMinValue(); | ||
} | ||
|
||
@Override | ||
public CDateRange makeMergedRange(CDateRange lastDaterange, int prioInteressingBorder) { | ||
return CDateRange.of(prioInteressingBorder, lastDaterange.getMaxValue()); | ||
} | ||
}, | ||
END() { | ||
@Override | ||
public List<CDateRange> getAlignedIterationDirection(List<CDateRange> alignedSubDivisions) { | ||
return Lists.reverse(alignedSubDivisions); | ||
} | ||
|
||
@Override | ||
public int getInterestingBorder(CDateRange daterange) { | ||
return daterange.getMaxValue(); | ||
} | ||
|
||
@Override | ||
public CDateRange makeMergedRange(CDateRange lastDaterange, int prioInteressingBorder) { | ||
return CDateRange.of(lastDaterange.getMinValue(), prioInteressingBorder); | ||
} | ||
}; | ||
|
||
public abstract List<CDateRange> getAlignedIterationDirection(List<CDateRange> alignedSubDivisions); | ||
|
||
public abstract int getInterestingBorder(CDateRange daterange); | ||
|
||
public abstract CDateRange makeMergedRange(CDateRange lastDaterange, int prioInteressingBorder); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.bakdata.conquery.models.forms.util; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public enum CalendarUnit { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doku |
||
DAYS(Alignment.DAY), | ||
QUARTERS(Alignment.QUARTER), | ||
YEARS(Alignment.YEAR); | ||
|
||
@Getter | ||
private final Alignment alignment; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warum nimmst du hier den Default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Njimefo
Im ExportFormular kann der Nutzer verschiedene zeitliche Stratifizierungen auswählen, also ob Events über Tage, Quartale oder Jahre zusammen gefasst werden sollen (Monate, Wochen wären theoretisch auch möglich). Das ist die
Resolution
, also die Auflösung der Stratifizierung.Dann gibt es noch das kalendarische
Alignment
. Das gibt an, woran sich die, durch dieResolution
festgelegten, Datumsbereiche ausrichten. So kannst du zum Beispiel eine Auflösung von Jahren am heutigenTag (
31.08.2021 - 31.08.2022
),Quartal (
01.07.2021 - 30.06.2022
) oderJahr (
01.01.2021 - 31.12.2021
) ausrichten.Jetzt zum Default: Die API lässt es zu, dass du ein
alignmentHint
gibts. Es passt aber ein gröberes Aligment nicht zu einer feineren Auflösung: Es ist nicht möglich Quartale am Kalenderjahr auszurichten. An dieser Stelle gibt es einen Fallback zum Default.