182 lines
7.6 KiB
Go
182 lines
7.6 KiB
Go
// Package opportunity calculates transparent labor-market signals. It does
|
|
// not predict whether an individual will be hired.
|
|
package opportunity
|
|
|
|
import (
|
|
"errors"
|
|
"math"
|
|
"sort"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const FormulaVersion = "az-employability-outlook-v2"
|
|
|
|
var ErrInsufficientEvidence = errors.New("insufficient evidence for employability outlook")
|
|
|
|
type Evidence struct {
|
|
ArizonaAnnualGraduates int `json:"arizona_annual_graduates"`
|
|
ArizonaGraduateHistory GraduateHistory `json:"arizona_graduate_history"`
|
|
ArizonaProjectedOpenings int `json:"arizona_projected_annual_openings"`
|
|
ProjectedEmploymentGrowthPercent float64 `json:"projected_employment_growth_percent"`
|
|
ActivePostings int `json:"active_postings"`
|
|
GraduateAcademicYear string `json:"graduate_academic_year"`
|
|
ProjectionPeriod string `json:"projection_period"`
|
|
PostingsObservedAt time.Time `json:"postings_observed_at"`
|
|
Geography string `json:"geography"`
|
|
SOCToCIPMappingCoverage float64 `json:"soc_to_cip_mapping_coverage"`
|
|
GraduateSourceURL string `json:"graduate_source_url"`
|
|
ProjectionSourceURL string `json:"projection_source_url"`
|
|
PostingSourceURL string `json:"posting_source_url"`
|
|
}
|
|
|
|
type Outlook struct {
|
|
FormulaVersion string `json:"formula_version"`
|
|
TodayEmployabilityPercent int `json:"today_employability_percent"`
|
|
FiveYearEmployabilityPercent int `json:"five_year_employability_percent"`
|
|
AnnualDemandCoveragePercent int `json:"annual_demand_coverage_percent"`
|
|
LivePostingCoveragePercent int `json:"live_posting_coverage_percent"`
|
|
FiveYearDemandCoveragePercent int `json:"five_year_demand_coverage_percent"`
|
|
GrowthSignalPercent int `json:"growth_signal_percent"`
|
|
AnnualDemandToGraduateRatio float64 `json:"annual_demand_to_graduate_ratio"`
|
|
ThreeYearAverageGraduates int `json:"three_year_average_graduates"`
|
|
ProjectedFiveYearGraduates int `json:"projected_five_year_graduates"`
|
|
GraduateAnnualTrendPercent float64 `json:"graduate_annual_trend_percent"`
|
|
TodayLabel string `json:"today_label"`
|
|
FiveYearLabel string `json:"five_year_label"`
|
|
Confidence string `json:"confidence"`
|
|
Limitations []string `json:"limitations"`
|
|
Evidence Evidence `json:"evidence"`
|
|
}
|
|
|
|
// Calculate creates two market indexes. Today's index combines projected
|
|
// annual openings with a live posting sample against the three-year average of
|
|
// exact Arizona CIP completions. The five-year index combines future demand
|
|
// coverage against trend-projected graduate supply with the official
|
|
// employment-growth projection. Neither index is a hiring probability.
|
|
func Calculate(evidence Evidence) (Outlook, error) {
|
|
average, trend, ok := graduateHistory(evidence.ArizonaGraduateHistory)
|
|
if !ok || evidence.ArizonaAnnualGraduates <= 0 || evidence.ArizonaProjectedOpenings < 0 || evidence.ActivePostings < 0 {
|
|
return Outlook{}, ErrInsufficientEvidence
|
|
}
|
|
if evidence.GraduateAcademicYear == "" || evidence.ProjectionPeriod == "" || evidence.PostingsObservedAt.IsZero() || evidence.Geography == "" {
|
|
return Outlook{}, ErrInsufficientEvidence
|
|
}
|
|
if evidence.GraduateSourceURL == "" || evidence.ProjectionSourceURL == "" || evidence.PostingSourceURL == "" {
|
|
return Outlook{}, ErrInsufficientEvidence
|
|
}
|
|
if evidence.SOCToCIPMappingCoverage <= 0 || evidence.SOCToCIPMappingCoverage > 1 {
|
|
return Outlook{}, ErrInsufficientEvidence
|
|
}
|
|
|
|
annualRatio := float64(evidence.ArizonaProjectedOpenings) / float64(average)
|
|
liveRatio := float64(evidence.ActivePostings) / float64(evidence.ArizonaAnnualGraduates)
|
|
annualCoverage := cappedPercent(annualRatio)
|
|
liveCoverage := cappedPercent(liveRatio)
|
|
today := int(math.Round(float64(annualCoverage)*0.75 + float64(liveCoverage)*0.25))
|
|
|
|
// Supply growth is deliberately capped at +/-10% per year so one unusual
|
|
// completion year cannot dominate the five-year result.
|
|
projectionTrend := math.Min(0.10, math.Max(-0.10, trend))
|
|
projectedGraduates := int(math.Round(float64(evidence.ArizonaAnnualGraduates) * math.Pow(1+projectionTrend, 5)))
|
|
if projectedGraduates < 1 {
|
|
projectedGraduates = 1
|
|
}
|
|
futureCoverage := cappedPercent(float64(evidence.ArizonaProjectedOpenings) / float64(projectedGraduates))
|
|
// Official growth of -5% maps to zero and +20% maps to 100, with values
|
|
// outside that range capped. This makes the scale explicit and stable.
|
|
growthSignal := cappedPercent((evidence.ProjectedEmploymentGrowthPercent + 5) / 25)
|
|
fiveYear := int(math.Round(float64(futureCoverage)*0.75 + float64(growthSignal)*0.25))
|
|
|
|
confidence := "lower"
|
|
if evidence.SOCToCIPMappingCoverage >= 0.8 {
|
|
confidence = "higher"
|
|
} else if evidence.SOCToCIPMappingCoverage >= 0.5 {
|
|
confidence = "moderate"
|
|
}
|
|
|
|
return Outlook{
|
|
FormulaVersion: FormulaVersion,
|
|
TodayEmployabilityPercent: today,
|
|
FiveYearEmployabilityPercent: fiveYear,
|
|
AnnualDemandCoveragePercent: annualCoverage,
|
|
LivePostingCoveragePercent: liveCoverage,
|
|
FiveYearDemandCoveragePercent: futureCoverage,
|
|
GrowthSignalPercent: growthSignal,
|
|
AnnualDemandToGraduateRatio: math.Round(annualRatio*100) / 100,
|
|
ThreeYearAverageGraduates: average,
|
|
ProjectedFiveYearGraduates: projectedGraduates,
|
|
GraduateAnnualTrendPercent: math.Round(trend*10000) / 100,
|
|
TodayLabel: outlookLabel(today),
|
|
FiveYearLabel: outlookLabel(fiveYear),
|
|
Confidence: confidence,
|
|
Limitations: []string{
|
|
"Market indexes—not your chance of being hired.",
|
|
"Current postings are a changing sample of government and official hiring sources, not the whole Arizona market.",
|
|
"Graduate supply is projected from three historical years and cannot predict enrollment, migration, or career changes.",
|
|
"Graduates may enter other occupations, and workers may enter without a mapped Arizona program.",
|
|
},
|
|
Evidence: evidence,
|
|
}, nil
|
|
}
|
|
|
|
type GraduateHistory map[string]int
|
|
|
|
func (history GraduateHistory) String() string {
|
|
years := make([]string, 0, len(history))
|
|
for year := range history {
|
|
years = append(years, year)
|
|
}
|
|
sort.Strings(years)
|
|
parts := make([]string, 0, len(years))
|
|
for _, year := range years {
|
|
parts = append(parts, year+": "+strconv.Itoa(history[year]))
|
|
}
|
|
return strings.Join(parts, ", ")
|
|
}
|
|
|
|
func graduateHistory(history map[string]int) (int, float64, bool) {
|
|
if len(history) < 3 {
|
|
return 0, 0, false
|
|
}
|
|
years := make([]string, 0, len(history))
|
|
total := 0
|
|
for year, graduates := range history {
|
|
if graduates < 0 {
|
|
return 0, 0, false
|
|
}
|
|
years = append(years, year)
|
|
total += graduates
|
|
}
|
|
sort.Strings(years)
|
|
average := int(math.Round(float64(total) / float64(len(years))))
|
|
if average <= 0 {
|
|
return 0, 0, false
|
|
}
|
|
oldest := history[years[0]]
|
|
latest := history[years[len(years)-1]]
|
|
trend := 0.0
|
|
if oldest > 0 {
|
|
trend = (float64(latest-oldest) / float64(oldest)) / float64(len(years)-1)
|
|
}
|
|
return average, trend, true
|
|
}
|
|
|
|
func cappedPercent(ratio float64) int {
|
|
return int(math.Round(math.Min(1, math.Max(0, ratio)) * 100))
|
|
}
|
|
|
|
func outlookLabel(percent int) string {
|
|
switch {
|
|
case percent >= 80:
|
|
return "strong demand relative to graduate supply"
|
|
case percent >= 50:
|
|
return "moderate demand relative to graduate supply"
|
|
case percent >= 25:
|
|
return "competitive market"
|
|
default:
|
|
return "limited visible demand relative to graduate supply"
|
|
}
|
|
}
|