feat(platform): 模型可用性 - 目录附带近24小时成功率与7天趋势
公开目录只统计系统渠道的 create 成败,样本不足或日志不可用时不改变现有可用判断;模型选择器展示当前可用状态和历史成功率。
This commit is contained in:
1 parent
b4e5eb22a6
commit
05f90caf78
10 files changed
+483
-2
No files matched your search
@@ -29,6 +29,16 @@ type APICallLogFilter struct {
|
||||
Limit int
|
||||
}
|
||||
|
||||
// PublicModelAvailabilityFilter limits the public availability read model to
|
||||
// system catalog channel models. Keeping this query separate from admin
|
||||
// analytics avoids exposing the admin payload or accidentally including user
|
||||
// owned channels in a public response.
|
||||
type PublicModelAvailabilityFilter struct {
|
||||
From time.Time
|
||||
To time.Time
|
||||
ChannelIDs []string
|
||||
}
|
||||
|
||||
func (r *Repository) RecordUserActivity(userID string, event string, count int, now time.Time) error {
|
||||
if userID == "" {
|
||||
return nil
|
||||
@@ -98,6 +108,24 @@ func (r *Repository) AnalyticsAPICallLogs(filter AnalyticsFilter) ([]model.ApiCa
|
||||
return logs, query.Omit("RequestBody", "ResponseBody").Find(&logs).Error
|
||||
}
|
||||
|
||||
// PublicModelAvailabilityLogs returns the compact, user-facing create
|
||||
// outcomes used by the model catalog availability read model. Polling,
|
||||
// downloads, uploads and local bookkeeping are deliberately excluded here.
|
||||
func (r *Repository) PublicModelAvailabilityLogs(filter PublicModelAvailabilityFilter) ([]model.ApiCallLog, error) {
|
||||
var logs []model.ApiCallLog
|
||||
if len(filter.ChannelIDs) == 0 || !filter.To.After(filter.From) {
|
||||
return logs, nil
|
||||
}
|
||||
query := whereTimeRange(r.db.Select("channel_id", "model", "status", "created_at"), "api_call_logs.created_at", filter.From, filter.To).
|
||||
Where("api_call_logs.channel_id IN ?", filter.ChannelIDs).
|
||||
Where("api_call_logs.user_id <> ''").
|
||||
Where("api_call_logs.model <> ''").
|
||||
Where("api_call_logs.request_kind = ?", "create").
|
||||
Where("api_call_logs.status IN ?", []model.ApiCallStatus{model.ApiCallStatusSucceeded, model.ApiCallStatusFailed}).
|
||||
Order("api_call_logs.created_at asc")
|
||||
return logs, query.Find(&logs).Error
|
||||
}
|
||||
|
||||
func (r *Repository) AnalyticsActivities(filter AnalyticsFilter) ([]model.UserDailyActivity, error) {
|
||||
var activities []model.UserDailyActivity
|
||||
query := r.db.Where("day >= ? AND day < ?", filter.From, filter.To)
|
||||
|
||||
Reference in new issue
Block a user