Skip to content
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

Merged
merged 33 commits into from
Jan 30, 2022

Conversation

DonMischo
Copy link
Collaborator

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

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
@ArchibaldBienetre
Copy link
Collaborator

no tests so far shame on me

🤷 imo, this just makes it harder for you to catch edge cases and understand if anything is still missing

Usually, you could

  • create a so-called "spike" to try things out, then throw that away
  • try things out in a learning test

as an alternative

@ArchibaldBienetre
Copy link
Collaborator

ArchibaldBienetre commented Jan 7, 2022

❌ Some tests are failing on CI, could you have a look?

It seems to be a null issue

Caused by: java.lang.NullPointerException
	at org.example.csv2tex@1.0-SNAPSHOT/org.example.csv2tex.placeholders.NoopPlaceholderReplacer.replaceBaseData(NoopPlaceholderReplacer.java:67)
	at org.example.csv2tex@1.0-SNAPSHOT/org.example.csv2tex.placeholders.NoopPlaceholderReplacer.replacePlaceholdersInTexFile(NoopPlaceholderReplacer.java:24)
	at org.example.csv2tex@1.0-SNAPSHOT/org.example.csv2tex.rendering.SchoolReportsRenderer.renderSingleSchoolReportPdf(SchoolReportsRenderer.java:81)
	at org.example.csv2tex@1.0-SNAPSHOT/org.example.csv2tex.rendering.SchoolReportsRenderer.renderStudentReports(SchoolReportsRenderer.java:74)
	at org.example.csv2tex@1.0-SNAPSHOT/org.example.csv2tex.rendering.SchoolReportsRenderer.renderSchoolReportsForGivenFiles(SchoolReportsRenderer.java:65)
	at org.example.csv2tex@1.0-SNAPSHOT/org.example.csv2tex.rendering.SchoolReportsRenderer.renderSchoolReportsForGivenFiles(SchoolReportsRenderer.java:54)
	... 84 more

EDIT: ✔️ Fixed, mixup of file and file content string

Comment on lines 66 to 75
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;
}
Copy link
Collaborator

@ArchibaldBienetre ArchibaldBienetre Jan 7, 2022

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
@ArchibaldBienetre
Copy link
Collaborator

@DonMischo to have a cleaner commit history, I rebased the branch onto main

Comment on lines 54 to 56
firstSchoolcompetencyData.schoolSubject.equals("Mathematik") ||
firstSchoolcompetencyData.schoolSubject.equals("Deutsch") ||
firstSchoolcompetencyData.schoolSubject.equals("Englisch")) {
Copy link
Collaborator

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? :(

Copy link
Collaborator

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

Comment on lines 64 to 67
assertThat(level).isEqualTo("rot");
assertThat(level1).isEqualTo("rot");
assertThat(level2).isEqualTo("blau");
assertThat(level3).isEqualTo("grün");
Copy link
Collaborator

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?

Copy link
Collaborator

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #64

@@ -0,0 +1,216 @@
\documentclass[11pt,a4paper]{article}
Copy link
Collaborator

@ArchibaldBienetre ArchibaldBienetre Jan 21, 2022

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

Copy link
Collaborator

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.

Copy link
Collaborator

@ArchibaldBienetre ArchibaldBienetre Jan 23, 2022

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
@ArchibaldBienetre ArchibaldBienetre mentioned this pull request Jan 21, 2022
1 task
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
Copy link
Collaborator

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
Copy link
Collaborator

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") ||
Copy link
Collaborator

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??

Comment on lines 167 to 179
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";
Copy link
Collaborator

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";
Copy link
Collaborator

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.

Comment on lines +168 to +175
case "1":
return "\\gradeOne";
case "2":
return "\\gradeTwo";
case "3":
return "\\gradeThree";
case "4":
return "\\gradeFour";
Copy link
Collaborator

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.

Comment on lines 205 to 215
@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;
}
Copy link
Collaborator

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

Comment on lines 19 to 26
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");
Copy link
Collaborator

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...

Comment on lines 16 to 36
@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("");
}
Copy link
Collaborator

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 🤷

Comment on lines 78 to 84
if (!currentSubject.equals(schoolCompetencyData.schoolSubject)) {
currentSubject = schoolCompetencyData.schoolSubject;

tables.append(makeTableEntry(competencyList, partOfYear));
//FIXME
competencyList.removeAll(competencyList);
competencyList.add(schoolCompetencyData);
Copy link
Collaborator

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
Copy link
Collaborator

@ArchibaldBienetre ArchibaldBienetre left a 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 :)

@ArchibaldBienetre ArchibaldBienetre marked this pull request as ready for review January 23, 2022 16:37
DonMischo and others added 2 commits January 24, 2022 21:30
fix: default grade row command
assertThat(grade4).isEqualTo("\\gradeFour");
assertThat(gradeNotGiven).isEqualTo("\\gradeNotGiven");
assertThat(gradeComesWithSecondHalfYear).isEqualTo("\\gradeComesWithSecondHalfYear");
assertThat(gradeFalse).isEqualTo("\\gradeDefault");
Copy link
Collaborator

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
@@ -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).*")
Copy link
Collaborator

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

@ArchibaldBienetre
Copy link
Collaborator

@DonMischo good for merge? :)

The rest (new placeholders...), that is a separate issue and should be a separate pull request

@ArchibaldBienetre
Copy link
Collaborator

No response on any communication channel. I'm merging this then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants