Add NextPath career exploration matches
This commit is contained in:
parent
cf6e4be6bb
commit
17963c604d
|
|
@ -0,0 +1,105 @@
|
|||
// Package career maps an interest result to occupations worth exploring. It
|
||||
// does not contain labor-market demand or employability calculations.
|
||||
package career
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"my-homelab-configs/cmd/nextpath/internal/assessment"
|
||||
)
|
||||
|
||||
//go:embed occupations.json
|
||||
var defaultCatalogJSON []byte
|
||||
|
||||
type Occupation struct {
|
||||
ONETSOC string `json:"onet_soc"`
|
||||
Title string `json:"title"`
|
||||
InterestOrder []assessment.Dimension `json:"interest_order"`
|
||||
Summary string `json:"summary"`
|
||||
TryFirst string `json:"try_first"`
|
||||
SourceURL string `json:"source_url"`
|
||||
}
|
||||
|
||||
type Catalog struct {
|
||||
Version string `json:"version"`
|
||||
Occupations []Occupation `json:"occupations"`
|
||||
}
|
||||
|
||||
type Match struct {
|
||||
Occupation Occupation `json:"occupation"`
|
||||
FitScore int `json:"fit_score"`
|
||||
Reason string `json:"reason"`
|
||||
Notice string `json:"notice"`
|
||||
}
|
||||
|
||||
func DefaultCatalog() (Catalog, error) {
|
||||
var catalog Catalog
|
||||
if err := json.Unmarshal(defaultCatalogJSON, &catalog); err != nil {
|
||||
return Catalog{}, fmt.Errorf("decode embedded occupation catalog: %w", err)
|
||||
}
|
||||
if catalog.Version == "" || len(catalog.Occupations) == 0 {
|
||||
return Catalog{}, fmt.Errorf("embedded occupation catalog is empty")
|
||||
}
|
||||
return catalog, nil
|
||||
}
|
||||
|
||||
// Rank returns deterministic personal-fit matches. FitScore is only an
|
||||
// interest-alignment score and must never be displayed as employability.
|
||||
func Rank(result assessment.Result, catalog Catalog, limit int) []Match {
|
||||
if limit <= 0 {
|
||||
return nil
|
||||
}
|
||||
percent := make(map[assessment.Dimension]int, len(result.Scores))
|
||||
for _, score := range result.Scores {
|
||||
percent[score.Dimension] = score.Percent
|
||||
}
|
||||
weights := []int{50, 30, 20}
|
||||
matches := make([]Match, 0, len(catalog.Occupations))
|
||||
for _, occupation := range catalog.Occupations {
|
||||
weighted := 0
|
||||
weightTotal := 0
|
||||
for index, dimension := range occupation.InterestOrder {
|
||||
if index >= len(weights) {
|
||||
break
|
||||
}
|
||||
weighted += percent[dimension] * weights[index]
|
||||
weightTotal += weights[index]
|
||||
}
|
||||
fit := 0
|
||||
if weightTotal > 0 {
|
||||
fit = weighted / weightTotal
|
||||
}
|
||||
matches = append(matches, Match{
|
||||
Occupation: occupation,
|
||||
FitScore: fit,
|
||||
Reason: reason(occupation.InterestOrder, percent),
|
||||
Notice: "Personal-interest alignment only; Arizona demand, wages, education access, and job evidence are not yet included.",
|
||||
})
|
||||
}
|
||||
sort.SliceStable(matches, func(i, j int) bool {
|
||||
if matches[i].FitScore == matches[j].FitScore {
|
||||
return matches[i].Occupation.Title < matches[j].Occupation.Title
|
||||
}
|
||||
return matches[i].FitScore > matches[j].FitScore
|
||||
})
|
||||
if limit < len(matches) {
|
||||
matches = matches[:limit]
|
||||
}
|
||||
return matches
|
||||
}
|
||||
|
||||
func reason(order []assessment.Dimension, percent map[assessment.Dimension]int) string {
|
||||
if len(order) == 0 {
|
||||
return "The catalog does not yet contain an interest profile for this occupation."
|
||||
}
|
||||
labels := map[assessment.Dimension]string{
|
||||
assessment.Realistic: "hands-on", assessment.Investigative: "analytical",
|
||||
assessment.Artistic: "creative", assessment.Social: "helping and teaching",
|
||||
assessment.Enterprising: "leading and persuading", assessment.Conventional: "organizing and verifying",
|
||||
}
|
||||
primary := order[0]
|
||||
return fmt.Sprintf("This work emphasizes %s activities; your current %s interest score is %d%%.", labels[primary], labels[primary], percent[primary])
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package career
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"my-homelab-configs/cmd/nextpath/internal/assessment"
|
||||
)
|
||||
|
||||
func TestDefaultCatalogRanksInterestFitWithoutClaimingEmployability(t *testing.T) {
|
||||
catalog, err := DefaultCatalog()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := assessment.Result{Scores: []assessment.DimensionScore{
|
||||
{Dimension: assessment.Investigative, Percent: 100},
|
||||
{Dimension: assessment.Conventional, Percent: 80},
|
||||
{Dimension: assessment.Artistic, Percent: 70},
|
||||
{Dimension: assessment.Realistic, Percent: 20},
|
||||
{Dimension: assessment.Social, Percent: 10},
|
||||
{Dimension: assessment.Enterprising, Percent: 0},
|
||||
}}
|
||||
matches := Rank(result, catalog, 3)
|
||||
if len(matches) != 3 {
|
||||
t.Fatalf("matches = %d, want 3", len(matches))
|
||||
}
|
||||
if matches[0].Occupation.ONETSOC != "15-1252.00" {
|
||||
t.Fatalf("first match = %s, want Software Developer", matches[0].Occupation.Title)
|
||||
}
|
||||
if matches[0].FitScore != 88 {
|
||||
t.Fatalf("fit score = %d, want 88", matches[0].FitScore)
|
||||
}
|
||||
if matches[0].Notice == "" {
|
||||
t.Fatal("match omitted its market-evidence boundary")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRankIsDeterministicForTies(t *testing.T) {
|
||||
catalog, _ := DefaultCatalog()
|
||||
matches := Rank(assessment.Result{}, catalog, len(catalog.Occupations))
|
||||
for index := 1; index < len(matches); index++ {
|
||||
if matches[index-1].Occupation.Title > matches[index].Occupation.Title {
|
||||
t.Fatal("zero-score ties are not ordered by title")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
{
|
||||
"version": "nextpath-occupation-sample-2026-01",
|
||||
"occupations": [
|
||||
{
|
||||
"onet_soc": "15-1252.00",
|
||||
"title": "Software Developer",
|
||||
"interest_order": ["I", "C", "A"],
|
||||
"summary": "Design, build, test, and maintain software systems.",
|
||||
"try_first": "Build a small application that solves a problem you personally have.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/15-1252.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "29-1141.00",
|
||||
"title": "Registered Nurse",
|
||||
"interest_order": ["S", "I", "C"],
|
||||
"summary": "Assess patients, coordinate care, and provide health education.",
|
||||
"try_first": "Take a first-aid course and interview a nurse about a normal shift.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/29-1141.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "47-2111.00",
|
||||
"title": "Electrician",
|
||||
"interest_order": ["R", "I", "C"],
|
||||
"summary": "Install, inspect, and repair electrical wiring and equipment.",
|
||||
"try_first": "Visit a registered apprenticeship program and try a supervised basic circuits project.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/47-2111.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "49-9021.00",
|
||||
"title": "HVAC Technician",
|
||||
"interest_order": ["R", "I", "C"],
|
||||
"summary": "Install and service heating, ventilation, and cooling systems.",
|
||||
"try_first": "Shadow a technician or complete an introductory refrigeration-systems module.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/49-9021.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "25-2021.00",
|
||||
"title": "Elementary School Teacher",
|
||||
"interest_order": ["S", "A", "E"],
|
||||
"summary": "Teach foundational subjects and support children's development.",
|
||||
"try_first": "Tutor a younger student or volunteer in a supervised youth program.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/25-2021.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "27-1024.00",
|
||||
"title": "Graphic Designer",
|
||||
"interest_order": ["A", "E", "R"],
|
||||
"summary": "Create visual concepts that communicate information and ideas.",
|
||||
"try_first": "Redesign a poster or small website and ask intended users for feedback.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/27-1024.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "13-2011.00",
|
||||
"title": "Accountant or Auditor",
|
||||
"interest_order": ["C", "E", "I"],
|
||||
"summary": "Prepare and examine financial records for accuracy and compliance.",
|
||||
"try_first": "Build a budget and reconcile it against a month of sample transactions.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/13-2011.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "17-2051.00",
|
||||
"title": "Civil Engineer",
|
||||
"interest_order": ["I", "R", "C"],
|
||||
"summary": "Plan and design infrastructure such as roads, water systems, and structures.",
|
||||
"try_first": "Model a small structure or drainage problem and test your assumptions.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/17-2051.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "35-1011.00",
|
||||
"title": "Chef or Head Cook",
|
||||
"interest_order": ["E", "R", "A"],
|
||||
"summary": "Direct food preparation and create reliable dining experiences.",
|
||||
"try_first": "Plan, cost, prepare, and review a meal for a small group.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/35-1011.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "21-1012.00",
|
||||
"title": "Educational or Career Counselor",
|
||||
"interest_order": ["S", "I", "A"],
|
||||
"summary": "Help people understand options, overcome barriers, and make plans.",
|
||||
"try_first": "Interview a counselor and volunteer in a supervised peer-support setting.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/21-1012.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "13-1081.00",
|
||||
"title": "Logistician",
|
||||
"interest_order": ["E", "C", "I"],
|
||||
"summary": "Analyze and coordinate how products, information, and resources move.",
|
||||
"try_first": "Map and improve the steps required to deliver something on time.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/13-1081.00"
|
||||
},
|
||||
{
|
||||
"onet_soc": "29-1292.00",
|
||||
"title": "Dental Hygienist",
|
||||
"interest_order": ["S", "R", "C"],
|
||||
"summary": "Provide preventive oral care and educate patients about dental health.",
|
||||
"try_first": "Observe a dental office if permitted and compare local program prerequisites.",
|
||||
"source_url": "https://www.onetonline.org/link/summary/29-1292.00"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
"my-homelab-configs/cmd/nextpath/internal/account"
|
||||
"my-homelab-configs/cmd/nextpath/internal/assessment"
|
||||
"my-homelab-configs/cmd/nextpath/internal/career"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -209,11 +210,17 @@ func (server *Server) results(writer http.ResponseWriter, request *http.Request)
|
|||
server.internalError(writer, "score assessment", err)
|
||||
return
|
||||
}
|
||||
catalog, err := career.DefaultCatalog()
|
||||
if err != nil {
|
||||
server.internalError(writer, "load occupation catalog", err)
|
||||
return
|
||||
}
|
||||
matches := career.Rank(result, catalog, 5)
|
||||
server.mu.Lock()
|
||||
csrf := server.sessions[token].CSRFToken
|
||||
server.mu.Unlock()
|
||||
server.render(writer, http.StatusOK, "Your interest profile", resultsPage, map[string]any{
|
||||
"Name": user.DisplayName, "Result": result, "CSRF": csrf,
|
||||
"Name": user.DisplayName, "Result": result, "Matches": matches, "CSRF": csrf,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func TestCompletePrivateAssessmentFlow(t *testing.T) {
|
|||
|
||||
response = get(t, client, testServer.URL+"/results")
|
||||
body := readBody(t, response)
|
||||
if response.StatusCode != http.StatusOK || !strings.Contains(body, "interest profile") || !strings.Contains(body, "not ability, identity, or employability") {
|
||||
if response.StatusCode != http.StatusOK || !strings.Contains(body, "interest profile") || !strings.Contains(body, "not ability, identity, or employability") || !strings.Contains(body, "Careers to explore next") {
|
||||
t.Fatalf("unexpected results response %d: %s", response.StatusCode, body)
|
||||
}
|
||||
response = get(t, client, testServer.URL+"/account/export")
|
||||
|
|
|
|||
|
|
@ -24,4 +24,4 @@ const loginPage = `{{define "content"}}<h1>Continue exploring.</h1><section clas
|
|||
|
||||
const assessmentPage = `{{define "content"}}<h1>What sounds interesting, {{.Name}}?</h1><p class="muted">Rate the activity itself—not whether you are already good at it.</p><div class="progress"><span style="width:{{progress .Answered .Total}}%"></span></div><p class="small muted">{{.Answered}} of {{.Total}} answered</p><section class="panel"><h2>{{.Question.Prompt}}</h2><form method="post" action="/assessment"><input type="hidden" name="csrf_token" value="{{.CSRF}}"><input type="hidden" name="question_id" value="{{.Question.ID}}"><div class="answers">{{range $value := seq}}<label><input type="radio" name="answer" value="{{$value}}" required>{{$value}}</label>{{end}}</div><div class="answers small muted"><span>Not interested</span><span></span><span>Unsure</span><span></span><span>Very interested</span></div><button type="submit">Save and continue</button></form></section>{{end}}`
|
||||
|
||||
const resultsPage = `{{define "content"}}<h1>Your current interest profile</h1><p>Hello {{.Name}}. Your three-letter exploration code is <code>{{.Result.Code}}</code>.</p><section class="panel">{{range .Result.Scores}}<div class="score"><strong>{{.Dimension}}</strong><div class="bar"><span style="width:{{.Percent}}%"></span></div><span>{{.Percent}}%</span></div>{{end}}</section><section class="panel"><h2>How to use this</h2><p>{{.Result.InstrumentNotice}}</p><p class="muted">Confidence: {{.Result.Confidence}}. This describes interests, not ability, identity, or employability. Career and Arizona opportunity matching will be added as separate evidence.</p></section><div class="actions"><a class="button" href="/account/export">Export my data</a><form method="post" action="/logout"><input type="hidden" name="csrf_token" value="{{.CSRF}}"><button class="secondary">Sign out</button></form></div><section class="panel"><h2>Delete account</h2><form method="post" action="/account/delete"><input type="hidden" name="csrf_token" value="{{.CSRF}}"><label for="confirm">Type DELETE</label><input id="confirm" name="confirm" required><button class="secondary" type="submit">Delete profile and answers</button></form></section>{{end}}`
|
||||
const resultsPage = `{{define "content"}}<h1>Your current interest profile</h1><p>Hello {{.Name}}. Your three-letter exploration code is <code>{{.Result.Code}}</code>.</p><section class="panel">{{range .Result.Scores}}<div class="score"><strong>{{.Dimension}}</strong><div class="bar"><span style="width:{{.Percent}}%"></span></div><span>{{.Percent}}%</span></div>{{end}}</section><section class="panel"><h2>Careers to explore next</h2><p class="muted">These are personal-interest matches, not employability rankings. Arizona market and education evidence will be scored separately.</p>{{range .Matches}}<article class="panel"><div class="small muted">O*NET-SOC {{.Occupation.ONETSOC}} · interest fit {{.FitScore}}%</div><h3>{{.Occupation.Title}}</h3><p>{{.Occupation.Summary}}</p><p>{{.Reason}}</p><p><strong>Try it first:</strong> {{.Occupation.TryFirst}}</p><a href="{{.Occupation.SourceURL}}" rel="noreferrer">Review the O*NET occupation profile</a></article>{{end}}</section><section class="panel"><h2>How to use this</h2><p>{{.Result.InstrumentNotice}}</p><p class="muted">Confidence: {{.Result.Confidence}}. This describes interests, not ability, identity, or employability.</p></section><div class="actions"><a class="button" href="/account/export">Export my data</a><form method="post" action="/logout"><input type="hidden" name="csrf_token" value="{{.CSRF}}"><button class="secondary">Sign out</button></form></div><section class="panel"><h2>Delete account</h2><form method="post" action="/account/delete"><input type="hidden" name="csrf_token" value="{{.CSRF}}"><label for="confirm">Type DELETE</label><input id="confirm" name="confirm" required><button class="secondary" type="submit">Delete profile and answers</button></form></section>{{end}}`
|
||||
|
|
|
|||
Loading…
Reference in New Issue