<commit_before>package com.softwaremill.codebrag.service.user

import com.softwaremill.codebrag.domain._
import com.typesafe.scalalogging.slf4j.Logging
import com.softwaremill.codebrag.dao.events.NewUserRegistered
import CommitAuthorClassification._
import org.joda.time.DateTime
import com.softwaremill.codebrag.cache.{UserReviewedCommitsCacheEntry, UserReviewedCommitsCache, RepositoryCache}
import com.softwaremill.codebrag.service.config.ReviewProcessConfig

class AfterUserRegistered(
  val repoCache: RepositoryCache,
  val reviewedCommitsCache: UserReviewedCommitsCache,
  val config: ReviewProcessConfig) extends SetStartingDateForUser {

  def run(user: NewUserRegistered) {
    setStartingDate(user)
  }

}

trait SetStartingDateForUser extends Logging {

  val repoCache: RepositoryCache
  val reviewedCommitsCache: UserReviewedCommitsCache
  val config: ReviewProcessConfig

  protected def setStartingDate(user: NewUserRegistered) {
    val defaultToReviewStartDate = user.timestamp.minusDays(config.initialToReviewDays)
    val allBranchCommits = repoCache.getBranchCommits(currentBranch)
    val newestForUserToReview = allBranchCommits.filterNot(commitAuthoredByUser(_, user)).take(config.initialCommitsToReviewCount)
    val dateBoundary = newestForUserToReview.lastOption match {
      case Some(last) => getLatestFromBothDates(last.commitDate, defaultToReviewStartDate)
      case None => defaultToReviewStartDate
    }
    val newUserCacheEntry = UserReviewedCommitsCacheEntry.forNewlyRegisteredUser(user.id, dateBoundary)
    reviewedCommitsCache.addNewUserEntry(newUserCacheEntry)
    logger.debug(s"New user ${user.login} registered. To review boundary date set to ${dateBoundary}")
  }


  def getLatestFromBothDates(lastCommitDate: DateTime, weekBeforeRegistration: DateTime): DateTime = {
    if (lastCommitDate.isBefore(weekBeforeRegistration)) {
      weekBeforeRegistration
    } else {
      lastCommitDate
    }
  }

  private def currentBranch = repoCache.repository.getCheckedOutBranchFullName

}<commit_msg>Simplified way of setting user review start date (since when commits are considered as to review).<commit_after>package com.softwaremill.codebrag.service.user

import com.typesafe.scalalogging.slf4j.Logging
import com.softwaremill.codebrag.dao.events.NewUserRegistered
import org.joda.time.DateTime
import com.softwaremill.codebrag.cache.{UserReviewedCommitsCacheEntry, UserReviewedCommitsCache}
import com.softwaremill.codebrag.service.config.ReviewProcessConfig

class AfterUserRegistered(val reviewedCommitsCache: UserReviewedCommitsCache, val config: ReviewProcessConfig) extends SetStartingDateForUser {

  def run(user: NewUserRegistered) {
    setStartingDate(user)
  }

}

trait SetStartingDateForUser extends Logging {

  protected val reviewedCommitsCache: UserReviewedCommitsCache
  protected val config: ReviewProcessConfig

  protected def setStartingDate(user: NewUserRegistered) {
    val toReviewStartDate = user.timestamp.minusDays(config.initialToReviewDays)
    val newUserCacheEntry = UserReviewedCommitsCacheEntry.forNewlyRegisteredUser(user.id, toReviewStartDate)
    reviewedCommitsCache.addNewUserEntry(newUserCacheEntry)
    logger.debug(s"New user ${user.login} registered. To review boundary date set to $toReviewStartDate")
  }

  def getLatestFromBothDates(lastCommitDate: DateTime, weekBeforeRegistration: DateTime): DateTime = {
    if (lastCommitDate.isBefore(weekBeforeRegistration)) {
      weekBeforeRegistration
    } else {
      lastCommitDate
    }
  }

}
{'fraction_non_alphanumeric': 0.06845827439886845, 'fraction_numerical': 0.0005657708628005657, 'mean_word_length': 6.157894736842105, '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': '5048880', 'n_tokens_mistral': 1032, 'n_tokens_neox': 1010, 'n_words': 191}