MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / GetTokenStatistics

Function GetTokenStatistics

controller/statistics_charts.go:49–81  ·  view source on GitHub ↗

GetTokenStatistics 获取按令牌统计的数据

(c *gin.Context)

Source from the content-addressed store, hash-verified

47
48// GetTokenStatistics 获取按令牌统计的数据
49func GetTokenStatistics(c *gin.Context) {
50 startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
51 endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
52 username := c.Query("username")
53 tokenName := c.Query("token_name")
54 modelName := c.Query("model_name")
55 channel, _ := strconv.Atoi(c.Query("channel"))
56 group := c.Query("group")
57 defaultTime := c.Query("default_time")
58
59 // 设置默认时间范围为最近7天
60 if startTimestamp == 0 && endTimestamp == 0 {
61 endTimestamp = time.Now().Unix()
62 startTimestamp = endTimestamp - 7*24*3600
63 }
64
65 // 设置默认时间粒度
66 if defaultTime == "" {
67 defaultTime = "day"
68 }
69
70 statistics, err := model.GetTokenStatistics(int(startTimestamp), int(endTimestamp), username, tokenName, modelName, channel, group, defaultTime)
71 if err != nil {
72 common.ApiError(c, err)
73 return
74 }
75
76 c.JSON(http.StatusOK, gin.H{
77 "success": true,
78 "message": "",
79 "data": statistics,
80 })
81}
82
83// GetUserStatistics 获取按用户统计的数据
84func GetUserStatistics(c *gin.Context) {

Callers

nothing calls this directly

Calls 2

GetTokenStatisticsFunction · 0.92
ApiErrorFunction · 0.92

Tested by

no test coverage detected