Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New way of habit status computation #6

Merged
merged 22 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
## 2024-01-07

- Updated the core functionality of the app to compute habit statuses on the go instead of caching them in the database. This change improves the robustness and clarity of the code.
- Refactored 'Routine' to 'Habit' across the application for better semantics.
- Improved performance by computing each date in a separate coroutine and introduced pagination for the RoutineCalendarScreen.
- Fixed various minor bugs and performance issues.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import android.app.Application
import com.rendox.routinetracker.core.data.di.completionHistoryDataModule
import com.rendox.routinetracker.core.data.di.completionTimeDataModule
import com.rendox.routinetracker.core.data.di.routineDataModule
import com.rendox.routinetracker.core.data.di.streakDataModule
import com.rendox.routinetracker.core.data.di.vacationDataModule
import com.rendox.routinetracker.core.database.di.localDataSourceModule
import com.rendox.routinetracker.core.domain.di.completionHistoryDomainModule
import com.rendox.routinetracker.core.domain.di.routineDomainModule
import com.rendox.routinetracker.core.domain.di.streakDomainModule
import com.rendox.routinetracker.core.domain.di.habitDomainModule
import com.rendox.routinetracker.feature.agenda.di.agendaScreenModule
import com.rendox.routinetracker.routine_details.di.routineDetailsModule
import org.koin.android.ext.koin.androidContext
Expand All @@ -23,11 +22,10 @@ class RoutineTrackerApp: Application() {
localDataSourceModule,
routineDataModule,
completionHistoryDataModule,
streakDataModule,
completionTimeDataModule,
routineDomainModule,
vacationDataModule,
habitDomainModule,
completionHistoryDomainModule,
streakDomainModule,
agendaScreenModule,
routineDetailsModule,
)
Expand Down
Binary file not shown.
Binary file modified build-logic/convention/build/libs/convention.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,66 +1,41 @@
package com.rendox.routinetracker.core.data.completion_history

import com.rendox.routinetracker.core.logic.time.LocalDateRange
import com.rendox.routinetracker.core.model.CompletionHistoryEntry
import com.rendox.routinetracker.core.model.HistoricalStatus
import com.rendox.routinetracker.core.model.Habit
import kotlinx.datetime.LocalDate

interface CompletionHistoryRepository {
suspend fun getNumOfTimesCompletedInPeriod(
habitId: Long,
minDate: LocalDate?,
maxDate: LocalDate?,
): Double

suspend fun getHistoryEntries(
routineId: Long,
dates: LocalDateRange,
): List<CompletionHistoryEntry>

suspend fun getHistoryEntryByDate(
routineId: Long,
date: LocalDate,
): CompletionHistoryEntry?

suspend fun insertHistoryEntry(
id: Long? = null,
routineId: Long,
entry: CompletionHistoryEntry,
)

suspend fun deleteHistoryEntry(
routineId: Long,
date: LocalDate,
)

suspend fun updateHistoryEntryByDate(
routineId: Long,
date: LocalDate,
newStatus: HistoricalStatus? = null,
newScheduleDeviation: Float? = null,
newTimesCompleted: Float? = null,
)

suspend fun getFirstHistoryEntry(routineId: Long): CompletionHistoryEntry?
suspend fun getLastHistoryEntry(routineId: Long): CompletionHistoryEntry?

suspend fun checkIfStatusWasCompletedLater(routineId: Long, date: LocalDate): Boolean
suspend fun deleteCompletedLaterBackupEntry(routineId: Long, date: LocalDate)

suspend fun getFirstHistoryEntryByStatus(
routineId: Long,
matchingStatuses: List<HistoricalStatus>,
suspend fun getRecordByDate(habitId: Long, date: LocalDate): Habit.CompletionRecord?
suspend fun getLastCompletedRecord(
habitId: Long,
minDate: LocalDate? = null,
maxDate: LocalDate? = null,
): CompletionHistoryEntry?
): Habit.CompletionRecord?

suspend fun getLastHistoryEntryByStatus(
routineId: Long,
matchingStatuses: List<HistoricalStatus>,
suspend fun getFirstCompletedRecord(
habitId: Long,
minDate: LocalDate? = null,
maxDate: LocalDate? = null,
): CompletionHistoryEntry?
): Habit.CompletionRecord?

suspend fun getTotalTimesCompletedInPeriod(
routineId: Long, startDate: LocalDate, endDate: LocalDate
): Double
suspend fun getRecordsInPeriod(
habitId: Long,
minDate: LocalDate?,
maxDate: LocalDate?,
): List<Habit.CompletionRecord>

suspend fun getScheduleDeviationInPeriod(
routineId: Long, startDate: LocalDate, endDate: LocalDate
): Double
suspend fun insertCompletion(
habitId: Long,
completionRecord: Habit.CompletionRecord,
)

suspend fun deleteCompletionByDate(
habitId: Long,
date: LocalDate,
)
}
Original file line number Diff line number Diff line change
@@ -1,116 +1,59 @@
package com.rendox.routinetracker.core.data.completion_history

import com.rendox.routinetracker.core.database.completion_history.CompletionHistoryLocalDataSource
import com.rendox.routinetracker.core.logic.time.LocalDateRange
import com.rendox.routinetracker.core.model.CompletionHistoryEntry
import com.rendox.routinetracker.core.model.HistoricalStatus
import com.rendox.routinetracker.core.model.Habit
import kotlinx.datetime.LocalDate

class CompletionHistoryRepositoryImpl(
private val localDataSource: CompletionHistoryLocalDataSource,
) : CompletionHistoryRepository {

override suspend fun getHistoryEntries(
routineId: Long,
dates: LocalDateRange
): List<CompletionHistoryEntry> {
return localDataSource.getHistoryEntries(routineId, dates)
}

override suspend fun getHistoryEntryByDate(
routineId: Long,
date: LocalDate
): CompletionHistoryEntry? {
return localDataSource.getHistoryEntryByDate(routineId, date)
}

override suspend fun insertHistoryEntry(
id: Long?,
routineId: Long,
entry: CompletionHistoryEntry,
) {
localDataSource.insertHistoryEntry(
id = id,
routineId = routineId,
entry = entry,
private val localDataSource: CompletionHistoryLocalDataSource
): CompletionHistoryRepository {
override suspend fun getNumOfTimesCompletedInPeriod(
habitId: Long,
minDate: LocalDate?,
maxDate: LocalDate?
): Double {
return localDataSource.getNumOfTimesCompletedInPeriod(
habitId, minDate, maxDate
)
}

override suspend fun deleteHistoryEntry(routineId: Long, date: LocalDate) {
localDataSource.deleteHistoryEntry(routineId, date)
}

override suspend fun updateHistoryEntryByDate(
routineId: Long,
date: LocalDate,
newStatus: HistoricalStatus?,
newScheduleDeviation: Float?,
newTimesCompleted: Float?,
) {
localDataSource.updateHistoryEntryByDate(
routineId = routineId,
date = date,
newStatus = newStatus,
newScheduleDeviation = newScheduleDeviation,
newTimesCompleted = newTimesCompleted,
override suspend fun getRecordByDate(habitId: Long, date: LocalDate): Habit.CompletionRecord? {
return localDataSource.getRecordByDate(
habitId, date
)
}

override suspend fun getFirstHistoryEntry(routineId: Long): CompletionHistoryEntry? {
return localDataSource.getFirstHistoryEntry(routineId)
}

override suspend fun getLastHistoryEntry(routineId: Long): CompletionHistoryEntry? {
return localDataSource.getLastHistoryEntry(routineId)
}

override suspend fun checkIfStatusWasCompletedLater(routineId: Long, date: LocalDate): Boolean {
return localDataSource.checkIfStatusWasCompletedLater(routineId, date)
}

override suspend fun deleteCompletedLaterBackupEntry(routineId: Long, date: LocalDate) {
localDataSource.deleteCompletedLaterBackupEntry(routineId, date)
override suspend fun getLastCompletedRecord(
habitId: Long,
minDate: LocalDate?,
maxDate: LocalDate?,
): Habit.CompletionRecord? {
return localDataSource.getLastCompletedRecord(habitId, minDate, maxDate)
}

override suspend fun getFirstHistoryEntryByStatus(
routineId: Long,
matchingStatuses: List<HistoricalStatus>,
override suspend fun getFirstCompletedRecord(
habitId: Long,
minDate: LocalDate?,
maxDate: LocalDate?,
): CompletionHistoryEntry? {
return localDataSource.getFirstHistoryEntryByStatus(
routineId = routineId,
matchingStatuses = matchingStatuses,
minDate = minDate,
maxDate = maxDate,
)
): Habit.CompletionRecord? {
return localDataSource.getFirstCompletedRecord(habitId, minDate, maxDate)
}

override suspend fun getLastHistoryEntryByStatus(
routineId: Long,
matchingStatuses: List<HistoricalStatus>,
override suspend fun getRecordsInPeriod(
habitId: Long,
minDate: LocalDate?,
maxDate: LocalDate?,
): CompletionHistoryEntry? = localDataSource.getLastHistoryEntryByStatus(
routineId = routineId,
matchingStatuses = matchingStatuses,
minDate = minDate,
maxDate = maxDate,
)

override suspend fun getTotalTimesCompletedInPeriod(
routineId: Long, startDate: LocalDate, endDate: LocalDate
): Double {
return localDataSource.getTotalTimesCompletedInPeriod(
routineId, startDate, endDate
): List<Habit.CompletionRecord> {
return localDataSource.getRecordsInPeriod(
habitId, minDate, maxDate
)
}

override suspend fun getScheduleDeviationInPeriod(
routineId: Long, startDate: LocalDate, endDate: LocalDate
): Double {
return localDataSource.getScheduleDeviationInPeriod(
routineId, startDate, endDate
)
override suspend fun insertCompletion(habitId: Long, completionRecord: Habit.CompletionRecord) {
localDataSource.insertCompletion(habitId, completionRecord)
}

override suspend fun deleteCompletionByDate(habitId: Long, date: LocalDate) {
localDataSource.deleteCompletionByDate(habitId, date)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import com.rendox.routinetracker.core.database.completion_history.CompletionHist
import org.koin.dsl.module

val completionHistoryDataModule = module {

single<CompletionHistoryLocalDataSource> {
CompletionHistoryLocalDataSourceImpl(db = get(), dispatcher = get())
CompletionHistoryLocalDataSourceImpl(db = get())
}

single<CompletionHistoryRepository> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.koin.dsl.module
val completionTimeDataModule = module {

single<CompletionTimeLocalDataSource> {
CompletionTimeLocalDataSourceImpl(db = get(), dispatcher = get())
CompletionTimeLocalDataSourceImpl(db = get())
}

single<CompletionTimeRepository> {
Expand Down
Loading