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 | 9bde0f9a74b89d01980fa658e5253acda7528d0c |
| Branch | per-tenant-routing |
| Path or archive member | internal/modules/wages/service.go |
| Original SHA-256 | 78d44e0af591a5e7f982e84fe72ff09e78fe8cc16044580acb267ccec89c8cf3 |
| Git blob SHA | 17c019d3d75bc6c6ae6d26255124efb62be37306 |
| Reading-copy SHA-256 | 78d44e0af591a5e7f982e84fe72ff09e78fe8cc16044580acb267ccec89c8cf3 |
Every recorded occurrence
These 3 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 | per-tenant-routing | 9bde0f9a74b89d01980fa658e5253acda7528d0c | Open original |
| Janady13/missionmatch / internal/modules/wages/service.go | deploy-and-ops | bdacd9d0b4d5998d25fc74bf4007f4c3ec538c7a | Open original |
| Janady13/missionmatch / internal/modules/wages/service.go | per-tenant-routing | 9bde0f9a74b89d01980fa658e5253acda7528d0c | Open original |
Recovered source transcript
Download complete source text ↓90 lines · 2.4 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 == nil {
return nil, ErrNoDatabase
}
leaf, release, err := s.db.Acquire(ctx)
if err != nil {
return nil, err
}
defer release()
if leaf.Pool == nil {
return nil, ErrNoDatabase
}
rows, err := dbgen.New(leaf.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
}