Skip to content

Commit 493ce7e

Browse files
committed
Extract repeated code in report generation
Many A&D reports have the same structure - organized by income interval, then by Borrower Characteristics (race, ethnicity, and minority status), then by disposition (application received, originated, denied, withdrawn, etc.) this method organizes data into that structure.
1 parent 81e58b9 commit 493ce7e

File tree

3 files changed

+50
-76
lines changed

3 files changed

+50
-76
lines changed

publication/src/main/scala/hmda/publication/reports/aggregate/A52.scala

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import java.util.Calendar
44

55
import akka.NotUsed
66
import akka.stream.scaladsl.Source
7-
import hmda.model.publication.reports.ApplicantIncomeEnum._
87
import hmda.model.publication.reports.{ ApplicantIncome, Disposition, MSAReport }
98
import hmda.publication.reports._
109
import hmda.publication.reports.util.DateUtil._
@@ -50,51 +49,16 @@ object A52 {
5049
val msa = msaReport(fipsCode.toString)
5150

5251
val incomeIntervals = calculateMedianIncomeIntervals(fipsCode)
53-
54-
val larsByIncome = larsByIncomeInterval(larsWithIncome, incomeIntervals)
55-
val borrowerCharacteristicsByIncomeF = borrowerCharacteristicsByIncomeInterval(larsByIncome, dispositions)
52+
val applicantIncomesF = applicantIncomesWithBorrowerCharacteristics(larsWithIncome, incomeIntervals, dispositions)
5653

5754
val yearF = calculateYear(larSource)
5855
val totalF = calculateDispositions(lars, dispositions)
5956

6057
for {
61-
lars50BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(LessThan50PercentOfMSAMedian)
62-
lars50To79BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(Between50And79PercentOfMSAMedian)
63-
lars80To99BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(Between80And99PercentOfMSAMedian)
64-
lars100To120BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(Between100And119PercentOfMSAMedian)
65-
lars120BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(GreaterThan120PercentOfMSAMedian)
66-
58+
applicantIncomes <- applicantIncomesF
6759
year <- yearF
6860
total <- totalF
6961
} yield {
70-
val income50 = ApplicantIncome(
71-
LessThan50PercentOfMSAMedian,
72-
lars50BorrowerCharacteristics
73-
)
74-
val income50To79 = ApplicantIncome(
75-
Between50And79PercentOfMSAMedian,
76-
lars50To79BorrowerCharacteristics
77-
)
78-
val income80To99 = ApplicantIncome(
79-
Between80And99PercentOfMSAMedian,
80-
lars80To99BorrowerCharacteristics
81-
)
82-
val income100To120 = ApplicantIncome(
83-
Between100And119PercentOfMSAMedian,
84-
lars100To120BorrowerCharacteristics
85-
)
86-
val income120 = ApplicantIncome(
87-
GreaterThan120PercentOfMSAMedian,
88-
lars120BorrowerCharacteristics
89-
)
90-
91-
val applicantIncomes = List(
92-
income50,
93-
income50To79,
94-
income80To99,
95-
income100To120,
96-
income120
97-
)
9862

9963
A52(
10064
year,

publication/src/main/scala/hmda/publication/reports/disclosure/D51.scala

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import java.util.Calendar
44

55
import akka.NotUsed
66
import akka.stream.scaladsl.Source
7-
import hmda.model.publication.reports.ApplicantIncomeEnum._
87
import hmda.publication.reports._
98
import hmda.model.publication.reports._
109
import hmda.publication.reports.util.DateUtil._
@@ -55,52 +54,17 @@ object D51 {
5554
val msa = msaReport(fipsCode.toString)
5655

5756
val incomeIntervals = calculateMedianIncomeIntervals(fipsCode)
58-
59-
val larsByIncome = larsByIncomeInterval(larsWithIncome, incomeIntervals)
60-
val borrowerCharacteristicsByIncomeF = borrowerCharacteristicsByIncomeInterval(larsByIncome, dispositions)
57+
val applicantIncomesF = applicantIncomesWithBorrowerCharacteristics(larsWithIncome, incomeIntervals, dispositions)
6158

6259
val yearF = calculateYear(larSource)
6360
val totalF = calculateDispositions(lars, dispositions)
6461

6562
for {
66-
lars50BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(LessThan50PercentOfMSAMedian)
67-
lars50To79BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(Between50And79PercentOfMSAMedian)
68-
lars80To99BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(Between80And99PercentOfMSAMedian)
69-
lars100To120BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(Between100And119PercentOfMSAMedian)
70-
lars120BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(GreaterThan120PercentOfMSAMedian)
71-
7263
institutionName <- institutionNameF
7364
year <- yearF
65+
applicantIncomes <- applicantIncomesF
7466
total <- totalF
7567
} yield {
76-
val income50 = ApplicantIncome(
77-
LessThan50PercentOfMSAMedian,
78-
lars50BorrowerCharacteristics
79-
)
80-
val income50To79 = ApplicantIncome(
81-
Between50And79PercentOfMSAMedian,
82-
lars50To79BorrowerCharacteristics
83-
)
84-
val income80To99 = ApplicantIncome(
85-
Between80And99PercentOfMSAMedian,
86-
lars80To99BorrowerCharacteristics
87-
)
88-
val income100To120 = ApplicantIncome(
89-
Between100And119PercentOfMSAMedian,
90-
lars100To120BorrowerCharacteristics
91-
)
92-
val income120 = ApplicantIncome(
93-
GreaterThan120PercentOfMSAMedian,
94-
lars120BorrowerCharacteristics
95-
)
96-
97-
val applicantIncomes = List(
98-
income50,
99-
income50To79,
100-
income80To99,
101-
income100To120,
102-
income120
103-
)
10468

10569
D51(
10670
respondentId,

publication/src/main/scala/hmda/publication/reports/util/ReportUtil.scala

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,52 @@ object ReportUtil extends SourceUtils {
6262
)
6363
}
6464

65+
def applicantIncomesWithBorrowerCharacteristics[ec: EC, mat: MAT, as: AS](
66+
larSource: Source[LoanApplicationRegisterQuery, NotUsed],
67+
incomeIntervals: Array[Double],
68+
dispositions: List[DispositionType]
69+
): Future[List[ApplicantIncome]] = {
70+
val larsByIncome = larsByIncomeInterval(larSource, incomeIntervals)
71+
val borrowerCharacteristicsByIncomeF = borrowerCharacteristicsByIncomeInterval(larsByIncome, dispositions)
72+
73+
for {
74+
lars50BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(LessThan50PercentOfMSAMedian)
75+
lars50To79BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(Between50And79PercentOfMSAMedian)
76+
lars80To99BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(Between80And99PercentOfMSAMedian)
77+
lars100To120BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(Between100And119PercentOfMSAMedian)
78+
lars120BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(GreaterThan120PercentOfMSAMedian)
79+
} yield {
80+
val income50 = ApplicantIncome(
81+
LessThan50PercentOfMSAMedian,
82+
lars50BorrowerCharacteristics
83+
)
84+
val income50To79 = ApplicantIncome(
85+
Between50And79PercentOfMSAMedian,
86+
lars50To79BorrowerCharacteristics
87+
)
88+
val income80To99 = ApplicantIncome(
89+
Between80And99PercentOfMSAMedian,
90+
lars80To99BorrowerCharacteristics
91+
)
92+
val income100To120 = ApplicantIncome(
93+
Between100And119PercentOfMSAMedian,
94+
lars100To120BorrowerCharacteristics
95+
)
96+
val income120 = ApplicantIncome(
97+
GreaterThan120PercentOfMSAMedian,
98+
lars120BorrowerCharacteristics
99+
)
100+
101+
List(
102+
income50,
103+
income50To79,
104+
income80To99,
105+
income100To120,
106+
income120
107+
)
108+
}
109+
}
110+
65111
def borrowerCharacteristicsByIncomeInterval[ec: EC, mat: MAT, as: AS](
66112
larsByIncome: Map[ApplicantIncomeEnum, Source[LoanApplicationRegisterQuery, NotUsed]],
67113
dispositions: List[DispositionType]

0 commit comments

Comments
 (0)