157 lines
4.6 KiB
Go
157 lines
4.6 KiB
Go
package model
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// 实验状态
|
|
const (
|
|
ExpStatusDraft = 0 // 草稿
|
|
ExpStatusRunning = 1 // 运行中
|
|
ExpStatusPaused = 2 // 已暂停
|
|
ExpStatusStopped = 3 // 已结束
|
|
)
|
|
|
|
// Experiment AB测试实验
|
|
type Experiment struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Status int `json:"status"`
|
|
StartTime *time.Time `json:"start_time"`
|
|
EndTime *time.Time `json:"end_time"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// Variant 实验变体
|
|
type Variant struct {
|
|
ID int64 `json:"id"`
|
|
ExperimentID int64 `json:"experiment_id"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Weight int `json:"weight"`
|
|
Params json.RawMessage `json:"params"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// UserAssignment 用户分组分配
|
|
type UserAssignment struct {
|
|
ID int64 `json:"id"`
|
|
ExperimentID int64 `json:"experiment_id"`
|
|
UserID string `json:"user_id"`
|
|
VariantID int64 `json:"variant_id"`
|
|
AssignedAt time.Time `json:"assigned_at"`
|
|
}
|
|
|
|
// Event 事件追踪
|
|
type Event struct {
|
|
ID int64 `json:"id"`
|
|
ExperimentID int64 `json:"experiment_id"`
|
|
VariantID int64 `json:"variant_id"`
|
|
UserID string `json:"user_id"`
|
|
EventType string `json:"event_type"`
|
|
EventValue float64 `json:"event_value"`
|
|
Metadata json.RawMessage `json:"metadata"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// ---- 请求 / 响应结构 ----
|
|
|
|
type CreateExperimentReq struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Description string `json:"description"`
|
|
}
|
|
|
|
type UpdateExperimentReq struct {
|
|
Name *string `json:"name"`
|
|
Description *string `json:"description"`
|
|
Status *int `json:"status"`
|
|
StartTime *time.Time `json:"start_time"`
|
|
EndTime *time.Time `json:"end_time"`
|
|
}
|
|
|
|
type CreateVariantReq struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Description string `json:"description"`
|
|
Weight int `json:"weight"`
|
|
Params json.RawMessage `json:"params"`
|
|
}
|
|
|
|
type UpdateVariantReq struct {
|
|
Name *string `json:"name"`
|
|
Description *string `json:"description"`
|
|
Weight *int `json:"weight"`
|
|
Params *json.RawMessage `json:"params"`
|
|
}
|
|
|
|
type AssignUserReq struct {
|
|
UserID string `json:"user_id" binding:"required"`
|
|
}
|
|
|
|
type TrackEventReq struct {
|
|
UserID string `json:"user_id" binding:"required"`
|
|
EventType string `json:"event_type" binding:"required"`
|
|
EventValue float64 `json:"event_value"`
|
|
Metadata json.RawMessage `json:"metadata"`
|
|
}
|
|
|
|
// VariantStats 变体统计
|
|
type VariantStats struct {
|
|
VariantID int64 `json:"variant_id"`
|
|
VariantName string `json:"variant_name"`
|
|
ExposureCount int64 `json:"exposure_count"`
|
|
ConvertCount int64 `json:"convert_count"`
|
|
ConvertRate float64 `json:"convert_rate"`
|
|
TotalValue float64 `json:"total_value"`
|
|
UserCount int64 `json:"user_count"`
|
|
}
|
|
|
|
// ExperimentResult 实验结果
|
|
type ExperimentResult struct {
|
|
ExperimentID int64 `json:"experiment_id"`
|
|
ExperimentName string `json:"experiment_name"`
|
|
Status int `json:"status"`
|
|
Variants []VariantStats `json:"variants"`
|
|
}
|
|
|
|
// UserExperimentGroup 玩家在某个实验中的分组信息
|
|
type UserExperimentGroup struct {
|
|
ExperimentID int64 `json:"experiment_id"`
|
|
ExperimentName string `json:"experiment_name"`
|
|
VariantID int64 `json:"variant_id"`
|
|
VariantName string `json:"variant_name"`
|
|
Params json.RawMessage `json:"params"`
|
|
}
|
|
|
|
// NullTime 辅助扫描 nullable time
|
|
type NullTime = sql.NullTime
|
|
|
|
// Whitelist 白名单
|
|
type Whitelist struct {
|
|
ID int64 `json:"id"`
|
|
ExperimentID int64 `json:"experiment_id"`
|
|
UserID string `json:"user_id"`
|
|
VariantID int64 `json:"variant_id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type CreateWhitelistReq struct {
|
|
UserID string `json:"user_id" binding:"required"`
|
|
VariantID int64 `json:"variant_id" binding:"required"`
|
|
}
|
|
|
|
type BatchCreateWhitelistReq struct {
|
|
Items []CreateWhitelistReq `json:"items" binding:"required,dive"`
|
|
}
|
|
|
|
// Response 统一响应
|
|
type Response struct {
|
|
Code int `json:"code"`
|
|
Msg string `json:"msg"`
|
|
Data interface{} `json:"data,omitempty"`
|
|
}
|