// Reproject explicitly listed, backed-up mileage days using the live writer SQL. package main import ( "context" "database/sql" "encoding/json" "flag" "fmt" _ "github.com/go-sql-driver/mysql" "lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope" "lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats" "os" "time" ) func main() { input := flag.String("input", "", "JSON array of vin/date/protocol") flag.Parse() b, e := os.ReadFile(*input) must(e) var rows []struct { VIN string `json:"vin"` Date string `json:"date"` Protocol string `json:"protocol"` } must(json.Unmarshal(b, &rows)) db, e := sql.Open("mysql", os.Getenv("MYSQL_DSN")) must(e) defer db.Close() ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute) defer cancel() for i, r := range rows { must(stats.ProjectDailyMileage(ctx, db, r.VIN, r.Date, envelope.Protocol(r.Protocol))) if (i+1)%500 == 0 { fmt.Printf("projected=%d/%d\n", i+1, len(rows)) } } fmt.Printf("completed=%d\n", len(rows)) } func must(e error) { if e != nil { fmt.Fprintln(os.Stderr, e) os.Exit(1) } }