<commit_before>package hmda.census.model

import hmda.model.fi.lar.LoanApplicationRegister

import scala.collection.immutable.ListMap
import scala.language.implicitConversions

case class Msa(
    id: String = "",
    name: String = "",
    totalLars: Int = 0,
    totalAmount: Int = 0,
    conv: Int = 0,
    FHA: Int = 0,
    VA: Int = 0,
    FSA: Int = 0,
    oneToFourFamily: Int = 0,
    MFD: Int = 0,
    multiFamily: Int = 0,
    homePurchase: Int = 0,
    homeImprovement: Int = 0,
    refinance: Int = 0
) {
  def addLar(lar: LoanApplicationRegister): Msa = {
    implicit def bool2int(b: Boolean): Int = if (b) 1 else 0

    new Msa(
      id = id,
      name = name,
      totalLars = totalLars + 1,
      totalAmount = totalAmount + lar.loan.amount,
      conv = conv + (lar.loan.loanType == 1),
      FHA = FHA + (lar.loan.loanType == 2),
      VA = VA + (lar.loan.loanType == 3),
      FSA = FSA + (lar.loan.loanType == 4),
      oneToFourFamily = oneToFourFamily + (lar.loan.propertyType == 1),
      MFD = MFD + (lar.loan.propertyType == 2),
      multiFamily = multiFamily + (lar.loan.propertyType == 3),
      homePurchase = homePurchase + (lar.loan.purpose == 1),
      homeImprovement = homeImprovement + (lar.loan.purpose == 2),
      refinance = refinance + (lar.loan.purpose == 3)
    )
  }
}

case class MsaMap(
    msas: ListMap[String, Msa] = ListMap[String, Msa]()
) {
  def +(lar: LoanApplicationRegister): MsaMap = {
    val id = lar.geography.msa
    val original = msas.getOrElse(id, Msa(id, CbsaLookup.nameFor(id)))
    val modified = original.addLar(lar)
    MsaMap(msas + ((id, modified)))
  }
}

case class MsaSummary(
    lars: Int = 0,
    amount: Int = 0,
    conv: Int = 0,
    FHA: Int = 0,
    VA: Int = 0,
    FSA: Int = 0,
    oneToFourFamily: Int = 0,
    MFD: Int = 0,
    multiFamily: Int = 0,
    homePurchase: Int = 0,
    homeImprovement: Int = 0,
    refinance: Int = 0
) {
  def +(elem: Msa): MsaSummary = {
    new MsaSummary(
      lars + elem.totalLars,
      amount + elem.totalAmount,
      conv + elem.conv,
      FHA + elem.FHA,
      VA + elem.VA,
      FSA + elem.FSA,
      oneToFourFamily + elem.oneToFourFamily,
      MFD + elem.MFD,
      multiFamily + elem.multiFamily,
      homePurchase + elem.homePurchase,
      homeImprovement + elem.homeImprovement,
      refinance + elem.refinance
    )
  }
}

case object MsaSummary {
  def fromMsaCollection(msas: Seq[Msa]): MsaSummary = {
    msas.foldLeft(MsaSummary()) { (summary, msa) => summary + msa }
  }
}
<commit_msg>switch from listmap to map<commit_after>package hmda.census.model

import hmda.model.fi.lar.LoanApplicationRegister

import scala.language.implicitConversions

case class Msa(
    id: String = "",
    name: String = "",
    totalLars: Int = 0,
    totalAmount: Int = 0,
    conv: Int = 0,
    FHA: Int = 0,
    VA: Int = 0,
    FSA: Int = 0,
    oneToFourFamily: Int = 0,
    MFD: Int = 0,
    multiFamily: Int = 0,
    homePurchase: Int = 0,
    homeImprovement: Int = 0,
    refinance: Int = 0
) {
  def addLar(lar: LoanApplicationRegister): Msa = {
    implicit def bool2int(b: Boolean): Int = if (b) 1 else 0

    new Msa(
      id = id,
      name = name,
      totalLars = totalLars + 1,
      totalAmount = totalAmount + lar.loan.amount,
      conv = conv + (lar.loan.loanType == 1),
      FHA = FHA + (lar.loan.loanType == 2),
      VA = VA + (lar.loan.loanType == 3),
      FSA = FSA + (lar.loan.loanType == 4),
      oneToFourFamily = oneToFourFamily + (lar.loan.propertyType == 1),
      MFD = MFD + (lar.loan.propertyType == 2),
      multiFamily = multiFamily + (lar.loan.propertyType == 3),
      homePurchase = homePurchase + (lar.loan.purpose == 1),
      homeImprovement = homeImprovement + (lar.loan.purpose == 2),
      refinance = refinance + (lar.loan.purpose == 3)
    )
  }
}

case class MsaMap(
    msas: Map[String, Msa] = Map[String, Msa]()
) {
  def +(lar: LoanApplicationRegister): MsaMap = {
    val id = lar.geography.msa
    val original = msas.getOrElse(id, Msa(id, CbsaLookup.nameFor(id)))
    val modified = original.addLar(lar)
    MsaMap(msas + ((id, modified)))
  }
}

case class MsaSummary(
    lars: Int = 0,
    amount: Int = 0,
    conv: Int = 0,
    FHA: Int = 0,
    VA: Int = 0,
    FSA: Int = 0,
    oneToFourFamily: Int = 0,
    MFD: Int = 0,
    multiFamily: Int = 0,
    homePurchase: Int = 0,
    homeImprovement: Int = 0,
    refinance: Int = 0
) {
  def +(elem: Msa): MsaSummary = {
    new MsaSummary(
      lars + elem.totalLars,
      amount + elem.totalAmount,
      conv + elem.conv,
      FHA + elem.FHA,
      VA + elem.VA,
      FSA + elem.FSA,
      oneToFourFamily + elem.oneToFourFamily,
      MFD + elem.MFD,
      multiFamily + elem.multiFamily,
      homePurchase + elem.homePurchase,
      homeImprovement + elem.homeImprovement,
      refinance + elem.refinance
    )
  }
}

case object MsaSummary {
  def fromMsaCollection(msas: Seq[Msa]): MsaSummary = {
    msas.foldLeft(MsaSummary()) { (summary, msa) => summary + msa }
  }
}

{'fraction_non_alphanumeric': 0.13297555158020274, 'fraction_numerical': 0.015106340687736036, 'mean_word_length': 2.5287517531556802, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1783477', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1850, 'n_words': 450}