fix: Fix incorrect average being calculated
This commit is contained in:
@@ -42,11 +42,15 @@ interface StatDao {
|
|||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT " +
|
"SELECT " +
|
||||||
"AVG(NULLIF(focusTimeQ1,0)) AS focusTimeQ1, " +
|
"AVG(focusTimeQ1) AS focusTimeQ1, " +
|
||||||
"AVG(NULLIF(focusTimeQ2,0)) AS focusTimeQ2, " +
|
"AVG(focusTimeQ2) AS focusTimeQ2, " +
|
||||||
"AVG(NULLIF(focusTimeQ3,0)) AS focusTimeQ3, " +
|
"AVG(focusTimeQ3) AS focusTimeQ3, " +
|
||||||
"AVG(NULLIF(focusTimeQ4,0)) AS focusTimeQ4 " +
|
"AVG(focusTimeQ4) AS focusTimeQ4 " +
|
||||||
"FROM (SELECT focusTimeQ1, focusTimeQ2, focusTimeQ3, focusTimeQ4 FROM stat ORDER BY date DESC LIMIT :n)"
|
"FROM (" +
|
||||||
|
"SELECT focusTimeQ1, focusTimeQ2, focusTimeQ3, focusTimeQ4 FROM stat " +
|
||||||
|
"WHERE focusTimeQ1 != 0 OR focusTimeQ2 != 0 OR focusTimeQ3 != 0 OR focusTimeQ4 != 0 " +
|
||||||
|
"ORDER BY date DESC LIMIT :n" +
|
||||||
|
")"
|
||||||
)
|
)
|
||||||
fun getLastNDaysAvgFocusTimes(n: Int): Flow<StatFocusTime?>
|
fun getLastNDaysAvgFocusTimes(n: Int): Flow<StatFocusTime?>
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,11 @@
|
|||||||
|
|
||||||
package org.nsh07.pomodoro.ui.statsScreen
|
package org.nsh07.pomodoro.ui.statsScreen
|
||||||
|
|
||||||
import android.graphics.Path
|
|
||||||
import android.graphics.RectF
|
|
||||||
import androidx.compose.animation.core.AnimationSpec
|
import androidx.compose.animation.core.AnimationSpec
|
||||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||||
import androidx.compose.material3.MaterialTheme.motionScheme
|
import androidx.compose.material3.MaterialTheme.motionScheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.patrykandpatrick.vico.compose.cartesian.CartesianChartHost
|
import com.patrykandpatrick.vico.compose.cartesian.CartesianChartHost
|
||||||
@@ -35,6 +32,7 @@ import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer
|
|||||||
import com.patrykandpatrick.vico.core.cartesian.data.CartesianValueFormatter
|
import com.patrykandpatrick.vico.core.cartesian.data.CartesianValueFormatter
|
||||||
import com.patrykandpatrick.vico.core.cartesian.layer.ColumnCartesianLayer
|
import com.patrykandpatrick.vico.core.cartesian.layer.ColumnCartesianLayer
|
||||||
import com.patrykandpatrick.vico.core.common.Fill
|
import com.patrykandpatrick.vico.core.common.Fill
|
||||||
|
import com.patrykandpatrick.vico.core.common.shape.CorneredShape
|
||||||
import org.nsh07.pomodoro.utils.millisecondsToHours
|
import org.nsh07.pomodoro.utils.millisecondsToHours
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||||
@@ -50,9 +48,6 @@ internal fun TimeColumnChart(
|
|||||||
},
|
},
|
||||||
animationSpec: AnimationSpec<Float>? = motionScheme.slowEffectsSpec()
|
animationSpec: AnimationSpec<Float>? = motionScheme.slowEffectsSpec()
|
||||||
) {
|
) {
|
||||||
val radius = with(LocalDensity.current) {
|
|
||||||
(thickness / 2).toPx()
|
|
||||||
}
|
|
||||||
ProvideVicoTheme(rememberM3VicoTheme()) {
|
ProvideVicoTheme(rememberM3VicoTheme()) {
|
||||||
CartesianChartHost(
|
CartesianChartHost(
|
||||||
chart =
|
chart =
|
||||||
@@ -63,29 +58,7 @@ internal fun TimeColumnChart(
|
|||||||
rememberLineComponent(
|
rememberLineComponent(
|
||||||
fill = fill(color),
|
fill = fill(color),
|
||||||
thickness = thickness,
|
thickness = thickness,
|
||||||
shape = { _, path, left, top, right, bottom ->
|
shape = CorneredShape.Pill
|
||||||
if (top + radius <= bottom - radius) {
|
|
||||||
path.arcTo(
|
|
||||||
RectF(left, top, right, top + 2 * radius),
|
|
||||||
180f,
|
|
||||||
180f
|
|
||||||
)
|
|
||||||
path.lineTo(right, bottom - radius)
|
|
||||||
path.arcTo(
|
|
||||||
RectF(left, bottom - 2 * radius, right, bottom),
|
|
||||||
0f,
|
|
||||||
180f
|
|
||||||
)
|
|
||||||
path.close()
|
|
||||||
} else {
|
|
||||||
path.addCircle(
|
|
||||||
left + radius,
|
|
||||||
bottom - radius,
|
|
||||||
radius,
|
|
||||||
Path.Direction.CW
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user