<commit_before>package com.android.szparag.todoist.models.implementations

import com.android.szparag.todoist.models.contracts.CalendarModel
import com.android.szparag.todoist.models.entities.RenderDay
import com.android.szparag.todoist.utils.Logger
import com.android.szparag.todoist.utils.ReactiveList
import com.android.szparag.todoist.utils.ReactiveListEvent
import com.android.szparag.todoist.utils.ReactiveMutableList
import com.android.szparag.todoist.utils.range
import com.android.szparag.todoist.utils.weekAsDays
import io.reactivex.Completable
import io.reactivex.Observable
import org.joda.time.LocalDate
import java.util.Locale
import java.util.Random


//todo: locale is useless here
//todo: or is it not?

private const val INITIAL_DAYS_CAPACITY = 7 * 8

class TodoistCalendarModel(private var locale: Locale) : CalendarModel {

  override val logger by lazy { Logger.create(this::class.java, this.hashCode()) }
  private lateinit var currentDay: LocalDate
  private val random by lazy { Random() }
  private val datesList: ReactiveList<LocalDate> = ReactiveMutableList(INITIAL_DAYS_CAPACITY, true)

  override fun attach(): Completable {
    logger.debug("attach")
    return Completable.fromAction {
      setupCalendarInstance()
      logger.debug("attach.action.finished")
    }
  }

  override fun detach(): Completable = Completable.fromAction { logger.debug("detach") }

  override fun subscribeForDaysListEvents(): Observable<ReactiveListEvent> {
    logger.debug("subscribeForDaysListEvents")
    return datesList.subscribeForListEvents()
  }

  override fun subscribeForDaysListData(): Observable<ReactiveList<LocalDate>> {
    logger.debug("subscribeForDaysListData")
    return datesList.subscribeForListData()
  }

  override fun requestRelativeWeekAsDays(weekForward: Boolean, fetchMultiplier: Int) {
    logger.debug("requestRelativeWeekAsDays, weekForward: $weekForward, fetchMultiplier: $fetchMultiplier")
    val boundaryLocalDate = datesList.boundary(weekForward)
    range(1, fetchMultiplier - 1).forEach { weekIndex ->
      val appendingLocalDates = boundaryLocalDate.plusWeeks(weekIndex).weekAsDays()
      datesList.insert(appendingLocalDates)
      logger.debug("requestRelativeWeekAsDays, index: $weekIndex, appending: $appendingLocalDates")
    }.also {
      logger.debug("requestRelativeWeekAsDays, datesList: $datesList")
    }
  }

  override fun setupCalendarInstance() {<commit_msg>week streaming: fixed range indexing, moved additional processing one day forward<commit_after>package com.android.szparag.todoist.models.implementations

import com.android.szparag.todoist.models.contracts.CalendarModel
import com.android.szparag.todoist.models.entities.RenderDay
import com.android.szparag.todoist.utils.Logger
import com.android.szparag.todoist.utils.ReactiveList
import com.android.szparag.todoist.utils.ReactiveListEvent
import com.android.szparag.todoist.utils.ReactiveMutableList
import com.android.szparag.todoist.utils.range
import com.android.szparag.todoist.utils.weekAsDays
import io.reactivex.Completable
import io.reactivex.Observable
import org.joda.time.LocalDate
import java.util.Locale
import java.util.Random


//todo: locale is useless here
//todo: or is it not?

private const val INITIAL_DAYS_CAPACITY = 7 * 8

class TodoistCalendarModel(private var locale: Locale) : CalendarModel {

  override val logger by lazy { Logger.create(this::class.java, this.hashCode()) }
  private lateinit var currentDay: LocalDate
  private val random by lazy { Random() }
  private val datesList: ReactiveList<LocalDate> = ReactiveMutableList(INITIAL_DAYS_CAPACITY, true)

  override fun attach(): Completable {
    logger.debug("attach")
    return Completable.fromAction {
      setupCalendarInstance()
      logger.debug("attach.action.finished")
    }
  }

  override fun detach(): Completable = Completable.fromAction { logger.debug("detach") }

  override fun subscribeForDaysListEvents(): Observable<ReactiveListEvent> {
    logger.debug("subscribeForDaysListEvents")
    return datesList.subscribeForListEvents()
  }

  override fun subscribeForDaysListData(): Observable<ReactiveList<LocalDate>> {
    logger.debug("subscribeForDaysListData")
    return datesList.subscribeForListData()
  }

  override fun requestRelativeWeekAsDays(weekForward: Boolean, fetchMultiplier: Int) {
    logger.debug("requestRelativeWeekAsDays, weekForward: $weekForward, fetchMultiplier: $fetchMultiplier")
    val boundaryLocalDate = datesList.boundary(weekForward)
    range(0, fetchMultiplier - 2).forEach { weekIndex -> //todo range 0 fetch-2 is little ambiguous, make it more readable
      val appendingLocalDates = boundaryLocalDate.plusWeeks(weekIndex).plusDays(1).weekAsDays()
      datesList.insert(appendingLocalDates)
      logger.debug("requestRelativeWeekAsDays, index: $weekIndex, appending: $appendingLocalDates")
    }.also {
      logger.debug("requestRelativeWeekAsDays, datesList: $datesList")
    }
  }

  override fun setupCalendarInstance() {
{'fraction_non_alphanumeric': 0.0940870954854175, 'fraction_numerical': 0.0021973631642029563, 'mean_word_length': 5.4192307692307695, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '6444841', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1471, 'n_words': 295}