<commit_before>package hmda.publication.reports.disclosure

import akka.NotUsed
import akka.stream.scaladsl.Source
import hmda.model.fi.lar.LoanApplicationRegister
import hmda.model.publication.reports.ApplicantIncomeEnum._
import hmda.model.publication.reports.EthnicityEnum._
import hmda.model.publication.reports.GenderEnum._
import hmda.model.publication.reports.MinorityStatusEnum._
import hmda.model.publication.reports.RaceEnum._
import hmda.publication.reports._
import hmda.publication.reports.util.EthnicityUtil.filterEthnicity
import hmda.publication.reports.util.GenderUtil.filterGender
import hmda.publication.reports.util.MinorityStatusUtil.filterMinorityStatus
import hmda.publication.reports.util.RaceUtil.filterRace
import hmda.publication.reports.util.ReportUtil._
import hmda.publication.reports.util.ReportsMetaDataLookup
import spray.json.JsValue

import scala.concurrent.Future

trait D11X
object D11X {


  def generate[ec: EC, mat: MAT, as: AS](
                                          report: D8X,
                                          larSource: Source[LoanApplicationRegister, NotUsed],
                                          fipsCode: Int,
                                          respondentId: String,
                                          institutionNameF: Future[String]
                                        ): Future[JsValue] = {

    val metaData = ReportsMetaDataLookup.values(report.reportId)

    val lars = larSource
      .filter(lar => lar.respondentId == respondentId)
      .filter(lar => lar.geography.msa != "NA")
      .filter(lar => lar.geography.msa.toInt == fipsCode)
      .filter(report.filters)

    val incomeIntervals = larsByIncomeInterval(
      lars.filter(lar => lar.applicant.income != "NA"),
      calculateMedianIncomeIntervals(fipsCode)
    )
    val msa = msaReport(fipsCode.toString).toJsonFormat<commit_msg>Add report filters for D11-X reports<commit_after>package hmda.publication.reports.disclosure

import akka.NotUsed
import akka.stream.scaladsl.Source
import hmda.model.fi.lar.LoanApplicationRegister
import hmda.model.publication.reports.ApplicantIncomeEnum._
import hmda.model.publication.reports.EthnicityEnum._
import hmda.model.publication.reports.GenderEnum._
import hmda.model.publication.reports.MinorityStatusEnum._
import hmda.model.publication.reports.RaceEnum._
import hmda.publication.reports._
import hmda.publication.reports.util.EthnicityUtil.filterEthnicity
import hmda.publication.reports.util.GenderUtil.filterGender
import hmda.publication.reports.util.MinorityStatusUtil.filterMinorityStatus
import hmda.publication.reports.util.RaceUtil.filterRace
import hmda.publication.reports.util.ReportUtil._
import hmda.publication.reports.util.ReportsMetaDataLookup
import spray.json.JsValue

import scala.concurrent.Future

trait D11X {
  val reportId: String
  def filters(lar: LoanApplicationRegister): Boolean
}

object D11_1 {
  val reportId = "D11-1"
  def filters(lar: LoanApplicationRegister): Boolean = {
    val loan = lar.loan
    loan.loanType == 2 && loan.purpose == 1 && lar.lienStatus == 1 &&
      loan.propertyType == 1 && loan.occupancy == 1
  }
}

object D11_2 {
  val reportId = "D11-2"
  def filters(lar: LoanApplicationRegister): Boolean = {
    val loan = lar.loan
    loan.loanType == 3 && loan.purpose == 1 && lar.lienStatus == 1 &&
      loan.propertyType == 1 && loan.occupancy == 1
  }
}

object D11_3 {
  val reportId = "D11-3"
  def filters(lar: LoanApplicationRegister): Boolean = {
    val loan = lar.loan
    loan.loanType == 1 && loan.purpose == 1 && lar.lienStatus == 1 &&
      loan.propertyType == 1 && loan.occupancy == 1
  }
}

object D11_4 {
  val reportId = "D11-4"
  def filters(lar: LoanApplicationRegister): Boolean = {
    val loan = lar.loan
    loan.loanType == 1 && loan.purpose == 1 && lar.lienStatus == 2 &&
      loan.propertyType == 1 && loan.occupancy == 1
  }
}

object D11_5 {
  val reportId = "D11-5"
  def filters(lar: LoanApplicationRegister): Boolean = {
    val loan = lar.loan
    loan.loanType == 2 && loan.purpose == 3 && lar.lienStatus == 1 &&
      loan.propertyType == 1 && loan.occupancy == 1
  }
}

object D11_6 {
  val reportId = "D11-6"
  def filters(lar: LoanApplicationRegister): Boolean = {
    val loan = lar.loan
    loan.loanType == 3 && loan.purpose == 3 && lar.lienStatus == 1 &&
      loan.propertyType == 1 && loan.occupancy == 1
  }
}

object D11_7 {
  val reportId = "D11-7"
  def filters(lar: LoanApplicationRegister): Boolean = {
    val loan = lar.loan
    loan.loanType == 1 && loan.purpose == 3 && lar.lienStatus == 1 &&
      loan.propertyType == 1 && loan.occupancy == 1
  }
}

object D11_8 {
  val reportId = "D11-8"
  def filters(lar: LoanApplicationRegister): Boolean = {
    val loan = lar.loan
    loan.loanType == 1 && loan.purpose == 3 && lar.lienStatus == 2 &&
      loan.propertyType == 1 && loan.occupancy == 1
  }
}

object D11_9 {
  val reportId = "D11-9"
  def filters(lar: LoanApplicationRegister): Boolean = {
    val loan = lar.loan
    loan.loanType == 1 && loan.purpose == 2 && lar.lienStatus == 1 &&
      loan.propertyType == 1 && loan.occupancy == 1
  }
}

object D11_10 {
  val reportId = "D11-10"
  def filters(lar: LoanApplicationRegister): Boolean = {
    val loan = lar.loan
    loan.loanType == 1 && loan.purpose == 2 && lar.lienStatus == 2 &&
      loan.propertyType == 1 && loan.occupancy == 1
  }
}

object D11X {


  def generate[ec: EC, mat: MAT, as: AS](
                                          report: D11X,
                                          larSource: Source[LoanApplicationRegister, NotUsed],
                                          fipsCode: Int,
                                          respondentId: String,
                                          institutionNameF: Future[String]
                                        ): Future[JsValue] = {

    val metaData = ReportsMetaDataLookup.values(report.reportId)

    val lars = larSource
      .filter(lar => lar.respondentId == respondentId)
      .filter(lar => lar.geography.msa != "NA")
      .filter(lar => lar.geography.msa.toInt == fipsCode)
      .filter(report.filters)

    val incomeIntervals = larsByIncomeInterval(
      lars.filter(lar => lar.applicant.income != "NA"),
      calculateMedianIncomeIntervals(fipsCode)
    )
    val msa = msaReport(fipsCode.toString).toJsonFormat
{'fraction_non_alphanumeric': 0.11252154834665413, 'fraction_numerical': 0.01958940604920859, 'mean_word_length': 2.7651917404129795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1892526', 'n_tokens_mistral': 2155, 'n_tokens_neox': 1945, 'n_words': 401}