Skip to content

Commit 90082da

Browse files
committed
Consolidate report generation code - less confusion
1 parent 9e22dc3 commit 90082da

File tree

1 file changed

+21
-51
lines changed
  • publication/src/main/scala/hmda/publication/reports/disclosure

1 file changed

+21
-51
lines changed

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

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,27 @@ import hmda.model.publication.reports.ApplicantIncomeEnum._
88
import hmda.publication.reports._
99
import hmda.model.publication.reports._
1010
import hmda.publication.reports.util.DateUtil._
11-
import hmda.publication.reports.util.DispositionType._
1211
import hmda.publication.reports.util.ReportUtil._
12+
import hmda.publication.reports.util.ReportsMetaDataLookup
1313
import hmda.query.model.filing.LoanApplicationRegisterQuery
1414

1515
import scala.concurrent.Future
1616

1717
case class D51(
1818
respondentId: String,
1919
institutionName: String,
20-
table: String,
21-
description: String,
2220
year: Int,
2321
reportDate: String,
2422
msa: MSAReport,
2523
applicantIncomes: List[ApplicantIncome],
26-
total: List[Disposition]
24+
total: List[Disposition],
25+
table: String = D51.metaData.reportTable,
26+
description: String = D51.metaData.description
2727
) extends DisclosureReport
2828

2929
object D51 {
30-
def apply(
31-
respondentId: String,
32-
institutionName: String,
33-
year: Int,
34-
reportDate: String,
35-
msa: MSAReport,
36-
applicantIncomes: List[ApplicantIncome],
37-
total: List[Disposition]
38-
): D51 = {
39-
40-
val description = "Disposition of applications for FHA, FSA/RHS, and VA home-purchase loans, 1- to 4-family and manufactured home dwellings, by income, race and ethnicity of applicant"
41-
42-
D51(
43-
respondentId,
44-
institutionName,
45-
"5-1",
46-
description,
47-
year,
48-
reportDate,
49-
msa,
50-
applicantIncomes,
51-
total
52-
)
53-
}
54-
55-
val dispositions: List[DispositionType] =
56-
List(
57-
ReceivedDisp,
58-
OriginatedDisp,
59-
ApprovedButNotAcceptedDisp,
60-
DeniedDisp,
61-
WithdrawnDisp,
62-
ClosedDisp
63-
)
30+
val metaData = ReportsMetaDataLookup.values("D51")
31+
val dispositions = metaData.dispositions
6432

6533
// Table filters:
6634
// Loan Type 2,3,4
@@ -69,12 +37,12 @@ object D51 {
6937
def generate[ec: EC, mat: MAT, as: AS](
7038
larSource: Source[LoanApplicationRegisterQuery, NotUsed],
7139
fipsCode: Int,
72-
respId: String,
40+
respondentId: String,
7341
institutionNameF: Future[String]
7442
): Future[D51] = {
7543

7644
val lars = larSource
77-
.filter(lar => lar.respondentId == respId)
45+
.filter(lar => lar.respondentId == respondentId)
7846
.filter(lar => lar.msa != "NA")
7947
.filter(lar => lar.msa.toInt == fipsCode)
8048
.filter { lar =>
@@ -91,7 +59,7 @@ object D51 {
9159
val larsByIncome = larsByIncomeInterval(larsWithIncome, incomeIntervals)
9260
val borrowerCharacteristicsByIncomeF = borrowerCharacteristicsByIncomeInterval(larsByIncome, dispositions)
9361

94-
val dateF = calculateYear(larSource)
62+
val yearF = calculateYear(larSource)
9563
val totalF = calculateDispositions(lars, dispositions)
9664

9765
for {
@@ -102,7 +70,7 @@ object D51 {
10270
lars120BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(GreaterThan120PercentOfMSAMedian)
10371

10472
institutionName <- institutionNameF
105-
date <- dateF
73+
year <- yearF
10674
total <- totalF
10775
} yield {
10876
val income50 = ApplicantIncome(
@@ -126,19 +94,21 @@ object D51 {
12694
lars120BorrowerCharacteristics
12795
)
12896

97+
val applicantIncomes = List(
98+
income50,
99+
income50To79,
100+
income80To99,
101+
income100To120,
102+
income120
103+
)
104+
129105
D51(
130-
respId,
106+
respondentId,
131107
institutionName,
132-
date,
108+
year,
133109
formatDate(Calendar.getInstance().toInstant),
134110
msa,
135-
List(
136-
income50,
137-
income50To79,
138-
income80To99,
139-
income100To120,
140-
income120
141-
),
111+
applicantIncomes,
142112
total
143113
)
144114
}

0 commit comments

Comments
 (0)