-
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
Conversation
if(resolution.supportsAlignment(alignmentHint) ) { | ||
return alignmentHint; | ||
} | ||
return resolution.getDefaultAlignment(); |
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 die Resolution
festgelegten, Datumsbereiche ausrichten. So kannst du zum Beispiel eine Auflösung von Jahren am heutigen
Tag (31.08.2021 - 31.08.2022
),
Quartal (01.07.2021 - 30.06.2022
) oder
Jahr (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.
@@ -132,7 +132,10 @@ public String getLocalizedTypeLabel() { | |||
} | |||
|
|||
private static DateContext.Alignment getFittingAlignment(DateContext.Alignment alignmentHint, DateContext.Resolution resolution) { | |||
return resolution.getSupportedAlignments().contains(alignmentHint)? alignmentHint : resolution.getSupportedAlignments().iterator().next(); | |||
if(resolution.supportsAlignment(alignmentHint) ) { |
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.
=> isAlignmentSupported
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.
Jep, das ist besser
backend/src/main/java/com/bakdata/conquery/models/error/ConqueryError.java
Outdated
Show resolved
Hide resolved
// We need to define this in a static block so the runtime can solve this cyclic | ||
// dependency between Resolution and alignment. Otherwise a NPE is thrown by the | ||
// Collection | ||
COMPLETE.compatibleAlignments = List.of(Alignment.NO_ALIGN); |
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.
Werde aus dem Kommentar leider nicht schlau, aber warum kannst du das nicht im Konstruktor machen?
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.
Beide kompilieren, aber der Erste läuft auf Grund der NPE nicht:
import lombok.RequiredArgsConstructor;
import java.util.List;
public class Test {
@org.junit.jupiter.api.Test
public void test() {
E1 e = E1.A;
}
@RequiredArgsConstructor
public static enum E1{
A(List.of(E2.a));
private final List<E2> e;
}
@RequiredArgsConstructor
public static enum E2 {
a(List.of(E1.A));
private final List<E1> e;
}
}
Ohne Collection dazwischen geht es:
import lombok.RequiredArgsConstructor;
import java.util.List;
public class Test {
@org.junit.jupiter.api.Test
public void test() {
E1 e = E1.A;
}
@RequiredArgsConstructor
public static enum E1{
A(E2.a);
private final E2 e;
}
@RequiredArgsConstructor
public static enum E2 {
a(E1.A);
private final E1 e;
}
}
// dependency between Resolution and alignment. Otherwise a NPE is thrown by the | ||
// Collection | ||
COMPLETE.compatibleAlignments = List.of(Alignment.NO_ALIGN); | ||
// Beware that the first alignment is considered the 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.
Kannst du das nicht einfach direkt kodieren für ein extra feld?
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.
Ich habe es jetzt als Methode definiert, dann gibt es bei der Konstruktion auch keine cyc Dependenies
} | ||
|
||
/** | ||
* Returns the amount of calendar alignment sub date ranges that would fit in to this resolution. | ||
*/ | ||
@JsonIgnore | ||
public OptionalInt getAmountForAlignment(Alignment alignment){ | ||
if (!this.compatibleAlignmentsAndAmount.containsKey(alignment)) { | ||
if (!this.compatibleAlignments.contains(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.
supportsAlignment benutzen.
@@ -270,8 +287,24 @@ public OptionalInt getAmountForAlignment(Alignment alignment){ | |||
QUARTER(CDateRange::getCoveredQuarters), | |||
YEAR(CDateRange::getCoveredYears); | |||
|
|||
static { | |||
NO_ALIGN.amountPerResolution = Map.of(Resolution.COMPLETE, 1); |
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.
Auch hier mir leider nicht klar warum du das nicht im ctor machen kannst.
Frage mich gerade auch, ob das nicht sogar was wäre das schon in einer DatteTime Bibliothek kodiert ist.
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.
Ich glaube nicht, weil es unterschiedliche Definitionen für manches gibt. Im Finanzsektor ist ein Jahr manchmal nur 360 Tage lang.
|
||
List<DateContext> contexts = DateContext.generateRelativeContexts(event, indexPlacement, featureTime, outcomeTime, timeUnit, ExportForm.getResolutionAlignmentMap(List.of(YEARS, QUARTERS), YEAR)); | ||
|
||
assertThat(contexts).containsExactly ( |
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.
uff :D
…ryError.java Co-authored-by: awildturtok <1553491+awildturtok@users.noreply.github.com>
*/ | ||
@JsonIgnore | ||
public OptionalInt getAmountForResolution(Resolution resolution) { | ||
Integer amount = getAmountPerResolution().get(resolution); |
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.
Würde ich über contains machen aber unwichtig
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.
Habs angepasst
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public enum CalendarUnit { |
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.
Doku
import lombok.RequiredArgsConstructor; | ||
import java.util.List; | ||
|
||
public class Test { |
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.
Test
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.
Die sollte jetzt raus sein
before the fallback for a date context alignment was determined by the order of the hash map. Now an ordered data structure is used there