diff --git a/cmd/nextpath/internal/career/catalog.go b/cmd/nextpath/internal/career/catalog.go new file mode 100644 index 0000000..4ebb302 --- /dev/null +++ b/cmd/nextpath/internal/career/catalog.go @@ -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]) +} diff --git a/cmd/nextpath/internal/career/catalog_test.go b/cmd/nextpath/internal/career/catalog_test.go new file mode 100644 index 0000000..d895a9e --- /dev/null +++ b/cmd/nextpath/internal/career/catalog_test.go @@ -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") + } + } +} diff --git a/cmd/nextpath/internal/career/occupations.json b/cmd/nextpath/internal/career/occupations.json new file mode 100644 index 0000000..088c124 --- /dev/null +++ b/cmd/nextpath/internal/career/occupations.json @@ -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" + } + ] +} + diff --git a/cmd/nextpath/internal/web/server.go b/cmd/nextpath/internal/web/server.go index 423bd16..0fea2a1 100644 --- a/cmd/nextpath/internal/web/server.go +++ b/cmd/nextpath/internal/web/server.go @@ -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, }) } diff --git a/cmd/nextpath/internal/web/server_test.go b/cmd/nextpath/internal/web/server_test.go index d1f20c6..89847c6 100644 --- a/cmd/nextpath/internal/web/server_test.go +++ b/cmd/nextpath/internal/web/server_test.go @@ -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") diff --git a/cmd/nextpath/internal/web/templates.go b/cmd/nextpath/internal/web/templates.go index 4956eca..dc88b9b 100644 --- a/cmd/nextpath/internal/web/templates.go +++ b/cmd/nextpath/internal/web/templates.go @@ -24,4 +24,4 @@ const loginPage = `{{define "content"}}

Continue exploring.

What sounds interesting, {{.Name}}?

Rate the activity itself—not whether you are already good at it.

{{.Answered}} of {{.Total}} answered

{{.Question.Prompt}}

{{range $value := seq}}{{end}}
Not interestedUnsureVery interested
{{end}}` -const resultsPage = `{{define "content"}}

Your current interest profile

Hello {{.Name}}. Your three-letter exploration code is {{.Result.Code}}.

{{range .Result.Scores}}
{{.Dimension}}
{{.Percent}}%
{{end}}

How to use this

{{.Result.InstrumentNotice}}

Confidence: {{.Result.Confidence}}. This describes interests, not ability, identity, or employability. Career and Arizona opportunity matching will be added as separate evidence.

Export my data

Delete account

{{end}}` +const resultsPage = `{{define "content"}}

Your current interest profile

Hello {{.Name}}. Your three-letter exploration code is {{.Result.Code}}.

{{range .Result.Scores}}
{{.Dimension}}
{{.Percent}}%
{{end}}

Careers to explore next

These are personal-interest matches, not employability rankings. Arizona market and education evidence will be scored separately.

{{range .Matches}}
O*NET-SOC {{.Occupation.ONETSOC}} · interest fit {{.FitScore}}%

{{.Occupation.Title}}

{{.Occupation.Summary}}

{{.Reason}}

Try it first: {{.Occupation.TryFirst}}

Review the O*NET occupation profile
{{end}}

How to use this

{{.Result.InstrumentNotice}}

Confidence: {{.Result.Confidence}}. This describes interests, not ability, identity, or employability.

Export my data

Delete account

{{end}}`