Skip to content

Commit

Permalink
Merge pull request #924 from nickgrippin/msa-title
Browse files Browse the repository at this point in the history
Add name to MSA response
  • Loading branch information
schbetsy authored Apr 12, 2017
2 parents 82d9feb + 99db2e8 commit 9a18f9e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Documents/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ Example response:
"msas": [
{
"id": "123",
"name": "Some, Place",
"totalLARS": 4,
"totalAmount": 123,
"conv": 4,
Expand All @@ -551,6 +552,7 @@ Example response:
},
{
"id": "456",
"name": "Other, Place",
"totalLARS": 5,
"totalAmount": 456,
"conv": 5,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package hmda.api.protocol.processing

import hmda.query.model.filing.{ Irs, Msa, MsaSummary }
import hmda.query.model.filing.{ Irs, Msa, MsaSummary, MsaWithName }
import spray.json.DefaultJsonProtocol

trait MsaProtocol extends DefaultJsonProtocol {
implicit val msaProtocol = jsonFormat13(Msa.apply)
implicit val msaWithNameProtocol = jsonFormat14(MsaWithName.apply)
implicit val msaSummaryProtocol = jsonFormat12(MsaSummary.apply)
implicit val irsProtocol = jsonFormat2(Irs.apply)
}
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ lazy val query = (project in file("query"))
libraryDependencies ++= configDeps ++ akkaPersistenceDeps ++ slickDeps
)
.dependsOn(modelJVM % "compile->compile;test->test")
.dependsOn(census % "compile->compile;test->test")
.dependsOn(persistenceModel % "compile->compile;test->test")

lazy val api = (project in file("api"))
Expand Down
4 changes: 4 additions & 0 deletions census/src/main/scala/hmda/census/model/CbsaLookup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ object CbsaLookup extends CbsaResourceUtils {
)
}
}.toSeq

val codeMap: Map[String, String] = {
values.map(x => (x.cbsa, x.cbsaTitle)).toMap
}
}

case class Cbsa(
Expand Down
46 changes: 44 additions & 2 deletions query/src/main/scala/hmda/query/model/filing/Msa.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package hmda.query.model.filing

import hmda.census.model.CbsaLookup

case class Msa(
id: String,
totalLars: Int,
Expand All @@ -16,6 +18,23 @@ case class Msa(
refinance: Int
)

case class MsaWithName(
id: String,
name: String,
totalLars: Int,
totalAmount: Int,
conv: Int,
FHA: Int,
VA: Int,
FSA: Int,
oneToFourFamily: Int,
MFD: Int,
multiFamily: Int,
homePurchase: Int,
homeImprovement: Int,
refinance: Int
)

case class MsaSummary(
lars: Int,
amount: Int,
Expand Down Expand Up @@ -52,11 +71,34 @@ case object MsaSummary {
def empty: MsaSummary = MsaSummary(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
}

case class Irs(msas: List[Msa], totals: MsaSummary)
case class Irs(msas: List[MsaWithName], totals: MsaSummary)

case object Irs {
def createIrs(msas: List[Msa]): Irs = {
val codeMap = CbsaLookup.codeMap
val msaSeqWithName = msas.map(m => addMsaName(m, codeMap.get(m.id)))

val summary = msas.foldLeft(MsaSummary.empty) { (summary, msa) => summary + msa }
Irs(msas, summary)

Irs(msaSeqWithName, summary)
}

private def addMsaName(msa: Msa, name: Option[String]): MsaWithName = {
MsaWithName(
msa.id,
name.getOrElse("NA"),
msa.totalLars,
msa.totalAmount,
msa.conv,
msa.FHA,
msa.VA,
msa.FSA,
msa.oneToFourFamily,
msa.MFD,
msa.multiFamily,
msa.homePurchase,
msa.homeImprovement,
msa.refinance
)
}
}

0 comments on commit 9a18f9e

Please sign in to comment.