diff --git a/apps/nextpath/README.md b/apps/nextpath/README.md index 9c72a48..87603be 100644 --- a/apps/nextpath/README.md +++ b/apps/nextpath/README.md @@ -16,6 +16,11 @@ official employment growth, and sampled current occupation postings. Raw counts, dates, geography, sources, formula inputs, and limitations remain visible beside both percentages. +Each matched career also shows up to three balanced Arizona study options. +NextPath weighs proximity, reported in-state tuition, admission accessibility, +exact-program completion volume, and institution completion outcomes. This is +a transparent public-data comparison—not a commercial college ranking. + See [the architecture document](../../docs/nextpath-architecture.md) for the MVP boundaries and delivery slices. diff --git a/cmd/nextpath/internal/career/catalog.go b/cmd/nextpath/internal/career/catalog.go index 4ebb302..2449ae0 100644 --- a/cmd/nextpath/internal/career/catalog.go +++ b/cmd/nextpath/internal/career/catalog.go @@ -76,7 +76,7 @@ func Rank(result assessment.Result, catalog Catalog, limit int) []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.", + Notice: "Personal-interest alignment only; labor evidence and education access are evaluated separately.", }) } sort.SliceStable(matches, func(i, j int) bool { diff --git a/cmd/nextpath/internal/education/rank.go b/cmd/nextpath/internal/education/rank.go new file mode 100644 index 0000000..fc3e8ca --- /dev/null +++ b/cmd/nextpath/internal/education/rank.go @@ -0,0 +1,148 @@ +// Package education ranks public Arizona study options using transparent, +// balanced access signals. It does not claim to rank academic quality. +package education + +import ( + "errors" + "math" + "sort" + + "my-homelab-configs/cmd/nextpath/internal/opportunity" +) + +var ErrZIPUnavailable = errors.New("ZIP coordinate is unavailable") + +type RankedOption struct { + opportunity.EducationOption + DistanceMiles int `json:"distance_miles"` + ProximityScore int `json:"proximity_score"` + AffordabilityScore int `json:"affordability_score"` + AccessScore int `json:"access_score"` + ProgramStrength int `json:"program_strength_score"` + BalancedScore int `json:"balanced_score"` + CostLabel string `json:"cost_label"` + AccessLabel string `json:"access_label"` + StrengthLabel string `json:"strength_label"` +} + +// Rank returns options that balance proximity, in-state tuition, admissions +// accessibility, and a public-data program-strength signal. Strength combines +// exact-program completion volume with the institution-wide completion rate; +// it is not a third-party rating or guarantee of program quality. +func Rank(snapshot opportunity.Snapshot, onet, zipCode string, limit int) ([]RankedOption, error) { + origin, ok := snapshot.ZIPCoordinates[zipCode] + if !ok { + return nil, ErrZIPUnavailable + } + options := snapshot.EducationOptions[onet] + if limit <= 0 || len(options) == 0 { + return nil, nil + } + maxCompletions := 1 + for _, option := range options { + if option.ProgramCompletions > maxCompletions { + maxCompletions = option.ProgramCompletions + } + } + ranked := make([]RankedOption, 0, len(options)) + for _, option := range options { + distance := int(math.Round(haversine(origin.Latitude, origin.Longitude, option.Latitude, option.Longitude))) + proximity := proximityScore(distance) + affordability, costLabel := affordabilityScore(option.AnnualInStateTuition) + access, accessLabel := admissionScore(option) + volume := 40 + int(math.Round(60*math.Sqrt(float64(option.ProgramCompletions)/float64(maxCompletions)))) + completion := option.InstitutionCompletionRatePercent + if completion <= 0 { + completion = 50 + } + strength := int(math.Round(float64(volume)*0.6 + float64(completion)*0.4)) + balanced := int(math.Round(float64(proximity)*0.25 + float64(affordability)*0.25 + float64(access)*0.20 + float64(strength)*0.30)) + ranked = append(ranked, RankedOption{ + EducationOption: option, DistanceMiles: distance, ProximityScore: proximity, + AffordabilityScore: affordability, AccessScore: access, ProgramStrength: strength, + BalancedScore: balanced, CostLabel: costLabel, AccessLabel: accessLabel, + StrengthLabel: strengthLabel(strength), + }) + } + sort.SliceStable(ranked, func(i, j int) bool { + if ranked[i].BalancedScore == ranked[j].BalancedScore { + return ranked[i].DistanceMiles < ranked[j].DistanceMiles + } + return ranked[i].BalancedScore > ranked[j].BalancedScore + }) + if limit < len(ranked) { + ranked = ranked[:limit] + } + return ranked, nil +} + +func haversine(lat1, lon1, lat2, lon2 float64) float64 { + const earthMiles = 3958.8 + toRadians := math.Pi / 180 + dLat := (lat2 - lat1) * toRadians + dLon := (lon2 - lon1) * toRadians + a := math.Sin(dLat/2)*math.Sin(dLat/2) + math.Cos(lat1*toRadians)*math.Cos(lat2*toRadians)*math.Sin(dLon/2)*math.Sin(dLon/2) + return earthMiles * 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a)) +} + +func proximityScore(miles int) int { + switch { + case miles <= 15: + return 100 + case miles <= 40: + return 80 + case miles <= 80: + return 60 + case miles <= 150: + return 40 + default: + return 20 + } +} + +func affordabilityScore(tuition int) (int, string) { + switch { + case tuition <= 0: + return 50, "tuition not reported" + case tuition <= 6000: + return 100, "lower-cost" + case tuition <= 12000: + return 80, "moderate-cost" + case tuition <= 20000: + return 60, "upper-middle cost" + case tuition <= 30000: + return 40, "higher-cost" + default: + return 20, "highest-cost tier" + } +} + +func admissionScore(option opportunity.EducationOption) (int, string) { + if option.AdmissionBasis == "open admissions" { + return 100, "open admissions" + } + rate := option.AdmissionRatePercent + switch { + case rate >= 75: + return 90, "broad access" + case rate >= 50: + return 70, "moderate access" + case rate >= 25: + return 50, "selective" + case rate > 0: + return 30, "highly selective" + default: + return 50, "admission rate not reported" + } +} + +func strengthLabel(score int) string { + switch { + case score >= 80: + return "strong public-data signal" + case score >= 60: + return "established public-data signal" + default: + return "developing or limited-data signal" + } +} diff --git a/cmd/nextpath/internal/education/rank_test.go b/cmd/nextpath/internal/education/rank_test.go new file mode 100644 index 0000000..c8caad8 --- /dev/null +++ b/cmd/nextpath/internal/education/rank_test.go @@ -0,0 +1,35 @@ +package education + +import ( + "testing" + + "my-homelab-configs/cmd/nextpath/internal/opportunity" +) + +func TestRankBalancesAccessCostDistanceAndProgramStrength(t *testing.T) { + snapshot := opportunity.Snapshot{ + ZIPCoordinates: map[string]opportunity.Coordinates{"85001": {Latitude: 33.45, Longitude: -112.07}}, + EducationOptions: map[string][]opportunity.EducationOption{"17-2051.00": { + {Institution: "Balanced College", Latitude: 33.50, Longitude: -112.10, AnnualInStateTuition: 9000, AdmissionRatePercent: 70, AdmissionBasis: "reported admission rate", ProgramCompletions: 50, InstitutionCompletionRatePercent: 70}, + {Institution: "Expensive Selective University", Latitude: 33.45, Longitude: -112.07, AnnualInStateTuition: 40000, AdmissionRatePercent: 10, AdmissionBasis: "reported admission rate", ProgramCompletions: 100, InstitutionCompletionRatePercent: 95}, + {Institution: "Distant Open College", Latitude: 35.20, Longitude: -111.65, AnnualInStateTuition: 4000, AdmissionBasis: "open admissions", ProgramCompletions: 20, InstitutionCompletionRatePercent: 35}, + }}, + } + ranked, err := Rank(snapshot, "17-2051.00", "85001", 3) + if err != nil { + t.Fatal(err) + } + if len(ranked) != 3 || ranked[0].Institution != "Balanced College" { + t.Fatalf("unexpected balanced ranking: %+v", ranked) + } + if ranked[0].BalancedScore <= ranked[1].BalancedScore || ranked[0].StrengthLabel == "" { + t.Fatalf("ranking omitted transparent scores: %+v", ranked) + } +} + +func TestRankRequiresLocalZIPEvidence(t *testing.T) { + _, err := Rank(opportunity.Snapshot{}, "17-2051.00", "85001", 3) + if err != ErrZIPUnavailable { + t.Fatalf("error = %v, want ErrZIPUnavailable", err) + } +} diff --git a/cmd/nextpath/internal/web/server.go b/cmd/nextpath/internal/web/server.go index 909666a..14a3c1c 100644 --- a/cmd/nextpath/internal/web/server.go +++ b/cmd/nextpath/internal/web/server.go @@ -15,6 +15,7 @@ import ( "my-homelab-configs/cmd/nextpath/internal/account" "my-homelab-configs/cmd/nextpath/internal/assessment" "my-homelab-configs/cmd/nextpath/internal/career" + "my-homelab-configs/cmd/nextpath/internal/education" "my-homelab-configs/cmd/nextpath/internal/opportunity" ) @@ -33,7 +34,8 @@ type Config struct { type careerResult struct { career.Match - Outlook *opportunity.Outlook + Outlook *opportunity.Outlook + StudyOptions []education.RankedOption } type session struct { @@ -250,6 +252,11 @@ func (server *Server) results(writer http.ResponseWriter, request *http.Request) server.config.Logger.Warn("calculate NextPath employability outlook", "occupation", match.Occupation.ONETSOC, "error", calculateErr) } } + if options, rankErr := education.Rank(snapshot, match.Occupation.ONETSOC, user.ZIPCode, 3); rankErr == nil { + view.StudyOptions = options + } else { + server.config.Logger.Warn("rank NextPath education options", "occupation", match.Occupation.ONETSOC, "error", rankErr) + } careerResults = append(careerResults, view) } server.mu.Lock() diff --git a/cmd/nextpath/internal/web/server_test.go b/cmd/nextpath/internal/web/server_test.go index 4bcc33e..00cd969 100644 --- a/cmd/nextpath/internal/web/server_test.go +++ b/cmd/nextpath/internal/web/server_test.go @@ -31,7 +31,15 @@ func TestCompletePrivateAssessmentFlow(t *testing.T) { "graduate_academic_year":"2024","projection_period":"2024-2034","postings_observed_at":"2026-12-05T12:00:00Z", "geography":"Arizona","soc_to_cip_mapping_coverage":0.9, "graduate_source_url":"https://example.test/graduates","projection_source_url":"https://example.test/projections","posting_source_url":"https://example.test/jobs" - }}}`), 0o600); err != nil { + }}, + "education_options":{"13-2011.00":[{ + "unit_id":"100","institution":"Arizona Accounting College","city":"Phoenix","zip_code":"85001", + "latitude":33.45,"longitude":-112.07,"website":"https://example.test/study","cip6":"520301", + "award_levels":["5"],"program_completions":80,"annual_in_state_tuition":9000, + "admission_rate_percent":75,"admission_basis":"reported admission rate","institution_completion_rate_percent":70 + }]}, + "zip_coordinates":{"85001":{"latitude":33.45,"longitude":-112.07}} +}`), 0o600); err != nil { t.Fatal(err) } testServer := httptest.NewServer(New(accounts, Config{OpportunityStorePath: opportunityPath}).Handler()) @@ -68,7 +76,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 or identity") || !strings.Contains(body, "Careers to explore next") || !strings.Contains(body, "Employability today: 88%") || !strings.Contains(body, "Five-year outlook: 90%") || !strings.Contains(body, "2022: 100, 2023: 100, 2024: 100") || !strings.Contains(body, "Retake the quiz") { + if response.StatusCode != http.StatusOK || !strings.Contains(body, "interest profile") || !strings.Contains(body, "not ability or identity") || !strings.Contains(body, "Careers to explore next") || !strings.Contains(body, "Employability today: 88%") || !strings.Contains(body, "Five-year outlook: 90%") || !strings.Contains(body, "2022: 100, 2023: 100, 2024: 100") || !strings.Contains(body, "Retake the quiz") || !strings.Contains(body, "Arizona Accounting College") || !strings.Contains(body, "Balanced places to start studying") { 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 de78ed4..ad6fbd7 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}}

Careers to explore next

Interest fit and Arizona market outlook are separate signals. These percentages are market indexes, not your probability of being hired.

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

{{.Occupation.Title}}

{{.Occupation.Summary}}

{{.Reason}}

{{if .Outlook}}

Arizona market evidence

Employability today: {{.Outlook.TodayEmployabilityPercent}}% · {{.Outlook.TodayLabel}}

Five-year outlook: {{.Outlook.FiveYearEmployabilityPercent}}% · {{.Outlook.FiveYearLabel}}

{{.Outlook.Evidence.ArizonaProjectedOpenings}} projected openings/year and {{.Outlook.Evidence.ActivePostings}} sampled current postings. Arizona exact-program completions: {{.Outlook.Evidence.ArizonaGraduateHistory}}; three-year average {{.Outlook.ThreeYearAverageGraduates}}. Demand-to-average-graduates ratio: {{.Outlook.AnnualDemandToGraduateRatio}}.

Official projected employment growth: {{.Outlook.Evidence.ProjectedEmploymentGrowthPercent}}%. Historical graduate trend: {{.Outlook.GraduateAnnualTrendPercent}}%/year; modeled five-year graduate supply: {{.Outlook.ProjectedFiveYearGraduates}}.

Today = 75% projected annual demand coverage + 25% sampled current posting coverage. Five-year = 75% projected demand coverage against trend-modeled supply + 25% official employment-growth signal. Supply trend is capped at ±10%/year; official growth from -5% to +20% maps to the 0–100 growth signal. {{.Outlook.Confidence}} evidence confidence. Snapshot {{.Outlook.Evidence.PostingsObservedAt.Format "Jan 2, 2006"}}.

{{else}}

Arizona employability outlook unavailable. Complete source evidence has not been refreshed for this occupation; no percentage is estimated.

{{end}}

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 or identity. Market indexes are contextual evidence, not a hiring promise.

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

Interest fit and Arizona market outlook are separate signals. These percentages are market indexes, not your probability of being hired.

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

{{.Occupation.Title}}

{{.Occupation.Summary}}

{{.Reason}}

{{if .Outlook}}

Arizona market evidence

Employability today: {{.Outlook.TodayEmployabilityPercent}}% · {{.Outlook.TodayLabel}}

Five-year outlook: {{.Outlook.FiveYearEmployabilityPercent}}% · {{.Outlook.FiveYearLabel}}

{{.Outlook.Evidence.ArizonaProjectedOpenings}} projected openings/year and {{.Outlook.Evidence.ActivePostings}} sampled current postings. Arizona exact-program completions: {{.Outlook.Evidence.ArizonaGraduateHistory}}; three-year average {{.Outlook.ThreeYearAverageGraduates}}. Demand-to-average-graduates ratio: {{.Outlook.AnnualDemandToGraduateRatio}}.

Official projected employment growth: {{.Outlook.Evidence.ProjectedEmploymentGrowthPercent}}%. Historical graduate trend: {{.Outlook.GraduateAnnualTrendPercent}}%/year; modeled five-year graduate supply: {{.Outlook.ProjectedFiveYearGraduates}}.

Today = 75% projected annual demand coverage + 25% sampled current posting coverage. Five-year = 75% projected demand coverage against trend-modeled supply + 25% official employment-growth signal. Supply trend is capped at ±10%/year; official growth from -5% to +20% maps to the 0–100 growth signal. {{.Outlook.Confidence}} evidence confidence. Snapshot {{.Outlook.Evidence.PostingsObservedAt.Format "Jan 2, 2006"}}.

{{else}}

Arizona employability outlook unavailable. Complete source evidence has not been refreshed for this occupation; no percentage is estimated.

{{end}}{{if .StudyOptions}}

Balanced places to start studying

Ranked for your ZIP by 25% proximity, 25% in-state tuition, 20% admission access, and 30% program strength. Program strength combines exact-program completion volume and the institution-wide completion rate; it is not a third-party school rating.

{{range .StudyOptions}}
{{.Institution}}

{{.City}}, Arizona · about {{.DistanceMiles}} miles · balanced score {{.BalancedScore}}/100

{{.CostLabel}}{{if .AnnualInStateTuition}} · ${{.AnnualInStateTuition}} reported annual in-state tuition{{end}} · {{.AccessLabel}}{{if .AdmissionRatePercent}} ({{.AdmissionRatePercent}}% admitted){{end}}

{{.StrengthLabel}} · {{.ProgramCompletions}} exact-program completions ({{.ProgramYear}}) · {{.InstitutionCompletionRatePercent}}% institution completion rate · {{range .AwardLevels}}{{.}}; {{end}}

Tuition and admissions: {{.CostAdmissionYear}} IPEDS reporting year.

{{if .Website}}Explore this institution{{end}}
{{end}}
{{else}}

Study options unavailable. Complete public program, cost, access, quality, and ZIP evidence has not been refreshed for this occupation.

{{end}}

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 or identity. Market indexes are contextual evidence, not a hiring promise.

Export my data

Delete account

{{end}}` diff --git a/docs/nextpath-architecture.md b/docs/nextpath-architecture.md index 3c6e526..3e7ef7c 100644 --- a/docs/nextpath-architecture.md +++ b/docs/nextpath-architecture.md @@ -78,6 +78,26 @@ coverage, and confidence value. Missing evidence makes the percentage unavailable instead of silently becoming zero. The UI must label it "rough market estimate—not your chance of being hired." +### Balanced places to study + +For each recommended occupation, NextPath finds Arizona institutions reporting +completions in the exact six-digit CIP program. It ranks up to three options +for the user's ZIP with a deliberately balanced score: + +| Signal | Weight | Evidence | +| --- | ---: | --- | +| Proximity | 25 | Great-circle distance from the user's Census ZIP-area coordinate to the IPEDS institution coordinate | +| Affordability | 25 | Reported annual in-state tuition tier | +| Admission access | 20 | Open admissions or the reported admission rate | +| Program strength | 30 | 60% exact-program completion volume and 40% institution-wide completion rate | + +The strength component is a public-data signal, not a third-party rating or a +claim about teaching quality. The balanced score prevents a nearby but very +expensive/selective institution—or a cheap but distant option with little +program evidence—from winning on one dimension alone. The UI displays every +component, source year, raw count, distance, and limitation. The user's ZIP is +matched locally and is never sent to a geocoding API. + ## Data contracts Occupation records use O*NET-SOC identifiers. Education programs use CIP codes. @@ -90,6 +110,7 @@ from: - IPEDS annual completion files with exact six-digit CIP programs; - Arizona CTE and registered apprenticeship directories; - Ayla's public feed of government and official-source job postings. +- Census ZIP Code Tabulation Area representative coordinates. Remote source data is cached with retrieval timestamps and source attribution. Job listings are short-lived examples, are linked to their publisher, and do