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

Analytics duplication refactor #4920

Closed
wants to merge 21 commits into from

Conversation

jaredb96
Copy link
Contributor

I implemented repository wrapper classes to decrease the code duplication in the hmda analytics app

@@ -392,85 +379,85 @@ object HmdaAnalyticsApp extends App with TransmittalSheetComponent with LarCompo
.mapAsync(1) { lar =>
for {
insertorupdate <- submissionId.period match {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we replace this very long match statement with a map? And maybe do the same for the other match statements here? It would cut down on a ton of lines of code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm could you clarify a bit what you were thinking?

Copy link
Contributor

Choose a reason for hiding this comment

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

Never mind, map isn't the right thing here. Not sure what I was thinking yesterday.

What I meant is we can simplify this to 2-3 cases: case Period(year, None) => and case Period(year, Some(quarter)) => (and keep the final case _ => case). Using a variable for the year and quarter will get rid of a ton of these match cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah let's do that, will take some time to update

@tptignor
Copy link
Contributor

@PatrickGoRaft , what are your thoughts on this PR generally? I'm sure it can be made to work if there are any current functional problems, and I'm always for reusing code, but how many lines are we cutting out of the total code size? I wonder if we could do even better with.a 2D (year, quarter) array, if it's worth it.

@jaredb96
Copy link
Contributor Author

@PatrickGoRaft , what are your thoughts on this PR generally? I'm sure it can be made to work if there are any current functional problems, and I'm always for reusing code, but how many lines are we cutting out of the total code size? I wonder if we could do even better with.a 2D (year, quarter) array, if it's worth it.

@tptignor I don't want to mix up work to much. Let's keep this PR with its current class structure that I wrote. A further refactor, with a complete redesign, ought to be another ticket.

@jaredb96 jaredb96 linked an issue Nov 1, 2024 that may be closed by this pull request
@@ -317,85 +317,12 @@ object HmdaAnalyticsApp extends App with TransmittalSheetComponent with LarCompo
for {
insertorupdate <- submissionId.period match {
case Period(2018, None) => YearlyLarRepositoryWrapper("2018").getLarRepository.insert(LarConverter2018(lar))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

2018 has a special lar converter so we're keeping this here

larRepository2024Q3.insert(
LarConverter(lar = lar, 2024, isQuarterly = true)
case Period(2018, None) => YearlyLarRepositoryWrapper("2018").getLarRepository.insert(LarConverter2018(lar))
case Period(submissionId.period.year, None) => YearlyLarRepositoryWrapper(submissionId.period.year.toString).getLarRepository.insert(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does using submissionId.period.year in the case work when you test it? I thought just declaring a new variable year would work here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this works, on another unit test ticket I'm going to refactor this a bit to demonstrate that. I think we should stick to making this depend on the submissionId for now since this line is a part of reading from that.

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.

Reduce duplication in hmda analytics
4 participants