diff --git a/dashboard.go b/dashboard.go index 3b6364f..fbfff5f 100644 --- a/dashboard.go +++ b/dashboard.go @@ -13,6 +13,8 @@ import ( // DashboardData holds aggregated statistics for the dashboard type DashboardData struct { TotalInstalls int `json:"total_installs"` + TotalAllTime int `json:"total_all_time"` // Total records in DB (not limited) + SampleSize int `json:"sample_size"` // How many records were sampled SuccessCount int `json:"success_count"` FailedCount int `json:"failed_count"` InstallingCount int `json:"installing_count"` @@ -132,10 +134,15 @@ func (p *PBClient) FetchDashboardData(ctx context.Context, days int, repoSource } // Fetch all records for the period - records, err := p.fetchRecords(ctx, filter) + result, err := p.fetchRecords(ctx, filter) if err != nil { return nil, err } + records := result.Records + + // Set total counts + data.TotalAllTime = result.TotalItems // Actual total in database + data.SampleSize = len(records) // How many we actually processed // Aggregate statistics appCounts := make(map[string]int) @@ -257,18 +264,18 @@ func (p *PBClient) FetchDashboardData(ctx context.Context, days int, repoSource data.SuccessRate = float64(data.SuccessCount) / float64(completed) * 100 } - // Convert maps to sorted slices (top 10) - data.TopApps = topN(appCounts, 10) - data.OsDistribution = topNOs(osCounts, 10) + // Convert maps to sorted slices (increased limits for better analytics) + data.TopApps = topN(appCounts, 20) + data.OsDistribution = topNOs(osCounts, 15) data.MethodStats = topNMethod(methodCounts, 10) - data.PveVersions = topNPve(pveCounts, 10) + data.PveVersions = topNPve(pveCounts, 15) data.TypeStats = topNType(typeCounts, 10) // Error analysis - data.ErrorAnalysis = buildErrorAnalysis(errorPatterns, 10) + data.ErrorAnalysis = buildErrorAnalysis(errorPatterns, 15) - // Failed apps with failure rates - data.FailedApps = buildFailedApps(appCounts, appFailures, 10) + // Failed apps with failure rates (min 10 installs threshold) + data.FailedApps = buildFailedApps(appCounts, appFailures, 15) // Daily stats for chart data.DailyStats = buildDailyStats(dailySuccess, dailyFailed, days) @@ -282,10 +289,10 @@ func (p *PBClient) FetchDashboardData(ctx context.Context, days int, repoSource data.ErrorCategories = buildErrorCategories(errorCatCounts) // Top tools - data.TopTools = buildToolStats(toolCounts, 10) + data.TopTools = buildToolStats(toolCounts, 15) // Top addons - data.TopAddons = buildAddonStats(addonCounts, 10) + data.TopAddons = buildAddonStats(addonCounts, 15) // Average install duration if durationCount > 0 { @@ -308,23 +315,30 @@ type TelemetryRecord struct { Created string `json:"created"` } -func (p *PBClient) fetchRecords(ctx context.Context, filter string) ([]TelemetryRecord, error) { +// fetchRecordsResult contains records and total count +type fetchRecordsResult struct { + Records []TelemetryRecord + TotalItems int // Actual total in database (not limited) +} + +func (p *PBClient) fetchRecords(ctx context.Context, filter string) (*fetchRecordsResult, error) { var allRecords []TelemetryRecord page := 1 perPage := 500 maxRecords := 100000 // Limit to prevent timeout with large datasets + totalItems := 0 for { - var url string + var reqURL string if filter != "" { - url = fmt.Sprintf("%s/api/collections/%s/records?filter=%s&sort=-created&page=%d&perPage=%d", + reqURL = fmt.Sprintf("%s/api/collections/%s/records?filter=%s&sort=-created&page=%d&perPage=%d", p.baseURL, p.targetColl, filter, page, perPage) } else { - url = fmt.Sprintf("%s/api/collections/%s/records?sort=-created&page=%d&perPage=%d", + reqURL = fmt.Sprintf("%s/api/collections/%s/records?sort=-created&page=%d&perPage=%d", p.baseURL, p.targetColl, page, perPage) } - req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil) if err != nil { return nil, err } @@ -345,6 +359,11 @@ func (p *PBClient) fetchRecords(ctx context.Context, filter string) ([]Telemetry } resp.Body.Close() + // Store total on first page + if page == 1 { + totalItems = result.TotalItems + } + allRecords = append(allRecords, result.Items...) // Stop if we have enough records or reached the end @@ -354,7 +373,10 @@ func (p *PBClient) fetchRecords(ctx context.Context, filter string) ([]Telemetry page++ } - return allRecords, nil + return &fetchRecordsResult{ + Records: allRecords, + TotalItems: totalItems, + }, nil } func topN(m map[string]int, n int) []AppCount { @@ -533,11 +555,12 @@ func buildErrorAnalysis(patterns map[string]map[string]bool, n int) []ErrorGroup func buildFailedApps(total, failed map[string]int, n int) []AppFailure { result := make([]AppFailure, 0) + minInstalls := 10 // Minimum installations to be considered (avoid noise from rare apps) for app, failCount := range failed { totalCount := total[app] - if totalCount == 0 { - continue + if totalCount < minInstalls { + continue // Skip apps with too few installations } rate := float64(failCount) / float64(totalCount) * 100 @@ -1808,13 +1831,15 @@ func DashboardHTML() string {