package elasticilm import ( "fmt" "strings" // "math" "testing" "time" ) // TestEnsureILMPolicy 测试 ensureILMPolicy 函数并生成warm阶段时间矩阵(CSV格式) func TestEnsureILMPolicy(t *testing.T) { // 定义时间框架 timeFrames := []string{"1m", "3m", "5m", "15m", "30m", "1H", "2H", "4H", "6H", "12H", "1D", "2D", "5D", "1W"} // 定义日期范围 startDate := time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC) endDate := time.Date(2025, 3, 1, 0, 0, 0, 0, time.UTC) currentDate := time.Date(2025, 4, 1, 0, 0, 0, 0, time.UTC) // 初始化HTML输出 var htmlOutput strings.Builder htmlOutput.WriteString(` ILM Warm Phase Matrix

ILM Warm Phase Duration Matrix

`) // 写入表头 for _, period := range timeFrames { htmlOutput.WriteString(fmt.Sprintf(``, period)) } htmlOutput.WriteString(``) // 遍历每个月 for d := startDate; !d.After(endDate); d = d.AddDate(0, 1, 0) { month := d.Format("2006-01") daysDiff := int(currentDate.Sub(d).Hours() / 24) htmlOutput.WriteString(``) // 遍历每个时间框架 for _, period := range timeFrames { // 默认配置 config := map[string]float64{ "timeDecayFactor": 0.3, "periodGranularityFactor": 0.7, "warmPhaseMultiplier": 1.0, "coldPhaseMultiplier": 2.0, "deletePhaseMultiplier": 3.0, } // 计算warm阶段时间 warmDays, _, _ := NonLinearCoolingModel(daysDiff, period, config) // 计算颜色 (0-255范围) 基于0-1800的范围 colorValue := int(float64(warmDays) / 2500 * 255) if colorValue > 255 { colorValue = 255 } bgColor := fmt.Sprintf("rgb(%d, 0, %d)", colorValue, 255-colorValue) htmlOutput.WriteString(fmt.Sprintf( ``, bgColor, warmDays, )) } htmlOutput.WriteString(``) } htmlOutput.WriteString(`
Month%s
` + month + `%d
`) // 打印HTML结果 fmt.Println(htmlOutput.String()) }