64 lines
2.3 KiB
Go
64 lines
2.3 KiB
Go
package opportunity
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
type Snapshot struct {
|
|
Version string `json:"version"`
|
|
GeneratedAt string `json:"generated_at"`
|
|
Occupations map[string]Evidence `json:"occupations"`
|
|
EducationOptions map[string][]EducationOption `json:"education_options"`
|
|
ZIPCoordinates map[string]Coordinates `json:"zip_coordinates"`
|
|
}
|
|
|
|
type Coordinates struct {
|
|
Latitude float64 `json:"latitude"`
|
|
Longitude float64 `json:"longitude"`
|
|
}
|
|
|
|
type EducationOption struct {
|
|
UnitID string `json:"unit_id"`
|
|
Institution string `json:"institution"`
|
|
City string `json:"city"`
|
|
ZIPCode string `json:"zip_code"`
|
|
Latitude float64 `json:"latitude"`
|
|
Longitude float64 `json:"longitude"`
|
|
Website string `json:"website"`
|
|
CIP6 string `json:"cip6"`
|
|
AwardLevels []string `json:"award_levels"`
|
|
ProgramCompletions int `json:"program_completions"`
|
|
AnnualInStateTuition int `json:"annual_in_state_tuition"`
|
|
AdmissionRatePercent float64 `json:"admission_rate_percent"`
|
|
AdmissionBasis string `json:"admission_basis"`
|
|
InstitutionCompletionRatePercent int `json:"institution_completion_rate_percent"`
|
|
ProgramYear string `json:"program_year"`
|
|
CostAdmissionYear string `json:"cost_admission_year"`
|
|
}
|
|
|
|
// Load reads the latest complete snapshot. A missing cache is an expected
|
|
// state: NextPath can still provide interest matches without inventing labor
|
|
// evidence.
|
|
func Load(path string) (Snapshot, error) {
|
|
if path == "" {
|
|
return Snapshot{}, nil
|
|
}
|
|
data, err := os.ReadFile(path)
|
|
if os.IsNotExist(err) {
|
|
return Snapshot{}, nil
|
|
}
|
|
if err != nil {
|
|
return Snapshot{}, fmt.Errorf("read opportunity cache: %w", err)
|
|
}
|
|
var snapshot Snapshot
|
|
if err := json.Unmarshal(data, &snapshot); err != nil {
|
|
return Snapshot{}, fmt.Errorf("decode opportunity cache: %w", err)
|
|
}
|
|
if snapshot.Version == "" || len(snapshot.Occupations) == 0 {
|
|
return Snapshot{}, fmt.Errorf("opportunity cache is empty")
|
|
}
|
|
return snapshot, nil
|
|
}
|