-
Notifications
You must be signed in to change notification settings - Fork 1
feat(ontology): expose occupation rating evidence #738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seonghobae
merged 6 commits into
feat/onet-rating-importer
from
feat/onet-rating-read-api
Aug 26, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9bc9e93
feat(ontology): expose occupation rating evidence
seonghobae 8f5b87b
Merge remote-tracking branch 'origin/feat/onet-rating-importer' into …
seonghobae 026ba80
Merge remote-tracking branch 'origin/feat/onet-rating-importer' into …
seonghobae 8932d19
Merge remote-tracking branch 'origin/feat/onet-rating-importer' into …
seonghobae 317205b
Merge remote-tracking branch 'origin/feat/onet-rating-read-api' into …
seonghobae e6a1d62
docs: keep occupation rating ADR lint-clean
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| """Read exact imported occupation ratings without deriving a score or weight.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from decimal import Decimal | ||
| from typing import Any, Protocol | ||
|
|
||
|
|
||
| class RatingReadConnection(Protocol): | ||
| """Small asyncpg-compatible surface used by the rating read projection.""" | ||
|
|
||
| async def fetchrow(self, query: str, *args: object) -> Any: | ||
| """Return one row or ``None``.""" | ||
|
|
||
| async def fetch(self, query: str, *args: object) -> list[Any]: | ||
| """Return ordered rows.""" | ||
|
|
||
|
|
||
| def _decimal_text(value: Decimal | None) -> str | None: | ||
| """Return the exact database decimal representation or honest absence.""" | ||
| return str(value) if value is not None else None | ||
|
|
||
|
|
||
| async def fetch_occupation_ratings( | ||
| conn: RatingReadConnection, | ||
| *, | ||
| data_release_code: str, | ||
| source_table_code: str, | ||
| onetsoc_code: str, | ||
| limit: int, | ||
| offset: int, | ||
| ) -> dict[str, object]: | ||
| """Return one bounded source profile and explicit artifact availability.""" | ||
| source = await conn.fetchrow( | ||
| """select rating_source.source_table_name, | ||
| rating_source.source_artifact_url, | ||
| rating_source.source_artifact_sha256, | ||
| rating_source.source_row_count, | ||
| scale_source.source_artifact_url as scale_artifact_url, | ||
| scale_source.source_artifact_sha256 as scale_artifact_sha256, | ||
| scale_source.source_row_count as scale_source_row_count | ||
| from occupational_source_table rating_source | ||
| left join occupational_source_table scale_source | ||
| on scale_source.data_release_code = rating_source.data_release_code | ||
| and scale_source.source_table_code = 'scales_reference' | ||
|
seonghobae marked this conversation as resolved.
|
||
| where rating_source.data_release_code = $1 | ||
| and rating_source.source_table_code = $2""", | ||
| data_release_code, | ||
| source_table_code, | ||
| ) | ||
| if source is None: | ||
| return { | ||
| "data_release_code": data_release_code, | ||
| "source_table_code": source_table_code, | ||
| "onetsoc_code": onetsoc_code, | ||
| "source_available": False, | ||
| "source": None, | ||
| "items": [], | ||
| "next_offset": None, | ||
| } | ||
| rows = await conn.fetch( | ||
| """select observation.element_id, element.element_name, | ||
| observation.scale_id, scale.scale_name, | ||
| scale.minimum_value, scale.maximum_value, | ||
| observation.category_value, observation.data_value, | ||
| observation.sample_size, observation.standard_error, | ||
| observation.lower_ci_bound, observation.upper_ci_bound, | ||
| observation.recommend_suppress, observation.not_relevant, | ||
| observation.source_updated_month, observation.domain_source_code | ||
| from occupational_rating_observation observation | ||
| join occupational_element_definition element | ||
| on element.data_release_code = observation.data_release_code | ||
| and element.element_id = observation.element_id | ||
| join occupational_scale_definition scale | ||
| on scale.data_release_code = observation.data_release_code | ||
| and scale.scale_id = observation.scale_id | ||
| where observation.data_release_code = $1 | ||
| and observation.source_table_code = $2 | ||
| and observation.onetsoc_code = $3 | ||
| order by observation.element_id, observation.scale_id, | ||
| observation.category_value nulls first | ||
| limit $4 offset $5""", | ||
| data_release_code, | ||
| source_table_code, | ||
| onetsoc_code, | ||
| limit + 1, | ||
| offset, | ||
| ) | ||
| page = rows[:limit] | ||
| items = [ | ||
| { | ||
| "element_id": row["element_id"], | ||
| "element_name": row["element_name"], | ||
| "scale_id": row["scale_id"], | ||
| "scale_name": row["scale_name"], | ||
| "minimum_value": _decimal_text(row["minimum_value"]), | ||
| "maximum_value": _decimal_text(row["maximum_value"]), | ||
| "category_value": row["category_value"], | ||
| "data_value": _decimal_text(row["data_value"]), | ||
| "sample_size": row["sample_size"], | ||
| "standard_error": _decimal_text(row["standard_error"]), | ||
| "lower_ci_bound": _decimal_text(row["lower_ci_bound"]), | ||
| "upper_ci_bound": _decimal_text(row["upper_ci_bound"]), | ||
| "recommend_suppress": row["recommend_suppress"], | ||
| "not_relevant": row["not_relevant"], | ||
| "source_updated_month": row["source_updated_month"], | ||
| "domain_source_code": row["domain_source_code"], | ||
| } | ||
| for row in page | ||
| ] | ||
| return { | ||
| "data_release_code": data_release_code, | ||
| "source_table_code": source_table_code, | ||
| "onetsoc_code": onetsoc_code, | ||
| "source_available": True, | ||
| "source": { | ||
| "source_table_name": source["source_table_name"], | ||
| "source_artifact_url": source["source_artifact_url"], | ||
| "source_artifact_sha256": source["source_artifact_sha256"], | ||
| "source_row_count": source["source_row_count"], | ||
| "scale_artifact_url": source["scale_artifact_url"], | ||
| "scale_artifact_sha256": source["scale_artifact_sha256"], | ||
| "scale_source_row_count": source["scale_source_row_count"], | ||
| }, | ||
| "items": items, | ||
| "next_offset": offset + limit if len(rows) > limit else None, | ||
|
seonghobae marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # ADR 0258: Authenticated occupation-rating source read API | ||
|
|
||
| **Status:** Accepted | ||
|
|
||
| **Date:** 2026-08-27 | ||
| **Extends:** ADR 0120, ADR 0184, ADR 0257 | ||
|
|
||
| ## Context | ||
|
|
||
| ADR 0257 preserves released occupation-to-element observations, but a database | ||
| import alone does not let a product user inspect what a job profile says. A | ||
| read contract must distinguish an unimported source from an imported source | ||
| with no row for one occupation, preserve low-precision and not-relevant flags, | ||
| and avoid presenting a published rating as a local weight or recommendation. | ||
|
|
||
| ## Decision | ||
|
|
||
| 1. Add an authenticated, read-only occupation-rating endpoint. O*NET source | ||
| observations are licensed public reference data and are not tenant records; | ||
| any authenticated LineageWeave account may read an imported artifact. | ||
| 2. Require exact release, source-table, and O*NET-SOC codes. Return | ||
| `source_available=false` when that pinned artifact is not imported; return | ||
| `source_available=true` with an empty item list when it is imported but has | ||
| no observation for the requested occupation. | ||
| 3. Return the rating and Scales Reference artifact URLs, SHA-256 values, and | ||
| row counts. Every observation retains element/scale identity, declared | ||
| bounds, optional category, exact decimal strings, sample/error/interval, | ||
| suppression, relevance, source month, and domain source. | ||
| 4. Order by element, scale, and category and use bounded offset pagination. | ||
| Per-occupation source partitions bound this projection; a cursor needs a | ||
| later decision only if measured production latency requires it. | ||
| 5. Do not aggregate, rank, normalize, infer person traits, or recommend an | ||
| occupation. Suppressed values remain visible with the suppression flag so a | ||
| user can audit the source without mistaking low precision for absence. | ||
| 6. API and frontend copy describe the evidence and the user's next action, | ||
| never importer, partition, model-provider, or orchestration internals. | ||
|
|
||
| ## Consequences | ||
|
|
||
| The semantic layer gains an honest product read boundary without duplicating | ||
| psychometric arithmetic. An accessible UI and its Storybook states remain a | ||
| separate delivery step after this API has authenticated runtime evidence. | ||
|
|
||
| ## References | ||
|
|
||
| National Center for O*NET Development. (2026). *O*NET 31.0 database* [Data | ||
| set]. https://www.onetcenter.org/database.html | ||
|
|
||
| PostgreSQL Global Development Group. (2026). *PostgreSQL 18 documentation: | ||
| Queries—limit and offset*. https://www.postgresql.org/docs/current/queries-limit.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.