Add versioned NextPath interest assessment
This commit is contained in:
parent
7da4512e29
commit
1b41035ca5
|
|
@ -0,0 +1,215 @@
|
|||
// Package assessment implements NextPath's versioned career-interest inventory.
|
||||
// It deliberately contains no HTTP, persistence, or recommendation logic.
|
||||
package assessment
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
)
|
||||
|
||||
const (
|
||||
BankVersion = "nextpath-interest-v1"
|
||||
MinAnswer = 1
|
||||
MaxAnswer = 5
|
||||
)
|
||||
|
||||
// Dimension is one of the six RIASEC interest dimensions.
|
||||
type Dimension string
|
||||
|
||||
const (
|
||||
Realistic Dimension = "R"
|
||||
Investigative Dimension = "I"
|
||||
Artistic Dimension = "A"
|
||||
Social Dimension = "S"
|
||||
Enterprising Dimension = "E"
|
||||
Conventional Dimension = "C"
|
||||
)
|
||||
|
||||
var Dimensions = []Dimension{
|
||||
Realistic, Investigative, Artistic, Social, Enterprising, Conventional,
|
||||
}
|
||||
|
||||
type Question struct {
|
||||
ID string `json:"id"`
|
||||
Dimension Dimension `json:"dimension"`
|
||||
Prompt string `json:"prompt"`
|
||||
}
|
||||
|
||||
type DimensionScore struct {
|
||||
Dimension Dimension `json:"dimension"`
|
||||
Raw int `json:"raw"`
|
||||
Answered int `json:"answered"`
|
||||
Percent int `json:"percent"`
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
Version string `json:"version"`
|
||||
Scores []DimensionScore `json:"scores"`
|
||||
Code string `json:"code"`
|
||||
Answered int `json:"answered"`
|
||||
TotalQuestions int `json:"total_questions"`
|
||||
Completeness int `json:"completeness_percent"`
|
||||
Confidence string `json:"confidence"`
|
||||
ResearchUseOnly bool `json:"research_use_only"`
|
||||
InstrumentNotice string `json:"instrument_notice"`
|
||||
}
|
||||
|
||||
// Questions is an original exploratory RIASEC-aligned bank. It is not the
|
||||
// official O*NET Interest Profiler and must not be represented as validated.
|
||||
var Questions = []Question{
|
||||
{ID: "r01", Dimension: Realistic, Prompt: "Build or repair something using tools."},
|
||||
{ID: "r02", Dimension: Realistic, Prompt: "Work outdoors or with plants, animals, or equipment."},
|
||||
{ID: "r03", Dimension: Realistic, Prompt: "Operate a machine or learn how a physical system works."},
|
||||
{ID: "r04", Dimension: Realistic, Prompt: "Solve a practical problem by making or testing a prototype."},
|
||||
{ID: "r05", Dimension: Realistic, Prompt: "Do work where you can see a concrete result at the end."},
|
||||
{ID: "i01", Dimension: Investigative, Prompt: "Investigate why a system, event, or organism behaves as it does."},
|
||||
{ID: "i02", Dimension: Investigative, Prompt: "Analyze data to discover a pattern or explain a problem."},
|
||||
{ID: "i03", Dimension: Investigative, Prompt: "Learn a difficult scientific or technical subject in depth."},
|
||||
{ID: "i04", Dimension: Investigative, Prompt: "Design an experiment or compare competing explanations."},
|
||||
{ID: "i05", Dimension: Investigative, Prompt: "Spend time solving a complex problem with no obvious answer."},
|
||||
{ID: "a01", Dimension: Artistic, Prompt: "Create an original story, image, performance, or design."},
|
||||
{ID: "a02", Dimension: Artistic, Prompt: "Express an idea through writing, music, video, or visual media."},
|
||||
{ID: "a03", Dimension: Artistic, Prompt: "Improve how a product or experience looks and feels."},
|
||||
{ID: "a04", Dimension: Artistic, Prompt: "Work on an open-ended project with room for imagination."},
|
||||
{ID: "a05", Dimension: Artistic, Prompt: "Notice and refine details of style, composition, or language."},
|
||||
{ID: "s01", Dimension: Social, Prompt: "Teach someone a skill or explain a difficult idea clearly."},
|
||||
{ID: "s02", Dimension: Social, Prompt: "Listen to a person and help them work through a problem."},
|
||||
{ID: "s03", Dimension: Social, Prompt: "Support the health, learning, or well-being of other people."},
|
||||
{ID: "s04", Dimension: Social, Prompt: "Collaborate closely with a group toward a shared result."},
|
||||
{ID: "s05", Dimension: Social, Prompt: "Make a new person feel included and understood."},
|
||||
{ID: "e01", Dimension: Enterprising, Prompt: "Persuade people to support an idea, product, or plan."},
|
||||
{ID: "e02", Dimension: Enterprising, Prompt: "Lead a group and take responsibility for its outcome."},
|
||||
{ID: "e03", Dimension: Enterprising, Prompt: "Start a project, organization, or small business."},
|
||||
{ID: "e04", Dimension: Enterprising, Prompt: "Negotiate priorities, resources, or an agreement."},
|
||||
{ID: "e05", Dimension: Enterprising, Prompt: "Make decisions when the situation is uncertain."},
|
||||
{ID: "c01", Dimension: Conventional, Prompt: "Organize records so other people can find and trust them."},
|
||||
{ID: "c02", Dimension: Conventional, Prompt: "Follow a detailed process and check that every step is correct."},
|
||||
{ID: "c03", Dimension: Conventional, Prompt: "Plan schedules, budgets, or inventories."},
|
||||
{ID: "c04", Dimension: Conventional, Prompt: "Find and correct inconsistencies in information."},
|
||||
{ID: "c05", Dimension: Conventional, Prompt: "Create a reliable system for recurring work."},
|
||||
}
|
||||
|
||||
var ErrIncomplete = errors.New("assessment is incomplete")
|
||||
|
||||
func questionIndex() map[string]Question {
|
||||
index := make(map[string]Question, len(Questions))
|
||||
for _, question := range Questions {
|
||||
index[question.ID] = question
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
// Score validates and scores answers on a one-to-five interest scale. Unknown
|
||||
// question IDs and duplicate dimensions cannot influence the result.
|
||||
func Score(answers map[string]int, requireComplete bool) (Result, error) {
|
||||
index := questionIndex()
|
||||
raw := make(map[Dimension]int, len(Dimensions))
|
||||
counts := make(map[Dimension]int, len(Dimensions))
|
||||
|
||||
for id, value := range answers {
|
||||
question, ok := index[id]
|
||||
if !ok {
|
||||
return Result{}, fmt.Errorf("unknown question %q", id)
|
||||
}
|
||||
if value < MinAnswer || value > MaxAnswer {
|
||||
return Result{}, fmt.Errorf("answer for %s must be between %d and %d", id, MinAnswer, MaxAnswer)
|
||||
}
|
||||
raw[question.Dimension] += value
|
||||
counts[question.Dimension]++
|
||||
}
|
||||
|
||||
if requireComplete && len(answers) != len(Questions) {
|
||||
return Result{}, fmt.Errorf("%w: answered %d of %d questions", ErrIncomplete, len(answers), len(Questions))
|
||||
}
|
||||
|
||||
scores := make([]DimensionScore, 0, len(Dimensions))
|
||||
for _, dimension := range Dimensions {
|
||||
answered := counts[dimension]
|
||||
percent := 0
|
||||
if answered > 0 {
|
||||
minimum := answered * MinAnswer
|
||||
span := answered * (MaxAnswer - MinAnswer)
|
||||
percent = int(math.Round(float64(raw[dimension]-minimum) * 100 / float64(span)))
|
||||
}
|
||||
scores = append(scores, DimensionScore{
|
||||
Dimension: dimension,
|
||||
Raw: raw[dimension],
|
||||
Answered: answered,
|
||||
Percent: percent,
|
||||
})
|
||||
}
|
||||
|
||||
sort.SliceStable(scores, func(i, j int) bool {
|
||||
if scores[i].Percent == scores[j].Percent {
|
||||
return dimensionOrder(scores[i].Dimension) < dimensionOrder(scores[j].Dimension)
|
||||
}
|
||||
return scores[i].Percent > scores[j].Percent
|
||||
})
|
||||
|
||||
codeLength := 3
|
||||
if len(scores) < codeLength {
|
||||
codeLength = len(scores)
|
||||
}
|
||||
code := ""
|
||||
for _, score := range scores[:codeLength] {
|
||||
code += string(score.Dimension)
|
||||
}
|
||||
|
||||
completeness := int(math.Round(float64(len(answers)) * 100 / float64(len(Questions))))
|
||||
confidence := "low"
|
||||
if completeness == 100 {
|
||||
confidence = "moderate"
|
||||
if len(scores) > 3 && scores[2].Percent-scores[3].Percent >= 15 {
|
||||
confidence = "higher"
|
||||
}
|
||||
}
|
||||
|
||||
return Result{
|
||||
Version: BankVersion,
|
||||
Scores: scores,
|
||||
Code: code,
|
||||
Answered: len(answers),
|
||||
TotalQuestions: len(Questions),
|
||||
Completeness: completeness,
|
||||
Confidence: confidence,
|
||||
ResearchUseOnly: true,
|
||||
InstrumentNotice: "Exploratory RIASEC-aligned inventory; not the official validated O*NET Interest Profiler.",
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NextQuestion makes the questionnaire feel responsive while preserving its
|
||||
// fixed scoring contract. It first balances coverage across dimensions, then
|
||||
// uses question order for reproducibility.
|
||||
func NextQuestion(answers map[string]int) (Question, bool) {
|
||||
answeredByDimension := make(map[Dimension]int, len(Dimensions))
|
||||
index := questionIndex()
|
||||
for id := range answers {
|
||||
if question, ok := index[id]; ok {
|
||||
answeredByDimension[question.Dimension]++
|
||||
}
|
||||
}
|
||||
|
||||
minimum := len(Questions) + 1
|
||||
for _, dimension := range Dimensions {
|
||||
if answeredByDimension[dimension] < minimum {
|
||||
minimum = answeredByDimension[dimension]
|
||||
}
|
||||
}
|
||||
for _, question := range Questions {
|
||||
if _, answered := answers[question.ID]; !answered && answeredByDimension[question.Dimension] == minimum {
|
||||
return question, true
|
||||
}
|
||||
}
|
||||
return Question{}, false
|
||||
}
|
||||
|
||||
func dimensionOrder(dimension Dimension) int {
|
||||
for index, candidate := range Dimensions {
|
||||
if candidate == dimension {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return len(Dimensions)
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package assessment
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScoreProducesStableRIASECCode(t *testing.T) {
|
||||
answers := make(map[string]int, len(Questions))
|
||||
preference := map[Dimension]int{
|
||||
Realistic: 2, Investigative: 5, Artistic: 4,
|
||||
Social: 3, Enterprising: 1, Conventional: 2,
|
||||
}
|
||||
for _, question := range Questions {
|
||||
answers[question.ID] = preference[question.Dimension]
|
||||
}
|
||||
|
||||
result, err := Score(answers, true)
|
||||
if err != nil {
|
||||
t.Fatalf("Score returned an error: %v", err)
|
||||
}
|
||||
if result.Code != "IAS" {
|
||||
t.Fatalf("code = %q, want IAS", result.Code)
|
||||
}
|
||||
if result.Completeness != 100 || result.Confidence != "higher" {
|
||||
t.Fatalf("unexpected completeness/confidence: %d/%s", result.Completeness, result.Confidence)
|
||||
}
|
||||
if !result.ResearchUseOnly {
|
||||
t.Fatal("exploratory assessment must retain its research-use notice")
|
||||
}
|
||||
}
|
||||
|
||||
func TestScoreRejectsIncompleteAndInvalidAnswers(t *testing.T) {
|
||||
if _, err := Score(map[string]int{"r01": 5}, true); !errors.Is(err, ErrIncomplete) {
|
||||
t.Fatalf("incomplete assessment error = %v, want ErrIncomplete", err)
|
||||
}
|
||||
if _, err := Score(map[string]int{"r01": 6}, false); err == nil {
|
||||
t.Fatal("out-of-range answer was accepted")
|
||||
}
|
||||
if _, err := Score(map[string]int{"not-a-question": 3}, false); err == nil {
|
||||
t.Fatal("unknown question was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextQuestionBalancesDimensions(t *testing.T) {
|
||||
answers := map[string]int{"r01": 4}
|
||||
next, ok := NextQuestion(answers)
|
||||
if !ok {
|
||||
t.Fatal("NextQuestion unexpectedly reported completion")
|
||||
}
|
||||
if next.Dimension != Investigative {
|
||||
t.Fatalf("next dimension = %q, want %q", next.Dimension, Investigative)
|
||||
}
|
||||
|
||||
for _, question := range Questions {
|
||||
answers[question.ID] = 3
|
||||
}
|
||||
if _, ok := NextQuestion(answers); ok {
|
||||
t.Fatal("NextQuestion returned an item after completion")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue