Expand description
Parent-child containment model and goal progress computation.
This module provides higher-level query functions that operate on the SQLite projection database to answer hierarchy questions:
- Which items are children of a given goal?
- What is a goal’s progress (done/total direct children)?
- What is a goal’s recursive progress (rolling up through nested goals)?
- Is a reparenting operation valid?
- What is the full subtree of a given item?
- What are the ancestors of a given item?
§Terminology
- Parent: An item whose
parent_idis null (root) or set to another item. - Goal: An item with
kind = 'goal'. Only goals may have children (reparenting to a non-goal is rejected). - Progress: The ratio of done (or archived) children to total non-deleted children. Nested goals contribute their own progress recursively.
§Cycle prevention
validate_reparent checks that the proposed new parent is not a descendant
of the item being moved, preventing reference cycles.
§Error handling
All functions return HierarchyError, which distinguishes between
domain errors (wrong kind, cycle detected, item not found) and database
errors.
Structs§
- Goal
Progress - Progress of a goal: how many children are done vs total.
Enums§
- Hierarchy
Error - Errors that can occur in hierarchy operations.
Functions§
- compute_
direct_ progress - Compute the direct progress of a goal: counts its immediate children.
- compute_
nested_ progress - Compute the nested progress of a goal, rolling up through the entire subtree.
- get_
ancestors - Get the ancestor chain of an item, from immediate parent up to root.
- get_
subtree_ ids - Get all item IDs in the subtree rooted at
root_id, includingroot_iditself. - validate_
reparent - Validate that reparenting
item_idundernew_parent_idis allowed.