mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-15 21:48:50 -06:00
Implement score and frequency widgets for habit groups
This commit is contained in:
@@ -54,14 +54,7 @@ class FrequencyCardPresenter {
|
||||
firstWeekday: Int,
|
||||
theme: Theme
|
||||
): FrequencyCardState {
|
||||
val normalizedEntries = habitGroup.habitList.map {
|
||||
it.computedEntries.normalizeEntries(it.isNumerical, it.frequency, it.targetValue)
|
||||
}
|
||||
val frequencies = normalizedEntries.map {
|
||||
it.computeWeekdayFrequency(isNumerical = true)
|
||||
}.reduce { acc, hashMap ->
|
||||
mergeMaps(acc, hashMap) { value1, value2 -> addArray(value1, value2) }
|
||||
}
|
||||
val frequencies = getFrequenciesFromHabitGroup(habitGroup)
|
||||
|
||||
return FrequencyCardState(
|
||||
color = habitGroup.color,
|
||||
@@ -72,6 +65,18 @@ class FrequencyCardPresenter {
|
||||
)
|
||||
}
|
||||
|
||||
fun getFrequenciesFromHabitGroup(habitGroup: HabitGroup): HashMap<Timestamp, Array<Int>> {
|
||||
val normalizedEntries = habitGroup.habitList.map {
|
||||
it.computedEntries.normalizeEntries(it.isNumerical, it.frequency, it.targetValue)
|
||||
}
|
||||
val frequencies = normalizedEntries.map {
|
||||
it.computeWeekdayFrequency(isNumerical = true)
|
||||
}.reduce { acc, hashMap ->
|
||||
mergeMaps(acc, hashMap) { value1, value2 -> addArray(value1, value2) }
|
||||
}
|
||||
return frequencies
|
||||
}
|
||||
|
||||
private fun <K, V> mergeMaps(map1: HashMap<K, V>, map2: HashMap<K, V>, mergeFunction: (V, V) -> V): HashMap<K, V> {
|
||||
val result = map1 // Step 1
|
||||
for ((key, value) in map2) { // Step 2
|
||||
|
||||
Reference in New Issue
Block a user