统计页重构:去掉顶部区间筛选,分布卡新增日/周/月/年与翻页,环形图改为引线标注并显示时长

This commit is contained in:
XIGE
2026-11-28 02:05:52 +08:00
parent e1087cfd41
commit f60b2956d4
8 changed files with 594 additions and 297 deletions

View File

@@ -467,17 +467,22 @@ object Store {
return out
}
fun distribution(fromMs: Long): List<ProjectSlice> { val list = ArrayList<ProjectSlice>()
/**
* 按项目汇总的专注时长,区间是左闭右开 [fromMs, toMs)。
* 统计页的日/周/月/年四档都要能看历史区间,所以必须带上界;
* 只给下界的话「11月26日」会一路把 26 号之后的记录也算进来。
*/
fun distribution(fromMs: Long, toMs: Long): List<ProjectSlice> { val list = ArrayList<ProjectSlice>()
db.rawQuery(
"""
SELECT COALESCE(p._id, 0), COALESCE(p.name, '未归类'), COALESCE(p.color, -1),
IFNULL(SUM(s.seconds),0), IFNULL(SUM(CASE WHEN s.completed = 1 THEN 1 ELSE 0 END),0)
FROM sessions s LEFT JOIN projects p ON p._id = s.project_id
WHERE s.start_at >= ?
WHERE s.start_at >= ? AND s.start_at < ?
GROUP BY s.project_id HAVING SUM(s.seconds) > 0
ORDER BY 4 DESC
""".trimIndent(),
arrayOf(fromMs.toString())
arrayOf(fromMs.toString(), toMs.toString())
).use { c ->
while (c.moveToNext()) {
list.add(
@@ -494,8 +499,8 @@ object Store {
return list
}
/** 按任务汇总的专注时长,用于统计页的"任务分布" */
fun taskSlices(fromMs: Long): List<ProjectSlice> {
/** 按任务汇总的专注时长,区间同样是 [fromMs, toMs) */
fun taskSlices(fromMs: Long, toMs: Long): List<ProjectSlice> {
val list = ArrayList<ProjectSlice>()
db.rawQuery(
"""
@@ -504,11 +509,11 @@ object Store {
FROM sessions s
LEFT JOIN tasks t ON t._id = s.task_id
LEFT JOIN projects p ON p._id = t.project_id
WHERE s.start_at >= ?
WHERE s.start_at >= ? AND s.start_at < ?
GROUP BY s.task_id HAVING SUM(s.seconds) > 0
ORDER BY 4 DESC
""".trimIndent(),
arrayOf(fromMs.toString())
arrayOf(fromMs.toString(), toMs.toString())
).use { c ->
while (c.moveToNext()) {
list.add(