chore(stock): 调试接口增加交易所分组与涨跌分布

This commit is contained in:
2026-07-04 11:29:56 +08:00
parent 346d3c5555
commit 42b2270839
+64
View File
@@ -155,6 +155,27 @@ func (h *StockHandler) TriggerSync(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": true, "records_count": count}) c.JSON(http.StatusOK, gin.H{"success": true, "records_count": count})
} }
type distributionRow struct {
Label string `json:"label"`
Count int64 `json:"count"`
}
type distributionScan struct {
SH int64
SZ int64
BJ int64
Up0_3 int64
Up3_5 int64
Up5_7 int64
Up7_10 int64
Up10 int64
Down0_3 int64
Down3_5 int64
Down5_7 int64
Down7_10 int64
Down10 int64
}
type debugStatsResponse struct { type debugStatsResponse struct {
TradeDate string `json:"trade_date"` TradeDate string `json:"trade_date"`
Total int64 `json:"total"` Total int64 `json:"total"`
@@ -166,6 +187,9 @@ type debugStatsResponse struct {
UpByPct int64 `json:"up_by_pct"` UpByPct int64 `json:"up_by_pct"`
DownByPct int64 `json:"down_by_pct"` DownByPct int64 `json:"down_by_pct"`
FlatByPct int64 `json:"flat_by_pct"` FlatByPct int64 `json:"flat_by_pct"`
ExchangeCounts map[string]int64 `json:"exchange_counts"`
UpDistribution []distributionRow `json:"up_distribution"`
DownDistribution []distributionRow `json:"down_distribution"`
FlatSamples []stockRow `json:"flat_samples"` FlatSamples []stockRow `json:"flat_samples"`
BoundarySamples []stockRow `json:"boundary_samples"` BoundarySamples []stockRow `json:"boundary_samples"`
UpBoundarySamples []stockRow `json:"up_boundary_samples"` UpBoundarySamples []stockRow `json:"up_boundary_samples"`
@@ -214,6 +238,46 @@ func (h *StockHandler) DebugStats(c *gin.Context) {
stats.TradeDate = latestDate.Format("2006-01-02") stats.TradeDate = latestDate.Format("2006-01-02")
var dist distributionScan
h.DB.WithContext(ctx).Model(&models.StockDailyQuote{}).
Select(`
SUM(CASE WHEN symbol LIKE '%.SH' THEN 1 ELSE 0 END) AS sh,
SUM(CASE WHEN symbol LIKE '%.SZ' THEN 1 ELSE 0 END) AS sz,
SUM(CASE WHEN symbol LIKE '%.BJ' THEN 1 ELSE 0 END) AS bj,
SUM(CASE WHEN change_pct > 0 AND change_pct <= 0.03 THEN 1 ELSE 0 END) AS up_0_3,
SUM(CASE WHEN change_pct > 0.03 AND change_pct <= 0.05 THEN 1 ELSE 0 END) AS up_3_5,
SUM(CASE WHEN change_pct > 0.05 AND change_pct <= 0.07 THEN 1 ELSE 0 END) AS up_5_7,
SUM(CASE WHEN change_pct > 0.07 AND change_pct <= 0.10 THEN 1 ELSE 0 END) AS up_7_10,
SUM(CASE WHEN change_pct > 0.10 THEN 1 ELSE 0 END) AS up_10,
SUM(CASE WHEN change_pct < 0 AND change_pct >= -0.03 THEN 1 ELSE 0 END) AS down_0_3,
SUM(CASE WHEN change_pct < -0.03 AND change_pct >= -0.05 THEN 1 ELSE 0 END) AS down_3_5,
SUM(CASE WHEN change_pct < -0.05 AND change_pct >= -0.07 THEN 1 ELSE 0 END) AS down_5_7,
SUM(CASE WHEN change_pct < -0.07 AND change_pct >= -0.10 THEN 1 ELSE 0 END) AS down_7_10,
SUM(CASE WHEN change_pct < -0.10 THEN 1 ELSE 0 END) AS down_10
`).
Where(baseWhere, latestDate, idxList).
Scan(&dist)
stats.ExchangeCounts = map[string]int64{
"sh": dist.SH,
"sz": dist.SZ,
"bj": dist.BJ,
}
stats.UpDistribution = []distributionRow{
{Label: "0~3%", Count: dist.Up0_3},
{Label: "3~5%", Count: dist.Up3_5},
{Label: "5~7%", Count: dist.Up5_7},
{Label: "7~10%", Count: dist.Up7_10},
{Label: ">10%", Count: dist.Up10},
}
stats.DownDistribution = []distributionRow{
{Label: "3~0%", Count: dist.Down0_3},
{Label: "5~3%", Count: dist.Down3_5},
{Label: "7~5%", Count: dist.Down5_7},
{Label: "10~7%", Count: dist.Down7_10},
{Label: ">10%", Count: dist.Down10},
}
var flatSamples []stockRow var flatSamples []stockRow
h.DB.WithContext(ctx).Model(&models.StockDailyQuote{}). h.DB.WithContext(ctx).Model(&models.StockDailyQuote{}).
Select("symbol, name, close, prev_close, change_pct"). Select("symbol, name, close, prev_close, change_pct").