-
Notifications
You must be signed in to change notification settings - Fork 0
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
generation of Latex code and replacement in template #60
Conversation
no tests so far *shame on me*. had to sort out how to do it. would've been easier having the Latex template first. Some warnings for string.concat and string.replace
src/main/java/org/example/csv2tex/placeholders/NoopPlaceholderReplacer.java
Outdated
Show resolved
Hide resolved
src/main/java/org/example/csv2tex/placeholders/NoopPlaceholderReplacer.java
Outdated
Show resolved
Hide resolved
🤷 imo, this just makes it harder for you to catch edge cases and understand if anything is still missing Usually, you could
as an alternative |
❌ Some tests are failing on CI, could you have a look? It seems to be a null issue
EDIT: ✔️ Fixed, mixup of file and file content string |
public String replaceBaseData(String texFileContent, SchoolReportData schoolReportData) { | ||
texFileContent.replace("#givenName", schoolReportData.givenName); | ||
texFileContent.replace("#surName", schoolReportData.surName); | ||
texFileContent.replace("#birthDay", schoolReportData.birthDay); | ||
texFileContent.replace("#schoolClass", schoolReportData.schoolClass); | ||
texFileContent.replace("#schoolYear", schoolReportData.schoolYear); | ||
texFileContent.replace("#partOfYear", schoolReportData.partOfYear); | ||
|
||
return texFileContent; | ||
} |
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.
Nice method scope, nice encapsulation... as a "teacher", I'm a bit proud here :) 👍
(well, only the public modifier should be changed, but that should be easy enough)
no tests so far *shame on me*. had to sort out how to do it. would've been easier having the Latex template first. Some warnings for string.concat and string.replace
c1f2403
to
737579a
Compare
@DonMischo to have a cleaner commit history, I rebased the branch onto main |
no tests so far *shame on me*. added Tex template adapted code for tex generation
100% test coverage added some options for level and grades
firstSchoolcompetencyData.schoolSubject.equals("Mathematik") || | ||
firstSchoolcompetencyData.schoolSubject.equals("Deutsch") || | ||
firstSchoolcompetencyData.schoolSubject.equals("Englisch")) { |
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.
Hard-coded German subject names? :(
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.
Currently, it's a necessity
src/main/java/org/example/csv2tex/placeholders/NoopPlaceholderReplacer.java
Outdated
Show resolved
Hide resolved
assertThat(level).isEqualTo("rot"); | ||
assertThat(level1).isEqualTo("rot"); | ||
assertThat(level2).isEqualTo("blau"); | ||
assertThat(level3).isEqualTo("grün"); |
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.
Why German? 🤔
Is it part of a package?
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.
German names of the subject levels - we could add an indirection for the future, though
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.
See #64
src/main/java/org/example/csv2tex/placeholders/NoopPlaceholderReplacer.java
Outdated
Show resolved
Hide resolved
src/main/java/org/example/csv2tex/placeholders/NoopPlaceholderReplacer.java
Outdated
Show resolved
Hide resolved
nice trap I set for Micha m(
@@ -0,0 +1,216 @@ | |||
\documentclass[11pt,a4paper]{article} |
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.
Good work, looks great !! :)
What I may want to ask
- that we rename this file SchoolReportTemplateHalfYear_HalbjahreszeugnisTemplat.tex
- that we rename some things that use an abbreviation, currently (e.g. SS -> minorSubject, MS -> mainSubject)
- that we move this file somewhere else (not production code resources), e.g. a dedicated folder at root level of the repo
- that we can get rid of German names like "grün" in Java - and use an indirection here (? sry, not my expertise ':D)
-
that we add a simple integration test that runs this template, and checks that this does not fail (DAU proofing for future local changes)EDIT: No, should be part of days/hours absent #58, as it fails currently with as-of-yet-unsupported placeholders
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.
I let "grün" etc in there. It makes more sense to move it to a "school-specific extension" in the future if there is demand.
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.
⬆️ Moved to issue #64
put commands in extra tex file put packages in extra tex file
removed comments below
Let's keep this in English, and spell out any assumed abbreviations. The code should be easily understood - we go for professional code here :)
Like before - a variable's role should be easy to understand. Replacements for these will be introduced by #58
It's not a template, all placeholders are replaced already.
as usual, good naming is key
return texFileContent; | ||
} | ||
|
||
@VisibleForTesting |
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.
@DonMischo usually, having to make methods non-private for tests is a sign of bad encapsulation.
As it is unexpected that purely-internal code is not public, it's good style to mark it (e.g. by adding @VisibleForTesting
)
return subjectTable.toString(); | ||
} | ||
|
||
// This is a HACK - Michael needed to introduce it in hard-coded form for now |
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.
We should be honest about such things!
|
||
// This is a HACK - Michael needed to introduce it in hard-coded form for now | ||
private boolean shouldRenderAsMajorSubject(SchoolCompetencyData firstSchoolCompetencyData, String partOfYear) { | ||
return partOfYear.equals("Endjahr") || |
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.
@DonMischo Why is it an "OR" with end of year?
Because all subjects are graded at the end of the year??
switch (grade) { | ||
case "1": | ||
return "\\gradeOne"; | ||
case "2": | ||
return "\\gradeTwo"; | ||
case "3": | ||
return "\\gradeThree"; | ||
case "4": | ||
return "\\gradeFour"; | ||
case "hj": | ||
return "\\gradeHalfYear"; | ||
case "nb": | ||
return "\\gradeNotGiven"; |
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.
@DonMischo this is something that we should have talked about - you introduce special values to the data format that we didn't talk about nor test before.
"Stringly-typed", as this is called, can work, but once more, such things should be made really explicit.
At the very least, we should document it in the code of org.example.csv2tex.data.SchoolReportData
case "hj": | ||
return "\\gradeHalfYear"; | ||
case "nb": | ||
return "\\gradeNotGiven"; |
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.
@DonMischo Does it mean the subject is ungraded in general? If so, let's make the naming more clear here.
case "1": | ||
return "\\gradeOne"; | ||
case "2": | ||
return "\\gradeTwo"; | ||
case "3": | ||
return "\\gradeThree"; | ||
case "4": | ||
return "\\gradeFour"; |
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.
@DonMischo I really don't like that our so-far very generic all-purpose software is now super specific about what strings it expects :(
But it will do for now, we could exctract anything specific to Erfurt to a separate plugin later.
@VisibleForTesting | ||
String replaceBaseData(String texFileContent, SchoolReportData schoolReportData) { | ||
texFileContent = texFileContent | ||
.replace(TEX_TEMPLATE_PLACEHOLDER_GIVEN_NAME, schoolReportData.givenName) | ||
.replace(TEX_TEMPLATE_PLACEHOLDER_SURNAME, schoolReportData.surName) | ||
.replace(TEX_TEMPLATE_PLACEHOLDER_BIRTHDAY, schoolReportData.birthDay) | ||
.replace(TEX_TEMPLATE_PLACEHOLDER_SCHOOL_CLASS, schoolReportData.schoolClass) | ||
.replace(TEX_TEMPLATE_PLACEHOLDER_SCHOOL_YEAR, schoolReportData.schoolYear) | ||
.replace(TEX_TEMPLATE_PLACEHOLDER_PART_OF_YEAR, schoolReportData.partOfYear); | ||
return texFileContent; | ||
} |
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.
@DonMischo I desperately tried to address in numerous places that we should match for word boundaries here ... but screw it, let's leave it for now
String grade = sut.makeGrade(schoolReportData.schoolCompetencies.get(0).grade); | ||
String grade1 = sut.makeGrade("1"); | ||
String grade2 = sut.makeGrade("2"); | ||
String grade3 = sut.makeGrade("3"); | ||
String grade4 = sut.makeGrade("4"); | ||
String gradeNotGiven = sut.makeGrade("nb"); | ||
String gradeHalfYear = sut.makeGrade("hj"); | ||
String gradeFalse = sut.makeGrade("7"); |
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.
Parameterized test would be a better fit, but I don't want to rewrite everything again...
@Test | ||
public void makeGrade() { | ||
SchoolReportData schoolReportData = generateSchoolReportData(); | ||
String grade = sut.makeGrade(schoolReportData.schoolCompetencies.get(0).grade); | ||
String grade1 = sut.makeGrade("1"); | ||
String grade2 = sut.makeGrade("2"); | ||
String grade3 = sut.makeGrade("3"); | ||
String grade4 = sut.makeGrade("4"); | ||
String gradeNotGiven = sut.makeGrade("nb"); | ||
String gradeComesWithSecondHalfYear = sut.makeGrade("hj"); | ||
String gradeFalse = sut.makeGrade("7"); | ||
|
||
assertThat(grade).isEqualTo("\\gradeOne"); | ||
assertThat(grade1).isEqualTo("\\gradeOne"); | ||
assertThat(grade2).isEqualTo("\\gradeTwo"); | ||
assertThat(grade3).isEqualTo("\\gradeThree"); | ||
assertThat(grade4).isEqualTo("\\gradeFour"); | ||
assertThat(gradeNotGiven).isEqualTo("\\gradeNotGiven"); | ||
assertThat(gradeComesWithSecondHalfYear).isEqualTo("\\gradeComesWithSecondHalfYear"); | ||
assertThat(gradeFalse).isEqualTo(""); | ||
} |
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.
such stuff should be a parameterized test, but it's okay 🤷
if (!currentSubject.equals(schoolCompetencyData.schoolSubject)) { | ||
currentSubject = schoolCompetencyData.schoolSubject; | ||
|
||
tables.append(makeTableEntry(competencyList, partOfYear)); | ||
//FIXME | ||
competencyList.removeAll(competencyList); | ||
competencyList.add(schoolCompetencyData); |
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.
Reason for the confusing removeAll:
- Generates a new table part for each new subject
It's a bit of a weird side effect here, I'll leave it mostly intact, though, and make the code easier to read
this bit was confusing, I'm not sure it works as-is!
makes it way easier to grasp what is going on, imo
200a60f
to
7aff3d6
Compare
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.
This bit is still a bit mysterious: #60 (comment)
Apart from that, I guess the code is quite okay now :)
fix: default grade row command
assertThat(grade4).isEqualTo("\\gradeFour"); | ||
assertThat(gradeNotGiven).isEqualTo("\\gradeNotGiven"); | ||
assertThat(gradeComesWithSecondHalfYear).isEqualTo("\\gradeComesWithSecondHalfYear"); | ||
assertThat(gradeFalse).isEqualTo("\\gradeDefault"); |
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.
@DonMischo this is why the test was failing, because you changed production code without adjusting the test case
I don't know if this will work, @DonMischo must test
cf36060
to
481d95f
Compare
@@ -48,7 +48,7 @@ public void renderSchoolReportsForGivenFiles_withNonExistentCsv_throwsException( | |||
assertThatThrownBy(() -> sut.renderSchoolReportsForGivenFiles(NONEXISTENT_CSV_FILE, NO_PLACEHOLDERS_TEX_FILE)) | |||
.describedAs("As the UI prevents the user from selecting a nonexistent file, we expect a generic exception") | |||
.isInstanceOf(RenderingException.class) | |||
.hasMessageContaining("No such file") | |||
.hasMessageMatching(".*(No such file|nicht gefunden).*") |
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.
@DonMischo please check if this fixes tests no your German Ubuntu
@DonMischo good for merge? :) The rest (new placeholders...), that is a separate issue and should be a separate pull request |
No response on any communication channel. I'm merging this then. |
no tests so far shame on me. had to sort out how to do it. would've been easier having the Latex template first.
Some warnings for string.concat and string.replace