feat(evidence): project skill evidence from confirmed assessments
This commit is contained in:
1 parent
4761508f13
commit
c2a8d17195
94 files changed
+10077
-151
No files matched your search
@@ -0,0 +1,266 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: evidence.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const listCandidateEvidenceFacts = `-- name: ListCandidateEvidenceFacts :many
|
||||
|
||||
SELECT
|
||||
fact.id,
|
||||
fact.kind,
|
||||
fact.source_type,
|
||||
fact.event_id,
|
||||
fact.result_id,
|
||||
fact.attribution,
|
||||
fact.trust,
|
||||
fact.grade,
|
||||
fact.basis,
|
||||
fact.calibration_status,
|
||||
fact.occurred_at,
|
||||
fact.visibility,
|
||||
COALESCE(
|
||||
(
|
||||
SELECT array_agg(skill.skill_code ORDER BY skill.skill_code)
|
||||
FROM skill_evidence_skills AS skill
|
||||
WHERE skill.fact_id = fact.id
|
||||
),
|
||||
'{}'::text []
|
||||
)::text [] AS skills
|
||||
FROM skill_evidence_facts AS fact
|
||||
WHERE
|
||||
fact.candidate_id = $1
|
||||
AND (
|
||||
$2::timestamptz IS NULL
|
||||
OR (fact.occurred_at, fact.id) < (
|
||||
$2::timestamptz,
|
||||
$3::uuid
|
||||
)
|
||||
)
|
||||
ORDER BY fact.occurred_at DESC, fact.id DESC
|
||||
LIMIT $4
|
||||
`
|
||||
|
||||
type ListCandidateEvidenceFactsParams struct {
|
||||
CandidateID pgtype.UUID
|
||||
AfterOccurredAt pgtype.Timestamptz
|
||||
AfterID pgtype.UUID
|
||||
RowLimit int32
|
||||
}
|
||||
|
||||
type ListCandidateEvidenceFactsRow struct {
|
||||
ID pgtype.UUID
|
||||
Kind string
|
||||
SourceType string
|
||||
EventID pgtype.UUID
|
||||
ResultID pgtype.UUID
|
||||
Attribution string
|
||||
Trust int16
|
||||
Grade string
|
||||
Basis string
|
||||
CalibrationStatus string
|
||||
OccurredAt pgtype.Timestamptz
|
||||
Visibility string
|
||||
Skills []string
|
||||
}
|
||||
|
||||
// Skill evidence reads. The projection tables hold no answer, score, item,
|
||||
// failure, or anti-cheat data, and none of these statements names the result,
|
||||
// attempt, or review tables: evidence is read from its own facts only.
|
||||
// The candidate's own facts, hidden ones included, newest event first. Every
|
||||
// statement is scoped by the owner; the caller passes the continuation
|
||||
// position of the previous page, if any, and fetches one extra row.
|
||||
func (q *Queries) ListCandidateEvidenceFacts(ctx context.Context, arg ListCandidateEvidenceFactsParams) ([]ListCandidateEvidenceFactsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listCandidateEvidenceFacts,
|
||||
arg.CandidateID,
|
||||
arg.AfterOccurredAt,
|
||||
arg.AfterID,
|
||||
arg.RowLimit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListCandidateEvidenceFactsRow
|
||||
for rows.Next() {
|
||||
var i ListCandidateEvidenceFactsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.SourceType,
|
||||
&i.EventID,
|
||||
&i.ResultID,
|
||||
&i.Attribution,
|
||||
&i.Trust,
|
||||
&i.Grade,
|
||||
&i.Basis,
|
||||
&i.CalibrationStatus,
|
||||
&i.OccurredAt,
|
||||
&i.Visibility,
|
||||
&i.Skills,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listCandidatePreviewEvidence = `-- name: ListCandidatePreviewEvidence :many
|
||||
SELECT DISTINCT ON (skill.skill_code)
|
||||
skill.skill_code AS skill,
|
||||
fact.grade,
|
||||
fact.trust,
|
||||
fact.basis,
|
||||
fact.calibration_status,
|
||||
extract(YEAR FROM fact.occurred_at AT TIME ZONE 'UTC')::integer AS observed_year
|
||||
FROM skill_evidence_facts AS fact
|
||||
INNER JOIN skill_evidence_skills AS skill
|
||||
ON fact.id = skill.fact_id
|
||||
WHERE
|
||||
fact.candidate_id = $1
|
||||
AND (skill.skill_code || '/' || fact.grade) = any($2::text [])
|
||||
AND fact.kind = 'measurement'
|
||||
AND fact.visibility = 'visible'
|
||||
ORDER BY skill.skill_code, fact.occurred_at, fact.id
|
||||
`
|
||||
|
||||
type ListCandidatePreviewEvidenceParams struct {
|
||||
CandidateID pgtype.UUID
|
||||
Categories []string
|
||||
}
|
||||
|
||||
type ListCandidatePreviewEvidenceRow struct {
|
||||
Skill string
|
||||
Grade string
|
||||
Trust int16
|
||||
Basis string
|
||||
CalibrationStatus string
|
||||
ObservedYear int32
|
||||
}
|
||||
|
||||
// The same selection for the candidate's own card preview, so the candidate
|
||||
// sees what an organization would read. It is scoped by the owner and runs
|
||||
// after the caller locked the effective C2 and publication; it does not apply
|
||||
// an organization or a cohort.
|
||||
func (q *Queries) ListCandidatePreviewEvidence(ctx context.Context, arg ListCandidatePreviewEvidenceParams) ([]ListCandidatePreviewEvidenceRow, error) {
|
||||
rows, err := q.db.Query(ctx, listCandidatePreviewEvidence, arg.CandidateID, arg.Categories)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListCandidatePreviewEvidenceRow
|
||||
for rows.Next() {
|
||||
var i ListCandidatePreviewEvidenceRow
|
||||
if err := rows.Scan(
|
||||
&i.Skill,
|
||||
&i.Grade,
|
||||
&i.Trust,
|
||||
&i.Basis,
|
||||
&i.CalibrationStatus,
|
||||
&i.ObservedYear,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listOrganizationVisibleEvidence = `-- name: ListOrganizationVisibleEvidence :many
|
||||
SELECT DISTINCT ON (skill.skill_code)
|
||||
skill.skill_code AS skill,
|
||||
fact.grade,
|
||||
fact.trust,
|
||||
fact.basis,
|
||||
fact.calibration_status,
|
||||
extract(YEAR FROM fact.occurred_at AT TIME ZONE 'UTC')::integer AS observed_year
|
||||
FROM candidate_effective_publications AS effective
|
||||
INNER JOIN skill_evidence_facts AS fact
|
||||
ON effective.user_id = fact.candidate_id
|
||||
INNER JOIN skill_evidence_skills AS skill
|
||||
ON fact.id = skill.fact_id
|
||||
WHERE
|
||||
effective.user_id = $1
|
||||
AND 'categories' = any(effective.fields)
|
||||
AND (skill.skill_code || '/' || fact.grade) = any($2::text [])
|
||||
AND fact.kind = 'measurement'
|
||||
AND fact.visibility = 'visible'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM candidate_hidden_organizations AS hidden
|
||||
WHERE
|
||||
hidden.user_id = effective.user_id
|
||||
AND hidden.organization_id = $3
|
||||
)
|
||||
ORDER BY skill.skill_code, fact.occurred_at, fact.id
|
||||
`
|
||||
|
||||
type ListOrganizationVisibleEvidenceParams struct {
|
||||
CandidateID pgtype.UUID
|
||||
Categories []string
|
||||
OrganizationID pgtype.UUID
|
||||
}
|
||||
|
||||
type ListOrganizationVisibleEvidenceRow struct {
|
||||
Skill string
|
||||
Grade string
|
||||
Trust int16
|
||||
Basis string
|
||||
CalibrationStatus string
|
||||
ObservedYear int32
|
||||
}
|
||||
|
||||
// The evidence that one organization may read about one candidate: one fact
|
||||
// for each category of the card, the fact that supports the confirmed grade
|
||||
// of that category (the earliest one that passed exactly that grade, so a
|
||||
// lower grade or a retake adds nothing). The statement selects from the
|
||||
// effective publication view (published and backed by an unrevoked C2) and
|
||||
// excludes the candidates that hide the reading organization, so no row means
|
||||
// nothing to read, whatever the reason. The card must publish the categories
|
||||
// field and only visible measurements qualify. The categories come from the
|
||||
// caller as "specialization/grade" pairs taken from the card that was just
|
||||
// projected, so the answer never names a skill the card does not show. The columns are
|
||||
// an allowlist: no identifier of the fact, the event, the result, or the
|
||||
// candidate leaves, the instant is cut to the year, and the basis and the
|
||||
// calibration (the same for every candidate) say that the fact is a synthetic
|
||||
// demonstration.
|
||||
func (q *Queries) ListOrganizationVisibleEvidence(ctx context.Context, arg ListOrganizationVisibleEvidenceParams) ([]ListOrganizationVisibleEvidenceRow, error) {
|
||||
rows, err := q.db.Query(ctx, listOrganizationVisibleEvidence, arg.CandidateID, arg.Categories, arg.OrganizationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListOrganizationVisibleEvidenceRow
|
||||
for rows.Next() {
|
||||
var i ListOrganizationVisibleEvidenceRow
|
||||
if err := rows.Scan(
|
||||
&i.Skill,
|
||||
&i.Grade,
|
||||
&i.Trust,
|
||||
&i.Basis,
|
||||
&i.CalibrationStatus,
|
||||
&i.ObservedYear,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
Reference in new issue
Block a user