Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions pkg/cli/forecast_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"math"
"os"
"strings"

"github.com/github/gh-aw/pkg/console"
"github.com/github/gh-aw/pkg/constants"
Expand Down Expand Up @@ -37,6 +36,7 @@ func renderForecastTable(output ForecastResult, config ForecastConfig) error {

anyUnreliable := false
var totalWeeklyP50, totalMonthlyP50 float64
var totalRuns int
rows := make([]forecastTableRow, 0, len(output.Workflows)+1)
for _, wf := range output.Workflows {
unreliableMark := ""
Expand All @@ -53,19 +53,23 @@ func renderForecastTable(output ForecastResult, config ForecastConfig) error {
if mc := wf.MonthlyMonteCarlo; mc != nil {
monthlyP50 = mc.P50ProjectedAIC
}
totalWeeklyP50 += weeklyP50
totalMonthlyP50 += monthlyP50
// Skip NaN/Inf so a single unreliable projection can't poison the totals.
if !math.IsNaN(weeklyP50) && !math.IsInf(weeklyP50, 0) {
totalWeeklyP50 += weeklyP50
}
if !math.IsNaN(monthlyP50) && !math.IsInf(monthlyP50, 0) {
totalMonthlyP50 += monthlyP50
}
Comment on lines +56 to +62
totalRuns += wf.SampledRuns

row := forecastTableRow{
Workflow: wf.WorkflowID + unreliableMark,
Engines: formatEngineList(wf.Engines),
Runs: wf.SampledRuns,
P50PerRun: formatForecastAIC(wf.P50AIC),
P95PerRun: formatForecastAIC(wf.P95AIC),
WeeklyP50: formatForecastAIC(weeklyP50),
MonthlyP50: formatForecastAIC(monthlyP50),
Comment on lines 70 to 71
SuccessRate: formatForecastPercent(wf.SuccessRate, wf.SampledRuns > 0),
Triggers: formatTriggerList(wf.ActiveTriggers),
}
rows = append(rows, row)
}
Expand All @@ -76,6 +80,7 @@ func renderForecastTable(output ForecastResult, config ForecastConfig) error {
if len(output.Workflows) > 1 {
rows = append(rows, forecastTableRow{
Workflow: "TOTAL",
Runs: totalRuns,
WeeklyP50: formatForecastAIC(totalWeeklyP50),
MonthlyP50: formatForecastAIC(totalMonthlyP50),
})
Expand All @@ -84,8 +89,10 @@ func renderForecastTable(output ForecastResult, config ForecastConfig) error {
fmt.Fprint(os.Stderr, console.RenderStruct(rows))
fmt.Fprintln(os.Stderr, "")

// Show detailed per-run samples section.
printRunSamplesSection(output.Workflows)
// Show detailed per-run samples section only when specific workflows were requested.
if len(config.WorkflowIDs) > 0 {
printRunSamplesSection(output.Workflows)
}

// Show experiment variant details when present.
for _, wf := range output.Workflows {
Expand Down Expand Up @@ -245,13 +252,6 @@ func formatForecastAIC(value float64) string {
return fmt.Sprintf("%.2fM", value/1_000_000)
}

func formatEngineList(engines []string) string {
if len(engines) == 0 {
return "-"
}
return strings.Join(engines, ", ")
}

// formatForecastSignedAIC formats a signed AIC value, preserving
// the sign so callers can display positive/negative deltas (e.g., error abs).
func formatForecastSignedAIC(value float64) string {
Expand All @@ -270,13 +270,3 @@ func formatForecastSignedAIC(value float64) string {
func roundForecastAIC(value float64) float64 {
return math.Round(value*1000) / 1000
}

func formatTriggerList(triggers []string) string {
if len(triggers) == 0 {
return "-"
}
if len(triggers) <= 3 {
return strings.Join(triggers, ", ")
}
return strings.Join(triggers[:3], ", ") + fmt.Sprintf(" +%d", len(triggers)-3)
}
2 changes: 0 additions & 2 deletions pkg/cli/forecast_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,10 @@ type workflowMeta struct {
// forecastTableRow is a flattened struct used for console table rendering.
type forecastTableRow struct {
Workflow string `json:"workflow" console:"header:Workflow"`
Engines string `json:"engines" console:"header:Engines"`
Runs int `json:"runs" console:"header:Runs"`
P50PerRun string `json:"p50_per_run" console:"header:P50 AIC/Run"`
P95PerRun string `json:"p95_per_run" console:"header:P95 AIC/Run"`
WeeklyP50 string `json:"weekly_p50" console:"header:Weekly AIC (P50)"`
MonthlyP50 string `json:"monthly_p50" console:"header:Monthly AIC (P50)"`
SuccessRate string `json:"success_rate" console:"header:Success Rate"`
Triggers string `json:"triggers" console:"header:Triggers"`
}
Loading