-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
292ca75
use ordered datastructure for Alignment to fallback to the correct one
thoniTUB c7c561c
makes Resolution less leaky
thoniTUB 48fa605
refactor Resolution and Alignment class
thoniTUB f7fbf9c
refactor CalendarUnit and AlignmentReference class
thoniTUB 3042814
removes warnings
thoniTUB 33ba59a
Update AutoDoc
github-actions[bot] aff26e4
remmoves static initializer blocks
thoniTUB 47d6000
Update backend/src/main/java/com/bakdata/conquery/models/error/Conque…
thoniTUB ed6fa31
removes scratch test class
thoniTUB 370932f
adds documentation for CalendarUnit
thoniTUB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
backend/src/main/java/com/bakdata/conquery/models/forms/util/Alignment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
Map<Resolution, Integer> amountMap = getAmountPerResolution(); | ||
if (amountMap.containsKey(resolution)) { | ||
return OptionalInt.of(amountMap.get(resolution)); | ||
} | ||
return OptionalInt.empty(); | ||
} | ||
} | ||
|
52 changes: 52 additions & 0 deletions
52
backend/src/main/java/com/bakdata/conquery/models/forms/util/AlignmentReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.