fix: 修复采纳统计计算

This commit is contained in:
yokowu
2025-07-24 18:50:28 +08:00
parent f390db4cfb
commit 53bb2005ec

View File

@@ -110,7 +110,7 @@ func (d *DashboardRepo) TimeStat(ctx context.Context, req domain.StatisticsFilte
sql.As(fmt.Sprintf("date_trunc('%s', created_at)", req.Precision), "date"),
sql.As("COUNT(DISTINCT user_id)", "user_count"),
sql.As("COUNT(*) FILTER (WHERE model_type = 'llm')", "llm_count"),
sql.As("COUNT(*) FILTER (WHERE model_type = 'coder')", "code_count"),
sql.As("COUNT(*) FILTER (WHERE is_suggested = true AND model_type = 'coder')", "code_count"),
sql.As("COUNT(*) FILTER (WHERE is_accept = true AND model_type = 'coder')", "accepted_count"),
sql.As(sql.Sum(task.FieldCodeLines), "code_lines"),
).GroupBy("date").
@@ -154,7 +154,10 @@ func (d *DashboardRepo) TimeStat(ctx context.Context, req domain.StatisticsFilte
})
}
totalAccepted, totalSuggested := int64(0), int64(0)
for _, v := range ds {
totalAccepted += v.AcceptedCount
totalSuggested += v.CodeCount
ts.TotalChats += v.LlmCount
ts.TotalCompletions += v.CodeCount
ts.TotalLinesOfCode += v.CodeLines
@@ -182,6 +185,10 @@ func (d *DashboardRepo) TimeStat(ctx context.Context, req domain.StatisticsFilte
}
}
if totalSuggested > 0 {
ts.TotalAcceptedPer = float64(totalAccepted) / float64(totalSuggested) * 100
}
return ts, nil
}
@@ -280,7 +287,7 @@ func (d *DashboardRepo) UserStat(ctx context.Context, req domain.StatisticsFilte
sql.As(fmt.Sprintf("date_trunc('%s', created_at)", req.Precision), "date"),
sql.As("COUNT(DISTINCT user_id)", "user_count"),
sql.As("COUNT(*) FILTER (WHERE model_type = 'llm')", "llm_count"),
sql.As("COUNT(*) FILTER (WHERE model_type = 'coder')", "code_count"),
sql.As("COUNT(*) FILTER (WHERE is_suggested = true AND model_type = 'coder')", "code_count"),
sql.As("COUNT(*) FILTER (WHERE is_accept = true AND model_type = 'coder')", "accepted_count"),
sql.As(sql.Sum(task.FieldCodeLines), "code_lines"),
).GroupBy("date").