Automate NextPath market evidence refresh
Homelab Main / validate (push) Failing after 1m35s Details
Homelab Main / running-update (push) Has been skipped Details
Homelab Main / debian-ops (push) Has been skipped Details

This commit is contained in:
juvenal.diaz 2026-12-05 14:06:50 -06:00
parent 6c7bcc7c1b
commit e00e1be795
9 changed files with 125 additions and 14 deletions

View File

@ -11,7 +11,7 @@ four kinds of evidence without pretending they are interchangeable:
The product does not calculate a person's probability of being hired. It
publishes a transparent **Arizona employability outlook percentage** comparing
annual graduates, projected annual openings, and current entry-level postings.
annual completions, projected annual openings, and current occupation postings.
Raw counts, dates, geography, sources, and limitations remain visible beside
the percentage.
@ -33,3 +33,23 @@ Redeployments never recreate the account store. Jeannie migrates the original
manual-preview file from `/data/homelab-nextpath/accounts.json` when needed and
writes a mode-0600 pre-deploy backup under `/data/homelab-nextpath/backups`.
## Enable the Arizona employability outlook
College Scorecard completion data is public. Projected openings and current
postings use the official CareerOneStop API, which requires a free API user ID
and token. Supply them only for the first deployment (or when rotating them):
```bash
read -r -p "CareerOneStop user ID: " career_user
read -r -s -p "CareerOneStop API token: " career_token; echo
LAB_NEXTPATH_CAREERONESTOP_USER_ID="$career_user" \
LAB_NEXTPATH_CAREERONESTOP_API_TOKEN="$career_token" \
./jeannie deploy-nextpath
unset career_user career_token
```
Jeannie stores the values in private mode-0600 files, refreshes evidence once
immediately, and installs a daily systemd timer. Later deployments reuse the
private credentials and the last successful evidence snapshot. Neither values
nor raw source responses are exposed to browsers.

View File

@ -15,7 +15,7 @@ var ErrInsufficientEvidence = errors.New("insufficient evidence for employabilit
type Evidence struct {
ArizonaAnnualGraduates int `json:"arizona_annual_graduates"`
ArizonaProjectedOpenings int `json:"arizona_projected_annual_openings"`
ActiveEntryLevelPostings int `json:"active_entry_level_postings"`
ActivePostings int `json:"active_postings"`
GraduateAcademicYear string `json:"graduate_academic_year"`
ProjectionPeriod string `json:"projection_period"`
PostingsObservedAt time.Time `json:"postings_observed_at"`
@ -39,10 +39,10 @@ type Outlook struct {
}
// Calculate uses projected annual openings for the stable 75-percent signal
// and a current entry-level posting snapshot for the remaining 25 percent.
// and a current occupation posting snapshot for the remaining 25 percent.
// The result is market context, not a personal hiring probability.
func Calculate(evidence Evidence) (Outlook, error) {
if evidence.ArizonaAnnualGraduates <= 0 || evidence.ArizonaProjectedOpenings < 0 || evidence.ActiveEntryLevelPostings < 0 {
if evidence.ArizonaAnnualGraduates <= 0 || evidence.ArizonaProjectedOpenings < 0 || evidence.ActivePostings < 0 {
return Outlook{}, ErrInsufficientEvidence
}
if evidence.GraduateAcademicYear == "" || evidence.ProjectionPeriod == "" || evidence.PostingsObservedAt.IsZero() || evidence.Geography == "" {
@ -56,7 +56,7 @@ func Calculate(evidence Evidence) (Outlook, error) {
}
annualRatio := float64(evidence.ArizonaProjectedOpenings) / float64(evidence.ArizonaAnnualGraduates)
liveRatio := float64(evidence.ActiveEntryLevelPostings) / float64(evidence.ArizonaAnnualGraduates)
liveRatio := float64(evidence.ActivePostings) / float64(evidence.ArizonaAnnualGraduates)
annualCoverage := cappedPercent(annualRatio)
liveCoverage := cappedPercent(liveRatio)
outlookPercent := int(math.Round(float64(annualCoverage)*0.75 + float64(liveCoverage)*0.25))
@ -78,7 +78,7 @@ func Calculate(evidence Evidence) (Outlook, error) {
Confidence: confidence,
Limitations: []string{
"Rough market estimate—not your chance of being hired.",
"Current postings are a changing snapshot and may contain incomplete entry-level labels.",
"Current postings are a changing snapshot and include varying experience levels.",
"Graduates may enter other occupations, and workers may enter without a mapped Arizona program.",
},
Evidence: evidence,

View File

@ -9,7 +9,7 @@ import (
func completeEvidence() Evidence {
return Evidence{
ArizonaAnnualGraduates: 1000, ArizonaProjectedOpenings: 800,
ActiveEntryLevelPostings: 200, GraduateAcademicYear: "2024-25",
ActivePostings: 200, GraduateAcademicYear: "2024-25",
ProjectionPeriod: "2024-2034", PostingsObservedAt: time.Date(2026, 12, 5, 12, 0, 0, 0, time.UTC),
Geography: "Arizona", SOCToCIPMappingCoverage: 0.9,
GraduateSourceURL: "https://example.test/graduates", ProjectionSourceURL: "https://example.test/projections",
@ -39,7 +39,7 @@ func TestCalculateShowsTransparentBoundedOutlook(t *testing.T) {
func TestDemandAboveGraduatesRetainsUncappedRatio(t *testing.T) {
evidence := completeEvidence()
evidence.ArizonaProjectedOpenings = 2400
evidence.ActiveEntryLevelPostings = 1500
evidence.ActivePostings = 1500
outlook, err := Calculate(evidence)
if err != nil {
t.Fatal(err)

View File

@ -26,7 +26,7 @@ func TestCompletePrivateAssessmentFlow(t *testing.T) {
opportunityPath := filepath.Join(t.TempDir(), "opportunity.json")
if err := os.WriteFile(opportunityPath, []byte(`{
"version":"v1","generated_at":"2026-12-05T12:00:00Z","occupations":{"13-2011.00":{
"arizona_annual_graduates":100,"arizona_projected_annual_openings":100,"active_entry_level_postings":50,
"arizona_annual_graduates":100,"arizona_projected_annual_openings":100,"active_postings":50,
"graduate_academic_year":"latest","projection_period":"2022-2032","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"

View File

@ -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>Careers to explore next</h2><p class="muted">Interest fit and Arizona market outlook are separate signals. The market percentage is a rough demand-to-completions comparison, not your probability of being hired.</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>{{if .Outlook}}<div class="outlook"><strong>Arizona employability outlook: {{.Outlook.EmployabilityOutlookPercent}}%</strong><p>{{.Outlook.Label}} · {{.Outlook.Confidence}} evidence confidence</p><p class="small">{{.Outlook.Evidence.ArizonaProjectedOpenings}} projected openings/year and {{.Outlook.Evidence.ActiveEntryLevelPostings}} postings observed, compared with {{.Outlook.Evidence.ArizonaAnnualGraduates}} recent Arizona completions. Demand-to-completions ratio: {{.Outlook.AnnualDemandToGraduateRatio}}.</p><p class="small muted">Formula: 75% projected annual demand coverage + 25% current posting coverage. Posting snapshot {{.Outlook.Evidence.PostingsObservedAt.Format "Jan 2, 2006"}}.</p><div class="small"><a href="{{.Outlook.Evidence.GraduateSourceURL}}" rel="noreferrer">Completion source</a> · <a href="{{.Outlook.Evidence.ProjectionSourceURL}}" rel="noreferrer">Projection source</a> · <a href="{{.Outlook.Evidence.PostingSourceURL}}" rel="noreferrer">Posting source</a></div></div>{{else}}<p class="muted"><strong>Arizona employability outlook unavailable.</strong> Complete source evidence has not been refreshed for this occupation; no percentage is estimated.</p>{{end}}<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 or identity. Market outlook is contextual evidence, not a hiring promise.</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">Interest fit and Arizona market outlook are separate signals. The market percentage is a rough demand-to-completions comparison, not your probability of being hired.</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>{{if .Outlook}}<div class="outlook"><strong>Arizona employability outlook: {{.Outlook.EmployabilityOutlookPercent}}%</strong><p>{{.Outlook.Label}} · {{.Outlook.Confidence}} evidence confidence</p><p class="small">{{.Outlook.Evidence.ArizonaProjectedOpenings}} projected openings/year and {{.Outlook.Evidence.ActivePostings}} current postings observed, compared with {{.Outlook.Evidence.ArizonaAnnualGraduates}} recent Arizona completions. Demand-to-completions ratio: {{.Outlook.AnnualDemandToGraduateRatio}}.</p><p class="small muted">Formula: 75% projected annual demand coverage + 25% current posting coverage. Postings include varying experience levels. Snapshot {{.Outlook.Evidence.PostingsObservedAt.Format "Jan 2, 2006"}}.</p><div class="small"><a href="{{.Outlook.Evidence.GraduateSourceURL}}" rel="noreferrer">Completion source</a> · <a href="{{.Outlook.Evidence.ProjectionSourceURL}}" rel="noreferrer">Projection source</a> · <a href="{{.Outlook.Evidence.PostingSourceURL}}" rel="noreferrer">Posting source</a></div></div>{{else}}<p class="muted"><strong>Arizona employability outlook unavailable.</strong> Complete source evidence has not been refreshed for this occupation; no percentage is estimated.</p>{{end}}<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 or identity. Market outlook is contextual evidence, not a hiring promise.</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}}`

View File

@ -61,7 +61,7 @@ authorization, or employer decisions.
| Component | Weight | Evidence |
| --- | ---: | --- |
| Annual demand coverage | 75 | Projected annual Arizona openings divided by annual Arizona completers |
| Live posting coverage | 25 | Current deduplicated entry-level postings divided by annual Arizona completers |
| Live posting coverage | 25 | Current occupation postings divided by annual Arizona completers |
Each coverage value is capped at 100 before weighting. The UI also shows the
uncapped annual openings-to-graduates ratio, so a shortage is not hidden when
@ -91,6 +91,14 @@ Remote source data is cached with retrieval timestamps and source attribution.
Job listings are short-lived examples, are linked to their publisher, and do
not become training data or evidence of guaranteed employment.
Jeannie refreshes the cache daily from the public College Scorecard API and
CareerOneStop. The latter requires a private API user ID and bearer token.
They are stored as mode `0600` files outside release directories and are never
sent to the browser. A refresh replaces the cache atomically only after every
catalog occupation has all three inputs; failures preserve the last successful
snapshot. With no complete snapshot, the results page says the outlook is
unavailable rather than presenting a synthetic percentage.
## Recommendation boundary
Deterministic code performs assessment scoring, eligibility filtering,

View File

@ -6023,6 +6023,10 @@ deploy_nextpath() {
local legacy_account_store="${install_dir}/accounts.json"
local backup_dir="${install_dir}/backups"
local backup_timestamp=""
local opportunity_store="${install_dir}/data/opportunity.json"
local credential_dir="${install_dir}/credentials"
local career_user_file="${credential_dir}/careeronestop-user-id"
local career_token_file="${credential_dir}/careeronestop-token"
local elapsed=0
require_debian_server "deploy-nextpath"
@ -6042,7 +6046,7 @@ deploy_nextpath() {
true|false) ;;
*) echo "LAB_NEXTPATH_SECURE_COOKIES must be true or false." >&2; return 1 ;;
esac
for required in go curl systemctl; do
for required in go curl systemctl python3; do
if ! command -v "${required}" >/dev/null 2>&1; then
echo "NextPath deployment requires ${required} on Debian." >&2
return 1
@ -6052,9 +6056,21 @@ deploy_nextpath() {
release_id="$(git -C "${REPO_ROOT}" rev-parse --verify HEAD)"
release_dir="${install_dir}/releases/${release_id}"
sudo install -d -o "${service_user}" -g "${service_user}" -m 0750 \
"${install_dir}" "${install_dir}/releases" "${install_dir}/data" "${backup_dir}"
"${install_dir}" "${install_dir}/releases" "${install_dir}/data" "${backup_dir}" "${credential_dir}"
sudo chmod 0700 "${install_dir}/data"
sudo chmod 0700 "${backup_dir}"
sudo chmod 0700 "${credential_dir}"
if [[ -n "${LAB_NEXTPATH_CAREERONESTOP_USER_ID:-}" || -n "${LAB_NEXTPATH_CAREERONESTOP_API_TOKEN:-}" ]]; then
if [[ -z "${LAB_NEXTPATH_CAREERONESTOP_USER_ID:-}" || -z "${LAB_NEXTPATH_CAREERONESTOP_API_TOKEN:-}" ]]; then
echo "Both LAB_NEXTPATH_CAREERONESTOP_USER_ID and LAB_NEXTPATH_CAREERONESTOP_API_TOKEN are required." >&2
return 1
fi
printf '%s' "${LAB_NEXTPATH_CAREERONESTOP_USER_ID}" | sudo tee "${career_user_file}" >/dev/null
printf '%s' "${LAB_NEXTPATH_CAREERONESTOP_API_TOKEN}" | sudo tee "${career_token_file}" >/dev/null
sudo chown "${service_user}:${service_user}" "${career_user_file}" "${career_token_file}"
sudo chmod 0600 "${career_user_file}" "${career_token_file}"
fi
# The initial manual-preview instructions used the install root. Migrate
# that file once, without ever replacing a store already managed by the
@ -6078,13 +6094,50 @@ deploy_nextpath() {
echo "Preserved a private pre-deploy NextPath account backup in ${backup_dir}."
fi
sudo -u "${service_user}" install -d -m 0750 "${release_dir}"
sudo -u "${service_user}" install -d -m 0750 "${release_dir}/scripts" "${release_dir}/data"
(
cd "${REPO_ROOT}"
GOTOOLCHAIN=local go test ./cmd/nextpath/...
GOTOOLCHAIN=local go build -trimpath -o "${release_dir}/nextpath" ./cmd/nextpath
)
sudo install -o "${service_user}" -g "${service_user}" -m 0550 \
"${REPO_ROOT}/scripts/nextpath-opportunity-refresh.py" "${release_dir}/scripts/nextpath-opportunity-refresh.py"
sudo install -o "${service_user}" -g "${service_user}" -m 0440 \
"${REPO_ROOT}/apps/nextpath/data/soc-cip-map.json" "${release_dir}/data/soc-cip-map.json"
sudo -u "${service_user}" ln -sfn "${release_dir}" "${install_dir}/current"
sudo tee /etc/systemd/system/nextpath-opportunity-refresh.service >/dev/null <<UNIT_EOF
[Unit]
Description=Refresh source-attributed NextPath Arizona labor evidence
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
User=${service_user}
Group=${service_user}
WorkingDirectory=${install_dir}/current
ExecStart=/usr/bin/python3 ${install_dir}/current/scripts/nextpath-opportunity-refresh.py --mapping ${install_dir}/current/data/soc-cip-map.json --output ${opportunity_store} --user-id-file ${career_user_file} --token-file ${career_token_file}
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=${install_dir}/data
UNIT_EOF
sudo tee /etc/systemd/system/nextpath-opportunity-refresh.timer >/dev/null <<UNIT_EOF
[Unit]
Description=Refresh NextPath Arizona labor evidence daily
[Timer]
OnCalendar=daily
RandomizedDelaySec=2h
Persistent=true
[Install]
WantedBy=timers.target
UNIT_EOF
sudo tee /etc/systemd/system/nextpath.service >/dev/null <<UNIT_EOF
[Unit]
Description=NextPath Arizona career exploration WIP
@ -6098,6 +6151,7 @@ Group=${service_user}
WorkingDirectory=${install_dir}/current
Environment=NEXTPATH_ADDRESS=${bind_ip}:${http_port}
Environment=NEXTPATH_ACCOUNT_STORE=${account_store}
Environment=NEXTPATH_OPPORTUNITY_STORE=${opportunity_store}
Environment=NEXTPATH_SECURE_COOKIES=${secure_cookies}
ExecStart=${install_dir}/current/nextpath
Restart=on-failure
@ -6112,6 +6166,21 @@ ReadWritePaths=${install_dir}/data
WantedBy=multi-user.target
UNIT_EOF
sudo systemctl daemon-reload
if sudo test -s "${career_user_file}" && sudo test -s "${career_token_file}"; then
if ! sudo systemctl start nextpath-opportunity-refresh.service; then
if sudo test -s "${opportunity_store}"; then
echo "Warning: NextPath evidence refresh failed; preserving the last successful snapshot." >&2
else
echo "NextPath evidence refresh failed and no prior snapshot is available." >&2
sudo journalctl -u nextpath-opportunity-refresh.service -n 50 --no-pager >&2 || true
return 1
fi
fi
sudo systemctl enable --now nextpath-opportunity-refresh.timer
else
sudo systemctl disable --now nextpath-opportunity-refresh.timer >/dev/null 2>&1 || true
echo "NextPath labor refresh is waiting for private CareerOneStop credentials; existing evidence cache was preserved."
fi
sudo systemctl enable nextpath.service
sudo systemctl restart nextpath.service

View File

@ -109,7 +109,7 @@ def refresh(mapping_path: Path, output_path: Path, user_id: str, token: str, api
occupations[onet] = {
"arizona_annual_graduates": graduates,
"arizona_projected_annual_openings": openings,
"active_entry_level_postings": postings,
"active_postings": postings,
"graduate_academic_year": "latest College Scorecard IPEDS awards cohort",
"projection_period": period,
"postings_observed_at": observed.isoformat().replace("+00:00", "Z"),
@ -144,8 +144,14 @@ def main() -> None:
parser.add_argument("--output", type=Path, required=True)
parser.add_argument("--user-id", default=os.environ.get("CAREERONESTOP_USER_ID", ""))
parser.add_argument("--token", default=os.environ.get("CAREERONESTOP_API_TOKEN", ""))
parser.add_argument("--user-id-file", type=Path)
parser.add_argument("--token-file", type=Path)
parser.add_argument("--data-gov-key", default=os.environ.get("DATA_GOV_API_KEY", "DEMO_KEY"))
args = parser.parse_args()
if args.user_id_file:
args.user_id = args.user_id_file.read_text().strip()
if args.token_file:
args.token = args.token_file.read_text().strip()
if not args.user_id or not args.token:
parser.error("CareerOneStop user ID and API token are required")
refresh(args.mapping, args.output, args.user_id, args.token, args.data_gov_key)

View File

@ -15,6 +15,14 @@ class NextPathPipelineTests(unittest.TestCase):
self.assertIn('require_debian_server "deploy-nextpath"', pipeline)
self.assertIn("GOTOOLCHAIN=local go test ./cmd/nextpath/...", pipeline)
self.assertIn("NEXTPATH_ACCOUNT_STORE=${account_store}", pipeline)
self.assertIn("NEXTPATH_OPPORTUNITY_STORE=${opportunity_store}", pipeline)
self.assertIn("nextpath-opportunity-refresh.timer", pipeline)
self.assertIn("LAB_NEXTPATH_CAREERONESTOP_API_TOKEN", pipeline)
self.assertIn("--token-file ${career_token_file}", pipeline)
self.assertLess(
pipeline.index("systemctl start nextpath-opportunity-refresh.service"),
pipeline.index("systemctl restart nextpath.service"),
)
self.assertIn("ReadWritePaths=${install_dir}/data", pipeline)
self.assertIn("sudo chmod 0700", pipeline)
self.assertIn('legacy_account_store="${install_dir}/accounts.json"', pipeline)