Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/wages/service.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/modules/wages/service.go |
| Original SHA-256 | c5b32d5d1b1bf2594393a99e0265ef20ef36a694d4e8a2af0c25cfda7fd83b5a |
| Git blob SHA | e75b2959bf33b5c78ff6e8ee2eb739d9ac2d7753 |
| Reading-copy SHA-256 | c5b32d5d1b1bf2594393a99e0265ef20ef36a694d4e8a2af0c25cfda7fd83b5a |
Every recorded occurrence
These 2 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/modules/wages/service.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/modules/wages/service.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
Recovered source transcript
Download complete source text ↓87 lines · 2.3 KB
package wages
import (
"context"
"errors"
"time"
"github.com/missionworkforce/missionmatch/internal/platform/database/dbgen"
"github.com/missionworkforce/missionmatch/internal/platform/tenant"
)
// ErrNoDatabase is returned when no pool is configured.
var ErrNoDatabase = errors.New("wages: no database configured")
// Service reads the cached BLS wage baseline.
type Service struct{ db *tenant.DB }
// NewService builds the service. db may be nil (then calls return ErrNoDatabase).
func NewService(db *tenant.DB) *Service { return &Service{db: db} }
// Baseline returns the wage baseline grouped by occupation, each with its Hawaii and New Mexico
// annual mean and median wages.
func (s *Service) Baseline(ctx context.Context) ([]WageBaseline, error) {
if !s.db.Ready() {
return nil, ErrNoDatabase
}
pool, release, perr := s.acquirePool(ctx)
if perr != nil {
return nil, perr
}
defer release()
rows, err := dbgen.New(pool).ListBlsWages(ctx)
if err != nil {
return nil, err
}
order := []string{} // preserve first seen occupation order
byOcc := map[string]*WageBaseline{} // occupation_code to baseline
areaIdx := map[string]map[string]int{} // occupation_code to area to index in Areas
syncedAt := time.Time{}
for _, r := range rows {
wb, ok := byOcc[r.OccupationCode]
if !ok {
wb = &WageBaseline{
OccupationCode: r.OccupationCode,
OccupationTitle: r.OccupationTitle,
Role: r.Role,
Year: r.PeriodYear,
Source: "BLS OEWS",
}
byOcc[r.OccupationCode] = wb
areaIdx[r.OccupationCode] = map[string]int{}
order = append(order, r.OccupationCode)
}
ai, ok := areaIdx[r.OccupationCode][r.Area]
if !ok {
wb.Areas = append(wb.Areas, AreaWage{Area: r.Area, AreaName: r.AreaName})
ai = len(wb.Areas) - 1
areaIdx[r.OccupationCode][r.Area] = ai
}
val := ""
if r.Value != nil {
val = r.Value.StringFixed(0)
}
switch r.Metric {
case "annual_mean":
wb.Areas[ai].AnnualMean = val
case "annual_median":
wb.Areas[ai].AnnualMedian = val
}
if r.SyncedAt.After(syncedAt) {
syncedAt = r.SyncedAt
}
}
out := make([]WageBaseline, 0, len(order))
for _, code := range order {
wb := byOcc[code]
if !syncedAt.IsZero() {
wb.SyncedAt = syncedAt.Format(time.RFC3339)
}
out = append(out, *wb)
}
return out, nil
}