deped-primitives 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deped_primitives-0.0.1/.editorconfig +18 -0
- deped_primitives-0.0.1/.github/workflows/ci.yml +35 -0
- deped_primitives-0.0.1/.gitignore +148 -0
- deped_primitives-0.0.1/.pre-commit-config.yaml +22 -0
- deped_primitives-0.0.1/AGENTS.md +27 -0
- deped_primitives-0.0.1/CHANGELOG.md +83 -0
- deped_primitives-0.0.1/PKG-INFO +151 -0
- deped_primitives-0.0.1/README.md +139 -0
- deped_primitives-0.0.1/docs/guide/filters.md +117 -0
- deped_primitives-0.0.1/docs/guide/hierarchies-and-region-groups.md +118 -0
- deped_primitives-0.0.1/docs/guide/legislative.md +54 -0
- deped_primitives-0.0.1/docs/guide/psgc-and-codes.md +96 -0
- deped_primitives-0.0.1/docs/guide/querying.md +85 -0
- deped_primitives-0.0.1/docs/guide/reference-vocabularies.md +72 -0
- deped_primitives-0.0.1/docs/index.md +70 -0
- deped_primitives-0.0.1/docs/reference/access.md +7 -0
- deped_primitives-0.0.1/docs/reference/codes.md +3 -0
- deped_primitives-0.0.1/docs/reference/education.md +3 -0
- deped_primitives-0.0.1/docs/reference/filters.md +13 -0
- deped_primitives-0.0.1/docs/reference/hierarchies.md +11 -0
- deped_primitives-0.0.1/docs/reference/legislative.md +19 -0
- deped_primitives-0.0.1/docs/reference/marimo.md +3 -0
- deped_primitives-0.0.1/docs/reference/psgc-lineage.md +3 -0
- deped_primitives-0.0.1/docs/reference/psgc.md +3 -0
- deped_primitives-0.0.1/docs/reference/region-groups.md +3 -0
- deped_primitives-0.0.1/docs/reference/regions.md +3 -0
- deped_primitives-0.0.1/docs/reference/school-sizes.md +3 -0
- deped_primitives-0.0.1/docs/reference/sql.md +13 -0
- deped_primitives-0.0.1/docs/status.md +78 -0
- deped_primitives-0.0.1/env.example +1 -0
- deped_primitives-0.0.1/justfile +29 -0
- deped_primitives-0.0.1/notebooks/school_area_explorer.py +25 -0
- deped_primitives-0.0.1/plans/01-init.md +387 -0
- deped_primitives-0.0.1/plans/02-cohesion.md +184 -0
- deped_primitives-0.0.1/plans/03-hardening.md +312 -0
- deped_primitives-0.0.1/plans/04-notebook.md +143 -0
- deped_primitives-0.0.1/pyproject.toml +43 -0
- deped_primitives-0.0.1/src/deped_primitives/__init__.py +3 -0
- deped_primitives-0.0.1/src/deped_primitives/access/__init__.py +34 -0
- deped_primitives-0.0.1/src/deped_primitives/access/locks.py +60 -0
- deped_primitives-0.0.1/src/deped_primitives/access/scope.py +445 -0
- deped_primitives-0.0.1/src/deped_primitives/codes/__init__.py +87 -0
- deped_primitives-0.0.1/src/deped_primitives/education/__init__.py +70 -0
- deped_primitives-0.0.1/src/deped_primitives/filters/__init__.py +88 -0
- deped_primitives-0.0.1/src/deped_primitives/filters/area_scope.py +236 -0
- deped_primitives-0.0.1/src/deped_primitives/filters/cascade.py +474 -0
- deped_primitives-0.0.1/src/deped_primitives/filters/membership.py +179 -0
- deped_primitives-0.0.1/src/deped_primitives/filters/models.py +141 -0
- deped_primitives-0.0.1/src/deped_primitives/filters/selections.py +176 -0
- deped_primitives-0.0.1/src/deped_primitives/hierarchies/__init__.py +159 -0
- deped_primitives-0.0.1/src/deped_primitives/hierarchies/aliases.py +27 -0
- deped_primitives-0.0.1/src/deped_primitives/hierarchies/definitions.py +229 -0
- deped_primitives-0.0.1/src/deped_primitives/hierarchies/graph.py +273 -0
- deped_primitives-0.0.1/src/deped_primitives/hierarchies/labels.py +325 -0
- deped_primitives-0.0.1/src/deped_primitives/legislative/__init__.py +198 -0
- deped_primitives-0.0.1/src/deped_primitives/legislative/coverage.py +598 -0
- deped_primitives-0.0.1/src/deped_primitives/legislative/data/legislative_coverage_rules.yml +1186 -0
- deped_primitives-0.0.1/src/deped_primitives/legislative/linkage.py +234 -0
- deped_primitives-0.0.1/src/deped_primitives/legislative/policy.py +311 -0
- deped_primitives-0.0.1/src/deped_primitives/legislative/special_cases.py +96 -0
- deped_primitives-0.0.1/src/deped_primitives/marimo/__init__.py +65 -0
- deped_primitives-0.0.1/src/deped_primitives/psgc/__init__.py +85 -0
- deped_primitives-0.0.1/src/deped_primitives/psgc/constants.py +89 -0
- deped_primitives-0.0.1/src/deped_primitives/psgc/core.py +321 -0
- deped_primitives-0.0.1/src/deped_primitives/psgc/exceptions.py +9 -0
- deped_primitives-0.0.1/src/deped_primitives/psgc/lineage.py +247 -0
- deped_primitives-0.0.1/src/deped_primitives/psgc/relations.py +147 -0
- deped_primitives-0.0.1/src/deped_primitives/psgc/types.py +22 -0
- deped_primitives-0.0.1/src/deped_primitives/region_groups/__init__.py +298 -0
- deped_primitives-0.0.1/src/deped_primitives/regions/__init__.py +145 -0
- deped_primitives-0.0.1/src/deped_primitives/school_sizes/__init__.py +110 -0
- deped_primitives-0.0.1/src/deped_primitives/sql/__init__.py +77 -0
- deped_primitives-0.0.1/src/deped_primitives/sql/builders.py +186 -0
- deped_primitives-0.0.1/src/deped_primitives/sql/choices.py +155 -0
- deped_primitives-0.0.1/src/deped_primitives/sql/clauses.py +233 -0
- deped_primitives-0.0.1/src/deped_primitives/sql/labels.py +55 -0
- deped_primitives-0.0.1/src/deped_primitives/sql/schema.py +73 -0
- deped_primitives-0.0.1/tests/__init__.py +0 -0
- deped_primitives-0.0.1/tests/fixtures/parity/filters/cascade_area_scope.json +47 -0
- deped_primitives-0.0.1/tests/fixtures/parity/generic/region_names.json +32 -0
- deped_primitives-0.0.1/tests/fixtures/parity/generic/school_grades.json +25 -0
- deped_primitives-0.0.1/tests/fixtures/parity/generic/school_sizes.json +29 -0
- deped_primitives-0.0.1/tests/fixtures/parity/legislative/coverage.json +23 -0
- deped_primitives-0.0.1/tests/fixtures/parity/legislative/value_primitives.json +21 -0
- deped_primitives-0.0.1/tests/fixtures/parity/sql/school_observations.json +29 -0
- deped_primitives-0.0.1/tests/fixtures/parity/sql/search_and_labels.json +24 -0
- deped_primitives-0.0.1/tests/test_access.py +335 -0
- deped_primitives-0.0.1/tests/test_codes.py +30 -0
- deped_primitives-0.0.1/tests/test_filters.py +314 -0
- deped_primitives-0.0.1/tests/test_generic_references.py +84 -0
- deped_primitives-0.0.1/tests/test_hierarchies.py +294 -0
- deped_primitives-0.0.1/tests/test_legislative.py +134 -0
- deped_primitives-0.0.1/tests/test_legislative_coverage.py +311 -0
- deped_primitives-0.0.1/tests/test_legislative_linkage.py +140 -0
- deped_primitives-0.0.1/tests/test_lineage.py +201 -0
- deped_primitives-0.0.1/tests/test_marimo_helpers.py +49 -0
- deped_primitives-0.0.1/tests/test_psgc_core.py +481 -0
- deped_primitives-0.0.1/tests/test_region_groups.py +189 -0
- deped_primitives-0.0.1/tests/test_runtime_guardrails.py +51 -0
- deped_primitives-0.0.1/tests/test_sql.py +248 -0
- deped_primitives-0.0.1/tests/test_version.py +13 -0
- deped_primitives-0.0.1/uv.lock +858 -0
- deped_primitives-0.0.1/zensical.toml +332 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# http://editorconfig.org
|
|
2
|
+
|
|
3
|
+
root = true
|
|
4
|
+
|
|
5
|
+
[*]
|
|
6
|
+
charset = utf-8
|
|
7
|
+
end_of_line = lf
|
|
8
|
+
indent_style = space
|
|
9
|
+
indent_size = 2
|
|
10
|
+
trim_trailing_whitespace = true
|
|
11
|
+
insert_final_newline = true
|
|
12
|
+
|
|
13
|
+
[*.py]
|
|
14
|
+
indent_size = 4
|
|
15
|
+
|
|
16
|
+
[*.{css,html,js,json,sass,scss,vue,yaml,yml}]
|
|
17
|
+
indent_style = space
|
|
18
|
+
indent_size = 2
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Example UV CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
uv-example:
|
|
11
|
+
name: Python (UV)
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout the repository
|
|
16
|
+
uses: actions/checkout@main
|
|
17
|
+
|
|
18
|
+
- name: Install the latest version of uv
|
|
19
|
+
uses: astral-sh/setup-uv@v7
|
|
20
|
+
with:
|
|
21
|
+
enable-cache: true
|
|
22
|
+
|
|
23
|
+
- name: Install the project with UV
|
|
24
|
+
run: uv sync --locked --all-extras --dev
|
|
25
|
+
|
|
26
|
+
- name: Install Dependencies
|
|
27
|
+
run: |
|
|
28
|
+
uv tool install pre-commit --with pre-commit-uv
|
|
29
|
+
pre-commit install-hooks
|
|
30
|
+
|
|
31
|
+
- name: Lint with pre-commit
|
|
32
|
+
run: pre-commit run --all-files
|
|
33
|
+
|
|
34
|
+
- name: Run tests
|
|
35
|
+
run: uv run pytest
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
.ruff_cache
|
|
3
|
+
*.sqlite
|
|
4
|
+
*.db
|
|
5
|
+
*.db-shm
|
|
6
|
+
*.db-wal
|
|
7
|
+
*.rdb
|
|
8
|
+
.env.*
|
|
9
|
+
__marimo__
|
|
10
|
+
|
|
11
|
+
# Byte-compiled / optimized / DLL files
|
|
12
|
+
__pycache__/
|
|
13
|
+
*.py[cod]
|
|
14
|
+
*$py.class
|
|
15
|
+
|
|
16
|
+
# C extensions
|
|
17
|
+
*.so
|
|
18
|
+
|
|
19
|
+
# Distribution / packaging
|
|
20
|
+
.Python
|
|
21
|
+
build/
|
|
22
|
+
develop-eggs/
|
|
23
|
+
dist/
|
|
24
|
+
downloads/
|
|
25
|
+
eggs/
|
|
26
|
+
.eggs/
|
|
27
|
+
lib/
|
|
28
|
+
lib64/
|
|
29
|
+
parts/
|
|
30
|
+
sdist/
|
|
31
|
+
var/
|
|
32
|
+
wheels/
|
|
33
|
+
share/python-wheels/
|
|
34
|
+
*.egg-info/
|
|
35
|
+
.installed.cfg
|
|
36
|
+
*.egg
|
|
37
|
+
MANIFEST
|
|
38
|
+
|
|
39
|
+
# PyInstaller
|
|
40
|
+
# Usually these files are written by a python script from a template
|
|
41
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
42
|
+
*.manifest
|
|
43
|
+
*.spec
|
|
44
|
+
|
|
45
|
+
# Installer logs
|
|
46
|
+
pip-log.txt
|
|
47
|
+
pip-delete-this-directory.txt
|
|
48
|
+
|
|
49
|
+
# Unit test / coverage reports
|
|
50
|
+
htmlcov/
|
|
51
|
+
.tox/
|
|
52
|
+
.nox/
|
|
53
|
+
.coverage
|
|
54
|
+
.coverage.*
|
|
55
|
+
.cache
|
|
56
|
+
nosetests.xml
|
|
57
|
+
coverage.xml
|
|
58
|
+
*.cover
|
|
59
|
+
*.py,cover
|
|
60
|
+
.hypothesis/
|
|
61
|
+
.pytest_cache/
|
|
62
|
+
cover/
|
|
63
|
+
|
|
64
|
+
# Translations
|
|
65
|
+
*.mo
|
|
66
|
+
*.pot
|
|
67
|
+
|
|
68
|
+
# Django stuff:
|
|
69
|
+
*.log
|
|
70
|
+
local_settings.py
|
|
71
|
+
db.sqlite3
|
|
72
|
+
db.sqlite3-journal
|
|
73
|
+
|
|
74
|
+
# Flask stuff:
|
|
75
|
+
instance/
|
|
76
|
+
.webassets-cache
|
|
77
|
+
|
|
78
|
+
# Scrapy stuff:
|
|
79
|
+
.scrapy
|
|
80
|
+
|
|
81
|
+
# Sphinx documentation
|
|
82
|
+
docs/_build/
|
|
83
|
+
|
|
84
|
+
# PyBuilder
|
|
85
|
+
.pybuilder/
|
|
86
|
+
target/
|
|
87
|
+
|
|
88
|
+
# Jupyter Notebook
|
|
89
|
+
.ipynb_checkpoints
|
|
90
|
+
|
|
91
|
+
# IPython
|
|
92
|
+
profile_default/
|
|
93
|
+
ipython_config.py
|
|
94
|
+
|
|
95
|
+
# pyenv
|
|
96
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
97
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
98
|
+
# .python-version
|
|
99
|
+
|
|
100
|
+
# pipenv
|
|
101
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
102
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
103
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
104
|
+
# install all needed dependencies.
|
|
105
|
+
#Pipfile.lock
|
|
106
|
+
|
|
107
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
108
|
+
__pypackages__/
|
|
109
|
+
|
|
110
|
+
# Celery stuff
|
|
111
|
+
celerybeat-schedule
|
|
112
|
+
celerybeat.pid
|
|
113
|
+
|
|
114
|
+
# SageMath parsed files
|
|
115
|
+
*.sage.py
|
|
116
|
+
|
|
117
|
+
# Environments
|
|
118
|
+
.env
|
|
119
|
+
.venv
|
|
120
|
+
env/
|
|
121
|
+
venv/
|
|
122
|
+
ENV/
|
|
123
|
+
env.bak/
|
|
124
|
+
venv.bak/
|
|
125
|
+
|
|
126
|
+
# Spyder project settings
|
|
127
|
+
.spyderproject
|
|
128
|
+
.spyproject
|
|
129
|
+
|
|
130
|
+
# Rope project settings
|
|
131
|
+
.ropeproject
|
|
132
|
+
|
|
133
|
+
# mkdocs documentation
|
|
134
|
+
/site
|
|
135
|
+
|
|
136
|
+
# mypy
|
|
137
|
+
.mypy_cache/
|
|
138
|
+
.dmypy.json
|
|
139
|
+
dmypy.json
|
|
140
|
+
|
|
141
|
+
# Pyre type checker
|
|
142
|
+
.pyre/
|
|
143
|
+
|
|
144
|
+
# pytype static type analyzer
|
|
145
|
+
.pytype/
|
|
146
|
+
|
|
147
|
+
# Cython debug symbols
|
|
148
|
+
cython_debug/
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
default_language_version:
|
|
2
|
+
python: python3.14
|
|
3
|
+
|
|
4
|
+
repos:
|
|
5
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
6
|
+
rev: v6.0.0
|
|
7
|
+
hooks:
|
|
8
|
+
- id: check-added-large-files
|
|
9
|
+
- id: end-of-file-fixer
|
|
10
|
+
- id: trailing-whitespace
|
|
11
|
+
- id: name-tests-test
|
|
12
|
+
args: ["--django"]
|
|
13
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
14
|
+
# Ruff version.
|
|
15
|
+
rev: v0.15.17
|
|
16
|
+
hooks:
|
|
17
|
+
# Run the linter.
|
|
18
|
+
- id: ruff-check
|
|
19
|
+
args: [--fix]
|
|
20
|
+
# Run the formatter.
|
|
21
|
+
- id: ruff-format
|
|
22
|
+
types_or: [python, pyi, jupyter]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Standards
|
|
2
|
+
|
|
3
|
+
## Start With The Docs
|
|
4
|
+
|
|
5
|
+
1. For new features, read the relevant docs before broad code search.
|
|
6
|
+
2. Start with `README.md`, `docs/index.md`.
|
|
7
|
+
4. Use the docs to identify likely app boundaries and entrypoints, then run targeted `rg` searches.
|
|
8
|
+
5. If behavior is not documented, inspect tests and implementation. Update docs when a change affects public concepts, routes, workflows, or commands.
|
|
9
|
+
|
|
10
|
+
## Valid Code
|
|
11
|
+
|
|
12
|
+
1. `except TypeError, ValueError` is valid in Python 3.14 and will compile, no need to fix.
|
|
13
|
+
2. If unnecessary, do not use lazy imports
|
|
14
|
+
3. After adding new feature, run `pre-commit run --all-files`, resolve any linting issues, then run `just check`
|
|
15
|
+
|
|
16
|
+
## Design Choices
|
|
17
|
+
|
|
18
|
+
1. Avoid pass-through adapters: do not add wrappers that merely rename, re-shape, or forward to another function unless they enforce a durable boundary, shared signature normalization, policy, validation, caching, logging, transactions, or meaningful repeated construction.
|
|
19
|
+
2. Prefer existing app boundaries, shell helpers, and documented integration patterns over new one-off service/helper layers.
|
|
20
|
+
3. When replacing an abstraction, update its callers and remove the obsolete layer in the same change.
|
|
21
|
+
4. Keep changes scoped. Avoid unrelated refactors, route churn, migration resets, generated-file churn, and developer-data changes unless explicitly requested.
|
|
22
|
+
|
|
23
|
+
## Commands And Verification
|
|
24
|
+
|
|
25
|
+
1. Use `uv run` and `just` recipes.
|
|
26
|
+
2. Routine check with `just check`.
|
|
27
|
+
4. Prefer targeted pytest slices for behavior changes.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
Post-parity hardening. Unlike the parity release, these are net-new APIs; each
|
|
6
|
+
lands with a named downstream consumer and its own fixtures, and the root package
|
|
7
|
+
still exposes only `__version__`. Planned hardening (legislative coverage
|
|
8
|
+
building and its YAML policy) is tracked in
|
|
9
|
+
[`docs/status.md`](docs/status.md).
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `deped_primitives.psgc.relations` with `is_valid_parent_child` (parent/child
|
|
14
|
+
validation across the NCR, HUC, Manila sub-municipality, and
|
|
15
|
+
municipality-collapse rules) and `breakdown` / `PsgcBreakdown` typed code
|
|
16
|
+
breakdowns for breadcrumb and drilldown context.
|
|
17
|
+
- `classify_lineage_delta` with `LineageDelta` / `LineageDeltaKind` in
|
|
18
|
+
`deped_primitives.psgc.lineage`, classifying resolved predecessor/successor
|
|
19
|
+
relationships as renamed, merged, split, transferred, or unchanged.
|
|
20
|
+
- `deped_primitives.hierarchies.graph` with the `HierarchyGraph` value object
|
|
21
|
+
(`cascade_path`, parent/child/ancestor/descendant traversal, `id_column`,
|
|
22
|
+
`boundary_level`), the prebuilt `PSGC_GRAPH` / `PSGC_NORMALIZED_GRAPH` /
|
|
23
|
+
`GOVERNANCE_GRAPH` / `LEGISLATIVE_GRAPH`, the `hierarchy_graph` resolver, and
|
|
24
|
+
opt-in `HierarchyGraph.extend(...)` for consumer drilldown levels (e.g. the
|
|
25
|
+
`psgc-maps` `legis_child` extension) that never mutate the core graphs.
|
|
26
|
+
- `resolve_level_alias` in `deped_primitives.hierarchies.aliases`, the single
|
|
27
|
+
owner of the `locality ↔ city ↔ municipality` equivalence, plus the
|
|
28
|
+
`has_boundary_geometry` / `boundary_artifact_name` renderability predicates.
|
|
29
|
+
- `deped_primitives.access` with `AccessScope` (office permission scope),
|
|
30
|
+
`ScopeLocks` (derived UI lock state), `scope_locks_from_access`, and Polars
|
|
31
|
+
island-group and access-scoped area-stats filtering rewritten from the pandas
|
|
32
|
+
originals.
|
|
33
|
+
- Generalized, adapter-declared SQL search (`search_clause(adapter, query,
|
|
34
|
+
fields=None)` backed by `SchemaAdapter.searchable_fields`) and the centralized
|
|
35
|
+
`deped_primitives.sql.labels` module owning the
|
|
36
|
+
region/locality/barangay/legislative label-coalesce precedence previously
|
|
37
|
+
duplicated across the builders — a behavior-preserving refactor (default field
|
|
38
|
+
set and label output unchanged).
|
|
39
|
+
- Hardening fixtures captured from source-repo behavior for each capability
|
|
40
|
+
above (parent/child truth tables, the Bacoor merger lineage delta, graph
|
|
41
|
+
traversal incl. the `legis_child` extension, and access-scope round-trips).
|
|
42
|
+
|
|
43
|
+
## 0.0.1
|
|
44
|
+
|
|
45
|
+
- Add parity-phase scaffold for `deped-primitives`.
|
|
46
|
+
- Add `deped_primitives.psgc` with PSGC type, constant, core, exception, and
|
|
47
|
+
pure lineage helpers.
|
|
48
|
+
- Add `deped_primitives.codes` with PSGC, boundary PCODE, legacy code, and name
|
|
49
|
+
normalization helpers.
|
|
50
|
+
- Add `deped_primitives.hierarchies` with shared area contract constants,
|
|
51
|
+
hierarchy aliases, level labels, derived group-id helpers, and sort helpers.
|
|
52
|
+
- Add `deped_primitives.region_groups` with the eight shared regional reporting
|
|
53
|
+
groups and a Polars component builder.
|
|
54
|
+
- Use the `psgc-maps` region-group display order as the canonical option order;
|
|
55
|
+
`deped-geos` exposed the same eight groups with a different option ordering.
|
|
56
|
+
- Add `deped_primitives.regions`, `deped_primitives.education`, and
|
|
57
|
+
`deped_primitives.school_sizes` with parity fixtures captured from
|
|
58
|
+
`deped-dataset/data/generic.yml`.
|
|
59
|
+
- Capture Phase 2b generic-reference fixtures for `region_names`,
|
|
60
|
+
`school_grades`, `school_sizes`, region display-label coalescing, and
|
|
61
|
+
inclusive school-size range matching.
|
|
62
|
+
- Add `deped_primitives.filters` with Polars territory cascade state, area-scope
|
|
63
|
+
helpers, membership traversal, and dataset foundation selection normalization.
|
|
64
|
+
- Capture Phase 3 parity fixtures for NCR province skipping, region-group plus
|
|
65
|
+
manual area-scope composition, SGA default exclusion, and stale selection
|
|
66
|
+
clearing.
|
|
67
|
+
- Add `deped_primitives.sql` with a `SchemaAdapter`, plain `FilterSpec`, dataset
|
|
68
|
+
`school_observations` SQL builders, choice SQL, rollup columns, where-clause
|
|
69
|
+
builders, and quote escaping.
|
|
70
|
+
- Add `deped_primitives.marimo` with optional cascading dropdown, `selection_with`,
|
|
71
|
+
and `option_key` helpers, plus a notebook smoke example for `check-notebooks`.
|
|
72
|
+
- Add `deped_primitives.legislative` with value primitives for legdist
|
|
73
|
+
normalization, anchor descendant predicates, anchor IDs by congress, and
|
|
74
|
+
legislative district code generation.
|
|
75
|
+
- Capture Phase 4 and Phase 6 parity fixtures for dataset explorer SQL fragments
|
|
76
|
+
and legislative value primitives.
|
|
77
|
+
- Document the purpose of landed Phase 1 through Phase 6 and the exact module
|
|
78
|
+
surface currently available.
|
|
79
|
+
- Share filter and SQL selection constants through `deped_primitives.filters`
|
|
80
|
+
and refresh stale docs that still described shipped parity phases as future
|
|
81
|
+
work.
|
|
82
|
+
- Enable the Zensical `mkdocstrings` plugin with the Python handler so generated
|
|
83
|
+
API reference pages render from source docstrings.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deped-primitives
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Shared DepEd PSGC, hierarchy, territory, SQL, and Marimo primitives.
|
|
5
|
+
Author-email: Marcelino Veloso III <marsveloso@gmail.com>
|
|
6
|
+
Requires-Python: >=3.14
|
|
7
|
+
Requires-Dist: polars>=1.41
|
|
8
|
+
Requires-Dist: pyyaml>=6.0
|
|
9
|
+
Provides-Extra: marimo
|
|
10
|
+
Requires-Dist: marimo>=0.16; extra == 'marimo'
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# deped-primitives
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
Shared DepEd primitives for PSGC codes and boundary-code normalization.
|
|
18
|
+
|
|
19
|
+
The package is in its parity phase. It ports existing behavior from the DepEd
|
|
20
|
+
toolchain into a small, tested library before downstream repositories migrate.
|
|
21
|
+
|
|
22
|
+
## Purpose
|
|
23
|
+
|
|
24
|
+
The package gives downstream projects one tested owner for shared DepEd value
|
|
25
|
+
rules that were duplicated across repositories:
|
|
26
|
+
|
|
27
|
+
- PSGC code shape validation and slicing.
|
|
28
|
+
- PSGC geographic level normalization and labels.
|
|
29
|
+
- Parent and ancestor rules for regions, provinces, HUCs, NCR localities,
|
|
30
|
+
Manila sub-municipalities, and barangays.
|
|
31
|
+
- Pure predecessor/successor lineage resolution helpers.
|
|
32
|
+
- PSA/NAMRIA boundary PCODE and legacy-code normalization.
|
|
33
|
+
- Stable comparable-name keys for exact source matching.
|
|
34
|
+
- Area hierarchy constants and public hierarchy option aliases.
|
|
35
|
+
- Regional reporting groups and their component-region rows.
|
|
36
|
+
- Region display aliases, school grade key stages, and school-size bands.
|
|
37
|
+
- Territory cascade state, area-scope filters, descendant/ancestor membership
|
|
38
|
+
traversal, and dataset foundation selection normalization.
|
|
39
|
+
- Schema-adapter SQL builders for the `school_observations` explorer surface.
|
|
40
|
+
- Optional Marimo helpers for cascading dropdown notebooks.
|
|
41
|
+
- Legislative anchor normalization, descendant barangay predicates, and
|
|
42
|
+
legislative district code generation.
|
|
43
|
+
|
|
44
|
+
It deliberately does not include dataframe pipelines, workbook loading, full
|
|
45
|
+
legislative coverage builders, YAML policy contracts, migration wrappers, or
|
|
46
|
+
repo-specific dashboards. Those remain in their source repos unless a later plan
|
|
47
|
+
explicitly moves them.
|
|
48
|
+
|
|
49
|
+
## Scope
|
|
50
|
+
|
|
51
|
+
- `deped_primitives.psgc`: zero-dependency PSGC parsing, hierarchy inference,
|
|
52
|
+
parent/ancestor rules, relation validation, typed code breakdowns, normalized
|
|
53
|
+
geo types, constants, and pure lineage helpers.
|
|
54
|
+
- `deped_primitives.codes`: stdlib normalization helpers for PSGC IDs, PSA/NAMRIA
|
|
55
|
+
boundary PCODEs, legacy codes, and comparable name keys.
|
|
56
|
+
- `deped_primitives.hierarchies`: shared hierarchy constants, derived group IDs,
|
|
57
|
+
level labels, hierarchy aliases, and sort helpers.
|
|
58
|
+
- `deped_primitives.region_groups`: regional reporting group definitions, options,
|
|
59
|
+
membership lookups, and Polars component-row generation.
|
|
60
|
+
- `deped_primitives.regions`: region display aliases keyed by PSGC region ID.
|
|
61
|
+
- `deped_primitives.education`: grade labels and key-stage lookup helpers.
|
|
62
|
+
- `deped_primitives.school_sizes`: school-size bands and inclusive range lookups.
|
|
63
|
+
- `deped_primitives.filters`: Polars territory cascades, area-scope helpers,
|
|
64
|
+
hierarchy membership traversal, and dataset-style selection normalization.
|
|
65
|
+
- `deped_primitives.access`: office access scopes, derived UI scope locks,
|
|
66
|
+
island-group scoping, and access-limited area-stats filtering.
|
|
67
|
+
- `deped_primitives.sql`: schema-adapter SQL builders for the dataset
|
|
68
|
+
`school_observations` explorer queries.
|
|
69
|
+
- `deped_primitives.marimo`: optional notebook control helpers; Marimo is loaded
|
|
70
|
+
only by the consumer environment.
|
|
71
|
+
- `deped_primitives.legislative`: legislative value primitives only.
|
|
72
|
+
|
|
73
|
+
The documentation is organized by domain:
|
|
74
|
+
|
|
75
|
+
- `docs/index.md` is the landing page and current-scope summary.
|
|
76
|
+
- `docs/guide/psgc-and-codes.md` covers PSGC, lineage, and boundary-code helpers.
|
|
77
|
+
- `docs/guide/hierarchies-and-region-groups.md` covers hierarchy and regional
|
|
78
|
+
reporting helpers.
|
|
79
|
+
- `docs/guide/reference-vocabularies.md` covers region aliases, grade key
|
|
80
|
+
stages, and school-size bands.
|
|
81
|
+
- `docs/guide/filters.md` covers territory cascade, area-scope, membership, and
|
|
82
|
+
selection helpers.
|
|
83
|
+
- `docs/guide/querying.md` covers SQL builders and optional Marimo controls.
|
|
84
|
+
- `docs/guide/legislative.md` covers legislative value helpers.
|
|
85
|
+
- `docs/reference/` contains generated API reference pages.
|
|
86
|
+
- `docs/status.md` records landed and deferred scope.
|
|
87
|
+
|
|
88
|
+
The root package intentionally exposes only `__version__`. Import concrete
|
|
89
|
+
helpers from their owner modules:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from deped_primitives.psgc import GeoType, ancestor_codes, breakdown, normalize_code
|
|
93
|
+
from deped_primitives.codes import normalize_boundary_pcode_to_psgc_id
|
|
94
|
+
|
|
95
|
+
assert normalize_code(" 13-3900-0000 ") == "1339000000"
|
|
96
|
+
assert ancestor_codes("1380610001", GeoType.BGY) == [
|
|
97
|
+
"1300000000",
|
|
98
|
+
"1380600000",
|
|
99
|
+
"1380610000",
|
|
100
|
+
]
|
|
101
|
+
assert breakdown("0908301001").barangay.code == "0908301001"
|
|
102
|
+
assert normalize_boundary_pcode_to_psgc_id("PH0102801") == "0102801000"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Pure lineage helpers live below `deped_primitives.psgc.lineage`:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from deped_primitives.psgc.lineage import psgc_like_from_code
|
|
109
|
+
|
|
110
|
+
assert psgc_like_from_code("098301000") == "0908301000"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Hierarchy and regional group helpers live in their owner modules:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from deped_primitives.hierarchies import configured_levels, hierarchy_internal_value
|
|
117
|
+
from deped_primitives.region_groups import region_group_region_ids
|
|
118
|
+
from deped_primitives.regions import region_common_label
|
|
119
|
+
from deped_primitives.school_sizes import school_size_label
|
|
120
|
+
from deped_primitives.filters import cascade_control_levels, derive_result_level
|
|
121
|
+
from deped_primitives.access import AccessScope, scope_locks_from_access
|
|
122
|
+
from deped_primitives.sql import SCHOOL_OBSERVATIONS_ADAPTER, FilterSpec, summary_sql
|
|
123
|
+
from deped_primitives.legislative import legis_id
|
|
124
|
+
|
|
125
|
+
assert hierarchy_internal_value("geo") == "psgc_normalized"
|
|
126
|
+
assert configured_levels("geo")[0] == "region_group"
|
|
127
|
+
assert "1900000000" not in region_group_region_ids("excluding_barmm")
|
|
128
|
+
assert region_common_label("1300000000") == "NCR"
|
|
129
|
+
assert school_size_label(101) == "vs"
|
|
130
|
+
assert cascade_control_levels("geo") == ("region", "province", "locality", "barangay")
|
|
131
|
+
assert derive_result_level("geo", (("region", "1300000000"),)) == "province"
|
|
132
|
+
assert scope_locks_from_access(
|
|
133
|
+
AccessScope(level="regional", psgc_region_id="1300000000")
|
|
134
|
+
).locked_levels == ("region",)
|
|
135
|
+
assert "school_observations" in summary_sql(SCHOOL_OBSERVATIONS_ADAPTER, FilterSpec())
|
|
136
|
+
assert legis_id(20, "1381701000", 0) == "201381701x"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Development
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
just test
|
|
143
|
+
just check
|
|
144
|
+
uv run zensical build
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Core depends on Polars only. Marimo remains optional:
|
|
148
|
+
|
|
149
|
+
```sh
|
|
150
|
+
uv run --extra marimo marimo check notebooks/*.py
|
|
151
|
+
```
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# deped-primitives
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Shared DepEd primitives for PSGC codes and boundary-code normalization.
|
|
6
|
+
|
|
7
|
+
The package is in its parity phase. It ports existing behavior from the DepEd
|
|
8
|
+
toolchain into a small, tested library before downstream repositories migrate.
|
|
9
|
+
|
|
10
|
+
## Purpose
|
|
11
|
+
|
|
12
|
+
The package gives downstream projects one tested owner for shared DepEd value
|
|
13
|
+
rules that were duplicated across repositories:
|
|
14
|
+
|
|
15
|
+
- PSGC code shape validation and slicing.
|
|
16
|
+
- PSGC geographic level normalization and labels.
|
|
17
|
+
- Parent and ancestor rules for regions, provinces, HUCs, NCR localities,
|
|
18
|
+
Manila sub-municipalities, and barangays.
|
|
19
|
+
- Pure predecessor/successor lineage resolution helpers.
|
|
20
|
+
- PSA/NAMRIA boundary PCODE and legacy-code normalization.
|
|
21
|
+
- Stable comparable-name keys for exact source matching.
|
|
22
|
+
- Area hierarchy constants and public hierarchy option aliases.
|
|
23
|
+
- Regional reporting groups and their component-region rows.
|
|
24
|
+
- Region display aliases, school grade key stages, and school-size bands.
|
|
25
|
+
- Territory cascade state, area-scope filters, descendant/ancestor membership
|
|
26
|
+
traversal, and dataset foundation selection normalization.
|
|
27
|
+
- Schema-adapter SQL builders for the `school_observations` explorer surface.
|
|
28
|
+
- Optional Marimo helpers for cascading dropdown notebooks.
|
|
29
|
+
- Legislative anchor normalization, descendant barangay predicates, and
|
|
30
|
+
legislative district code generation.
|
|
31
|
+
|
|
32
|
+
It deliberately does not include dataframe pipelines, workbook loading, full
|
|
33
|
+
legislative coverage builders, YAML policy contracts, migration wrappers, or
|
|
34
|
+
repo-specific dashboards. Those remain in their source repos unless a later plan
|
|
35
|
+
explicitly moves them.
|
|
36
|
+
|
|
37
|
+
## Scope
|
|
38
|
+
|
|
39
|
+
- `deped_primitives.psgc`: zero-dependency PSGC parsing, hierarchy inference,
|
|
40
|
+
parent/ancestor rules, relation validation, typed code breakdowns, normalized
|
|
41
|
+
geo types, constants, and pure lineage helpers.
|
|
42
|
+
- `deped_primitives.codes`: stdlib normalization helpers for PSGC IDs, PSA/NAMRIA
|
|
43
|
+
boundary PCODEs, legacy codes, and comparable name keys.
|
|
44
|
+
- `deped_primitives.hierarchies`: shared hierarchy constants, derived group IDs,
|
|
45
|
+
level labels, hierarchy aliases, and sort helpers.
|
|
46
|
+
- `deped_primitives.region_groups`: regional reporting group definitions, options,
|
|
47
|
+
membership lookups, and Polars component-row generation.
|
|
48
|
+
- `deped_primitives.regions`: region display aliases keyed by PSGC region ID.
|
|
49
|
+
- `deped_primitives.education`: grade labels and key-stage lookup helpers.
|
|
50
|
+
- `deped_primitives.school_sizes`: school-size bands and inclusive range lookups.
|
|
51
|
+
- `deped_primitives.filters`: Polars territory cascades, area-scope helpers,
|
|
52
|
+
hierarchy membership traversal, and dataset-style selection normalization.
|
|
53
|
+
- `deped_primitives.access`: office access scopes, derived UI scope locks,
|
|
54
|
+
island-group scoping, and access-limited area-stats filtering.
|
|
55
|
+
- `deped_primitives.sql`: schema-adapter SQL builders for the dataset
|
|
56
|
+
`school_observations` explorer queries.
|
|
57
|
+
- `deped_primitives.marimo`: optional notebook control helpers; Marimo is loaded
|
|
58
|
+
only by the consumer environment.
|
|
59
|
+
- `deped_primitives.legislative`: legislative value primitives only.
|
|
60
|
+
|
|
61
|
+
The documentation is organized by domain:
|
|
62
|
+
|
|
63
|
+
- `docs/index.md` is the landing page and current-scope summary.
|
|
64
|
+
- `docs/guide/psgc-and-codes.md` covers PSGC, lineage, and boundary-code helpers.
|
|
65
|
+
- `docs/guide/hierarchies-and-region-groups.md` covers hierarchy and regional
|
|
66
|
+
reporting helpers.
|
|
67
|
+
- `docs/guide/reference-vocabularies.md` covers region aliases, grade key
|
|
68
|
+
stages, and school-size bands.
|
|
69
|
+
- `docs/guide/filters.md` covers territory cascade, area-scope, membership, and
|
|
70
|
+
selection helpers.
|
|
71
|
+
- `docs/guide/querying.md` covers SQL builders and optional Marimo controls.
|
|
72
|
+
- `docs/guide/legislative.md` covers legislative value helpers.
|
|
73
|
+
- `docs/reference/` contains generated API reference pages.
|
|
74
|
+
- `docs/status.md` records landed and deferred scope.
|
|
75
|
+
|
|
76
|
+
The root package intentionally exposes only `__version__`. Import concrete
|
|
77
|
+
helpers from their owner modules:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from deped_primitives.psgc import GeoType, ancestor_codes, breakdown, normalize_code
|
|
81
|
+
from deped_primitives.codes import normalize_boundary_pcode_to_psgc_id
|
|
82
|
+
|
|
83
|
+
assert normalize_code(" 13-3900-0000 ") == "1339000000"
|
|
84
|
+
assert ancestor_codes("1380610001", GeoType.BGY) == [
|
|
85
|
+
"1300000000",
|
|
86
|
+
"1380600000",
|
|
87
|
+
"1380610000",
|
|
88
|
+
]
|
|
89
|
+
assert breakdown("0908301001").barangay.code == "0908301001"
|
|
90
|
+
assert normalize_boundary_pcode_to_psgc_id("PH0102801") == "0102801000"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Pure lineage helpers live below `deped_primitives.psgc.lineage`:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from deped_primitives.psgc.lineage import psgc_like_from_code
|
|
97
|
+
|
|
98
|
+
assert psgc_like_from_code("098301000") == "0908301000"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Hierarchy and regional group helpers live in their owner modules:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from deped_primitives.hierarchies import configured_levels, hierarchy_internal_value
|
|
105
|
+
from deped_primitives.region_groups import region_group_region_ids
|
|
106
|
+
from deped_primitives.regions import region_common_label
|
|
107
|
+
from deped_primitives.school_sizes import school_size_label
|
|
108
|
+
from deped_primitives.filters import cascade_control_levels, derive_result_level
|
|
109
|
+
from deped_primitives.access import AccessScope, scope_locks_from_access
|
|
110
|
+
from deped_primitives.sql import SCHOOL_OBSERVATIONS_ADAPTER, FilterSpec, summary_sql
|
|
111
|
+
from deped_primitives.legislative import legis_id
|
|
112
|
+
|
|
113
|
+
assert hierarchy_internal_value("geo") == "psgc_normalized"
|
|
114
|
+
assert configured_levels("geo")[0] == "region_group"
|
|
115
|
+
assert "1900000000" not in region_group_region_ids("excluding_barmm")
|
|
116
|
+
assert region_common_label("1300000000") == "NCR"
|
|
117
|
+
assert school_size_label(101) == "vs"
|
|
118
|
+
assert cascade_control_levels("geo") == ("region", "province", "locality", "barangay")
|
|
119
|
+
assert derive_result_level("geo", (("region", "1300000000"),)) == "province"
|
|
120
|
+
assert scope_locks_from_access(
|
|
121
|
+
AccessScope(level="regional", psgc_region_id="1300000000")
|
|
122
|
+
).locked_levels == ("region",)
|
|
123
|
+
assert "school_observations" in summary_sql(SCHOOL_OBSERVATIONS_ADAPTER, FilterSpec())
|
|
124
|
+
assert legis_id(20, "1381701000", 0) == "201381701x"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
just test
|
|
131
|
+
just check
|
|
132
|
+
uv run zensical build
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Core depends on Polars only. Marimo remains optional:
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
uv run --extra marimo marimo check notebooks/*.py
|
|
139
|
+
```
|