<commit_before>package hmda.utils

import com.typesafe.config.ConfigFactory

object YearUtils {

  val config = ConfigFactory.load()

  val firstYear   = config.getString("hmda.filing.first_year")
  val currentYear = config.getString("hmda.filing.current")

  def isValidYear(year: Int): Boolean =
    (year >= firstYear.toInt) && (year <= currentYear.toInt)

  def isValidQuarter(quarter: String): Boolean =
    quarter.length == 2 &&
      quarter.head == 'Q' &&
      quarter.last.isDigit && {
      val digit = quarter.last.toString.toInt
      digit >= 1 && digit <= 3
    }

  def period(year: Int, quarter: Option[String]): String =
    quarter.fold(ifEmpty = s"$year")(quarter => s"$year-$quarter")
}
<commit_msg>parse period<commit_after>package hmda.utils

import com.typesafe.config.ConfigFactory
import cats.implicits._

object YearUtils {

  val config = ConfigFactory.load()

  val firstYear   = config.getString("hmda.filing.first_year")
  val currentYear = config.getString("hmda.filing.current")

  def isValidYear(year: Int): Boolean =
    (year >= firstYear.toInt) && (year <= currentYear.toInt)

  def isValidQuarter(quarter: String): Boolean =
    quarter.length == 2 &&
      quarter.head == 'Q' &&
      quarter.last.isDigit && {
      val digit = quarter.last.toString.toInt
      digit >= 1 && digit <= 3
    }

  def period(year: Int, quarter: Option[String]): String =
    quarter.fold(ifEmpty = s"$year")(quarter => s"$year-$quarter")

  case class Period(year: Int, quarter: Option[String])

  def parsePeriod(period: String): Either[Exception, Period] = {
    val raw = period.split("-")
    if (raw.length == 1) Period(raw(0).toInt, None).asRight
    else if (raw.length == 2) Period(raw(0).toInt, Option(raw(1))).asRight
    else new Exception(s"Failed to parse invalid period: $period").asLeft
  }
}

{'fraction_non_alphanumeric': 0.14675395526459356, 'fraction_numerical': 0.006001091107474086, 'mean_word_length': 3.7268041237113403, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '817570', 'n_tokens_mistral': 612, 'n_tokens_neox': 581, 'n_words': 132}