mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
start score from 1.0 for at most and reflect the same in history
This commit is contained in:
@@ -31,5 +31,6 @@ data class CreateHabitCommand(
|
||||
val habit = modelFactory.buildHabit()
|
||||
habit.copyFrom(model)
|
||||
habitList.add(habit)
|
||||
habit.recompute()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,9 +90,10 @@ data class Habit(
|
||||
isNumerical = isNumerical,
|
||||
)
|
||||
|
||||
val to = DateUtils.getTodayWithOffset().plus(30)
|
||||
val today = DateUtils.getTodayWithOffset()
|
||||
val to = today.plus(30)
|
||||
val entries = computedEntries.getKnown()
|
||||
var from = entries.lastOrNull()?.timestamp ?: to
|
||||
var from = entries.lastOrNull()?.timestamp ?: today
|
||||
if (from.isNewerThan(to)) from = to
|
||||
|
||||
scores.recompute(
|
||||
|
||||
@@ -75,13 +75,12 @@ class ScoreList {
|
||||
to: Timestamp,
|
||||
) {
|
||||
map.clear()
|
||||
if (computedEntries.getKnown().isEmpty()) return
|
||||
if (from.isNewerThan(to)) return
|
||||
var rollingSum = 0.0
|
||||
var numerator = frequency.numerator
|
||||
var denominator = frequency.denominator
|
||||
val freq = frequency.toDouble()
|
||||
val values = computedEntries.getByInterval(from, to).map { it.value }.toIntArray()
|
||||
val isAtMost = numericalHabitType == NumericalHabitType.AT_MOST
|
||||
|
||||
// For non-daily boolean habits, we double the numerator and the denominator to smooth
|
||||
// out irregular repetition schedules (for example, weekly habits performed on different
|
||||
@@ -91,7 +90,7 @@ class ScoreList {
|
||||
denominator *= 2
|
||||
}
|
||||
|
||||
var previousValue = 0.0
|
||||
var previousValue = if (isNumerical && isAtMost) 1.0 else 0.0
|
||||
for (i in values.indices) {
|
||||
val offset = values.size - i - 1
|
||||
if (isNumerical) {
|
||||
@@ -101,7 +100,7 @@ class ScoreList {
|
||||
}
|
||||
|
||||
val normalizedRollingSum = rollingSum / 1000
|
||||
val percentageCompleted = if (numericalHabitType == NumericalHabitType.AT_LEAST) {
|
||||
val percentageCompleted = if (!isAtMost) {
|
||||
if (targetValue > 0)
|
||||
min(1.0, normalizedRollingSum / targetValue)
|
||||
else
|
||||
|
||||
@@ -45,6 +45,7 @@ data class HistoryCardState(
|
||||
val color: PaletteColor,
|
||||
val firstWeekday: DayOfWeek,
|
||||
val series: List<HistoryChart.Square>,
|
||||
val defaultSquare: HistoryChart.Square,
|
||||
val theme: Theme,
|
||||
val today: LocalDate,
|
||||
)
|
||||
@@ -131,6 +132,10 @@ class HistoryCardPresenter(
|
||||
}
|
||||
}
|
||||
}
|
||||
val defaultSquare = if (habit.isNumerical && habit.targetType == NumericalHabitType.AT_MOST)
|
||||
HistoryChart.Square.ON
|
||||
else
|
||||
HistoryChart.Square.OFF
|
||||
|
||||
return HistoryCardState(
|
||||
color = habit.color,
|
||||
@@ -138,6 +143,7 @@ class HistoryCardPresenter(
|
||||
today = today.toLocalDate(),
|
||||
theme = theme,
|
||||
series = series,
|
||||
defaultSquare = defaultSquare
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ class HistoryChart(
|
||||
var firstWeekday: DayOfWeek,
|
||||
var paletteColor: PaletteColor,
|
||||
var series: List<Square>,
|
||||
var defaultSquare: Square,
|
||||
var theme: Theme,
|
||||
var today: LocalDate,
|
||||
var onDateClickedListener: OnDateClickedListener = OnDateClickedListener { },
|
||||
@@ -189,7 +190,7 @@ class HistoryChart(
|
||||
offset: Int,
|
||||
) {
|
||||
|
||||
val value = if (offset >= series.size) Square.OFF else series[offset]
|
||||
val value = if (offset >= series.size) defaultSquare else series[offset]
|
||||
val squareColor: Color
|
||||
val color = theme.color(paletteColor.paletteIndex)
|
||||
squareColor = when (value) {
|
||||
|
||||
@@ -49,6 +49,7 @@ class HistoryChartTest {
|
||||
dateFormatter = JavaLocalDateFormatter(Locale.US),
|
||||
firstWeekday = SUNDAY,
|
||||
onDateClickedListener = dateClickedListener,
|
||||
defaultSquare = OFF,
|
||||
series = listOf(
|
||||
2, // today
|
||||
2, 1, 2, 1, 2, 1, 2,
|
||||
|
||||
Reference in New Issue
Block a user