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:
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.9 KiB |
@@ -62,6 +62,7 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
|||||||
firstWeekday = preferences.firstWeekday,
|
firstWeekday = preferences.firstWeekday,
|
||||||
paletteColor = habit.color,
|
paletteColor = habit.color,
|
||||||
series = emptyList(),
|
series = emptyList(),
|
||||||
|
defaultSquare = HistoryChart.Square.OFF,
|
||||||
theme = themeSwitcher.currentTheme,
|
theme = themeSwitcher.currentTheme,
|
||||||
today = DateUtils.getTodayWithOffset().toLocalDate(),
|
today = DateUtils.getTodayWithOffset().toLocalDate(),
|
||||||
onDateClickedListener = onDateClickedListener ?: OnDateClickedListener { },
|
onDateClickedListener = onDateClickedListener ?: OnDateClickedListener { },
|
||||||
@@ -101,6 +102,7 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
|||||||
theme = LightTheme()
|
theme = LightTheme()
|
||||||
)
|
)
|
||||||
chart?.series = model.series
|
chart?.series = model.series
|
||||||
|
chart?.defaultSquare = model.defaultSquare
|
||||||
dataView.postInvalidate()
|
dataView.postInvalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,14 +162,14 @@ class NumberButtonView(
|
|||||||
fun draw(canvas: Canvas) {
|
fun draw(canvas: Canvas) {
|
||||||
var activeColor = if (targetType == NumericalHabitType.AT_LEAST) {
|
var activeColor = if (targetType == NumericalHabitType.AT_LEAST) {
|
||||||
when {
|
when {
|
||||||
|
value < 0.0 && preferences.areQuestionMarksEnabled -> lowContrast
|
||||||
max(0.0, value) >= threshold -> color
|
max(0.0, value) >= threshold -> color
|
||||||
value <= 0 -> lowContrast
|
|
||||||
else -> mediumContrast
|
else -> mediumContrast
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
when {
|
when {
|
||||||
|
value < 0.0 && preferences.areQuestionMarksEnabled -> lowContrast
|
||||||
value <= threshold -> color
|
value <= threshold -> color
|
||||||
value >= 2 * threshold -> lowContrast
|
|
||||||
else -> mediumContrast
|
else -> mediumContrast
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class HistoryCardView(context: Context, attrs: AttributeSet) : LinearLayout(cont
|
|||||||
theme = state.theme,
|
theme = state.theme,
|
||||||
dateFormatter = JavaLocalDateFormatter(Locale.getDefault()),
|
dateFormatter = JavaLocalDateFormatter(Locale.getDefault()),
|
||||||
series = state.series,
|
series = state.series,
|
||||||
|
defaultSquare = state.defaultSquare,
|
||||||
firstWeekday = state.firstWeekday,
|
firstWeekday = state.firstWeekday,
|
||||||
)
|
)
|
||||||
binding.chart.postInvalidate()
|
binding.chart.postInvalidate()
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ class HistoryWidget(
|
|||||||
theme = WidgetTheme(),
|
theme = WidgetTheme(),
|
||||||
)
|
)
|
||||||
(widgetView.dataView as AndroidDataView).apply {
|
(widgetView.dataView as AndroidDataView).apply {
|
||||||
(this.view as HistoryChart).series = model.series
|
val historyChart = (this.view as HistoryChart)
|
||||||
|
historyChart.series = model.series
|
||||||
|
historyChart.defaultSquare = model.defaultSquare
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +73,7 @@ class HistoryWidget(
|
|||||||
dateFormatter = JavaLocalDateFormatter(Locale.getDefault()),
|
dateFormatter = JavaLocalDateFormatter(Locale.getDefault()),
|
||||||
firstWeekday = prefs.firstWeekday,
|
firstWeekday = prefs.firstWeekday,
|
||||||
series = listOf(),
|
series = listOf(),
|
||||||
|
defaultSquare = HistoryChart.Square.OFF,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
).apply {
|
).apply {
|
||||||
|
|||||||
@@ -31,5 +31,6 @@ data class CreateHabitCommand(
|
|||||||
val habit = modelFactory.buildHabit()
|
val habit = modelFactory.buildHabit()
|
||||||
habit.copyFrom(model)
|
habit.copyFrom(model)
|
||||||
habitList.add(habit)
|
habitList.add(habit)
|
||||||
|
habit.recompute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,9 +90,10 @@ data class Habit(
|
|||||||
isNumerical = isNumerical,
|
isNumerical = isNumerical,
|
||||||
)
|
)
|
||||||
|
|
||||||
val to = DateUtils.getTodayWithOffset().plus(30)
|
val today = DateUtils.getTodayWithOffset()
|
||||||
|
val to = today.plus(30)
|
||||||
val entries = computedEntries.getKnown()
|
val entries = computedEntries.getKnown()
|
||||||
var from = entries.lastOrNull()?.timestamp ?: to
|
var from = entries.lastOrNull()?.timestamp ?: today
|
||||||
if (from.isNewerThan(to)) from = to
|
if (from.isNewerThan(to)) from = to
|
||||||
|
|
||||||
scores.recompute(
|
scores.recompute(
|
||||||
|
|||||||
@@ -75,13 +75,12 @@ class ScoreList {
|
|||||||
to: Timestamp,
|
to: Timestamp,
|
||||||
) {
|
) {
|
||||||
map.clear()
|
map.clear()
|
||||||
if (computedEntries.getKnown().isEmpty()) return
|
|
||||||
if (from.isNewerThan(to)) return
|
|
||||||
var rollingSum = 0.0
|
var rollingSum = 0.0
|
||||||
var numerator = frequency.numerator
|
var numerator = frequency.numerator
|
||||||
var denominator = frequency.denominator
|
var denominator = frequency.denominator
|
||||||
val freq = frequency.toDouble()
|
val freq = frequency.toDouble()
|
||||||
val values = computedEntries.getByInterval(from, to).map { it.value }.toIntArray()
|
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
|
// 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
|
// out irregular repetition schedules (for example, weekly habits performed on different
|
||||||
@@ -91,7 +90,7 @@ class ScoreList {
|
|||||||
denominator *= 2
|
denominator *= 2
|
||||||
}
|
}
|
||||||
|
|
||||||
var previousValue = 0.0
|
var previousValue = if (isNumerical && isAtMost) 1.0 else 0.0
|
||||||
for (i in values.indices) {
|
for (i in values.indices) {
|
||||||
val offset = values.size - i - 1
|
val offset = values.size - i - 1
|
||||||
if (isNumerical) {
|
if (isNumerical) {
|
||||||
@@ -101,7 +100,7 @@ class ScoreList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val normalizedRollingSum = rollingSum / 1000
|
val normalizedRollingSum = rollingSum / 1000
|
||||||
val percentageCompleted = if (numericalHabitType == NumericalHabitType.AT_LEAST) {
|
val percentageCompleted = if (!isAtMost) {
|
||||||
if (targetValue > 0)
|
if (targetValue > 0)
|
||||||
min(1.0, normalizedRollingSum / targetValue)
|
min(1.0, normalizedRollingSum / targetValue)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ data class HistoryCardState(
|
|||||||
val color: PaletteColor,
|
val color: PaletteColor,
|
||||||
val firstWeekday: DayOfWeek,
|
val firstWeekday: DayOfWeek,
|
||||||
val series: List<HistoryChart.Square>,
|
val series: List<HistoryChart.Square>,
|
||||||
|
val defaultSquare: HistoryChart.Square,
|
||||||
val theme: Theme,
|
val theme: Theme,
|
||||||
val today: LocalDate,
|
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(
|
return HistoryCardState(
|
||||||
color = habit.color,
|
color = habit.color,
|
||||||
@@ -138,6 +143,7 @@ class HistoryCardPresenter(
|
|||||||
today = today.toLocalDate(),
|
today = today.toLocalDate(),
|
||||||
theme = theme,
|
theme = theme,
|
||||||
series = series,
|
series = series,
|
||||||
|
defaultSquare = defaultSquare
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class HistoryChart(
|
|||||||
var firstWeekday: DayOfWeek,
|
var firstWeekday: DayOfWeek,
|
||||||
var paletteColor: PaletteColor,
|
var paletteColor: PaletteColor,
|
||||||
var series: List<Square>,
|
var series: List<Square>,
|
||||||
|
var defaultSquare: Square,
|
||||||
var theme: Theme,
|
var theme: Theme,
|
||||||
var today: LocalDate,
|
var today: LocalDate,
|
||||||
var onDateClickedListener: OnDateClickedListener = OnDateClickedListener { },
|
var onDateClickedListener: OnDateClickedListener = OnDateClickedListener { },
|
||||||
@@ -189,7 +190,7 @@ class HistoryChart(
|
|||||||
offset: Int,
|
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 squareColor: Color
|
||||||
val color = theme.color(paletteColor.paletteIndex)
|
val color = theme.color(paletteColor.paletteIndex)
|
||||||
squareColor = when (value) {
|
squareColor = when (value) {
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class HistoryChartTest {
|
|||||||
dateFormatter = JavaLocalDateFormatter(Locale.US),
|
dateFormatter = JavaLocalDateFormatter(Locale.US),
|
||||||
firstWeekday = SUNDAY,
|
firstWeekday = SUNDAY,
|
||||||
onDateClickedListener = dateClickedListener,
|
onDateClickedListener = dateClickedListener,
|
||||||
|
defaultSquare = OFF,
|
||||||
series = listOf(
|
series = listOf(
|
||||||
2, // today
|
2, // today
|
||||||
2, 1, 2, 1, 2, 1, 2,
|
2, 1, 2, 1, 2, 1, 2,
|
||||||
|
|||||||
Reference in New Issue
Block a user