39 lines
902 B
Go
39 lines
902 B
Go
package analytics
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"cloudipvalidator/internal/db"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Load reads a finished run from the database and computes its analysis.
|
||
|
|
func Load(ctx context.Context, d *db.DB, runID int64) (*Analysis, error) {
|
||
|
|
run, err := d.GetRun(ctx, runID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
results, err := d.ListRunResults(ctx, runID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
subnets, err := d.ListSubnets(ctx)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
sites, err := d.ListSites(ctx)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
names := map[int]string{}
|
||
|
|
for _, s := range sites {
|
||
|
|
names[s.Index] = s.SiteID
|
||
|
|
}
|
||
|
|
rechecked, err := d.CountRecheckedInRun(ctx, runID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return Compute(Input{
|
||
|
|
Run: *run, Results: results, Subnets: subnets, SiteNames: names, Rechecked: rechecked,
|
||
|
|
Each: func(fn func(db.RunCheck)) error { return d.EachRunCheck(ctx, runID, fn) },
|
||
|
|
})
|
||
|
|
}
|