饼图按系列根任务与任务当前项目归并,选择器改为立即创建(v3.11)
This commit is contained in:
@@ -799,15 +799,24 @@ object Store {
|
||||
* 按项目汇总的专注时长,区间是左闭右开 [fromMs, toMs)。
|
||||
* 统计页的日/周/月/年四档都要能看历史区间,所以必须带上界;
|
||||
* 只给下界的话「11月26日」会一路把 26 号之后的记录也算进来。
|
||||
*
|
||||
* 归属以任务当前所在项目为准(`t.project_id`),session 里的 `project_id`
|
||||
* 只是写入当时的快照:任务换过项目、或项目被删(任务被移到未分类)之后,
|
||||
* 快照会指向已不存在的项目,整块变成「未归类」,与任务饼图对不上。
|
||||
* 任务已删除(`task_id = 0`)时才退回快照。
|
||||
*/
|
||||
fun distribution(fromMs: Long, toMs: Long): List<ProjectSlice> { val list = ArrayList<ProjectSlice>()
|
||||
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),
|
||||
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
|
||||
FROM sessions s
|
||||
LEFT JOIN tasks t ON t._id = s.task_id
|
||||
LEFT JOIN projects p
|
||||
ON p._id = CASE WHEN t._id IS NOT NULL THEN t.project_id ELSE s.project_id END
|
||||
WHERE s.start_at >= ? AND s.start_at < ?
|
||||
GROUP BY s.project_id HAVING SUM(s.seconds) > 0
|
||||
GROUP BY COALESCE(p._id, 0) HAVING SUM(s.seconds) > 0
|
||||
ORDER BY 4 DESC
|
||||
""".trimIndent(),
|
||||
arrayOf(fromMs.toString(), toMs.toString())
|
||||
@@ -827,18 +836,30 @@ object Store {
|
||||
return list
|
||||
}
|
||||
|
||||
/** 按任务汇总的专注时长,区间同样是 [fromMs, toMs) */
|
||||
/**
|
||||
* 按任务汇总的专注时长,区间同样是 [fromMs, toMs)。
|
||||
*
|
||||
* 一个「任务」在库里可能是多行:重复任务每个周期生成一条实例(`origin_id` 指回根任务),
|
||||
* 每次专注结束还会写一条完成记录副本。如果按 `s.task_id` 原样分组,同名的任务会被
|
||||
* 拆成好几块(每块只统计到自己那份时长),看起来就是「有些任务统计不到」。
|
||||
* 因此统一归到系列根任务(`origin_id = 0` 那一条)再分组,名称与颜色也取根任务。
|
||||
*/
|
||||
fun taskSlices(fromMs: Long, toMs: Long): List<ProjectSlice> {
|
||||
val list = ArrayList<ProjectSlice>()
|
||||
db.rawQuery(
|
||||
"""
|
||||
SELECT COALESCE(t._id, 0), COALESCE(t.title, '未关联任务'), COALESCE(p.color, -1),
|
||||
SELECT COALESCE(root._id, t._id, 0),
|
||||
COALESCE(root.title, t.title, '未关联任务'),
|
||||
COALESCE(p.color, -1),
|
||||
IFNULL(SUM(s.seconds),0), COUNT(*)
|
||||
FROM sessions s
|
||||
LEFT JOIN tasks t ON t._id = s.task_id
|
||||
LEFT JOIN projects p ON p._id = t.project_id
|
||||
LEFT JOIN tasks root
|
||||
ON root._id = CASE WHEN t.origin_id > 0 THEN t.origin_id ELSE t._id END
|
||||
LEFT JOIN projects p
|
||||
ON p._id = COALESCE(root.project_id, t.project_id)
|
||||
WHERE s.start_at >= ? AND s.start_at < ?
|
||||
GROUP BY s.task_id HAVING SUM(s.seconds) > 0
|
||||
GROUP BY COALESCE(root._id, t._id, 0) HAVING SUM(s.seconds) > 0
|
||||
ORDER BY 4 DESC
|
||||
""".trimIndent(),
|
||||
arrayOf(fromMs.toString(), toMs.toString())
|
||||
|
||||
Reference in New Issue
Block a user