|
@ -465,30 +465,25 @@ func (th *TimeArrowHelper) CallHitTimeArrow(t time.Time, group string, call func |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (th *TimeArrowHelper) GetHitTimeArrow(t time.Time, group string, expandTags ...string) (*TimeArrow, error) { |
|
|
func (th *TimeArrowHelper) GetHitTimeArrow(t time.Time, group string, expandTags ...string) (*TimeArrow, error) { |
|
|
startTime := time.Now() |
|
|
|
|
|
defer func() { |
|
|
|
|
|
log.Println("GetHitTimeArrow耗时:", time.Since(startTime)) |
|
|
|
|
|
}() |
|
|
|
|
|
log.Println("GetHitTimeArrow", t, group, expandTags) |
|
|
|
|
|
dataStartTime := time.Now() |
|
|
|
|
|
ta, err := th.GetData(group) |
|
|
ta, err := th.GetData(group) |
|
|
dataEndTime := time.Now() |
|
|
|
|
|
log.Println("GetData耗时:", dataEndTime.Sub(dataStartTime)) |
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
sliceStartTime := time.Now() |
|
|
|
|
|
sort.Slice(ta, func(i, j int) bool { |
|
|
sort.Slice(ta, func(i, j int) bool { |
|
|
return ta[i].Weights > ta[j].Weights |
|
|
return ta[i].Weights > ta[j].Weights |
|
|
}) |
|
|
}) |
|
|
log.Println("Slice排序耗时:", time.Since(sliceStartTime)) |
|
|
|
|
|
|
|
|
|
|
|
forStart := time.Now() |
|
|
|
|
|
|
|
|
|
|
|
taSize := len(ta) |
|
|
|
|
|
log.Println("taSize: ", taSize) |
|
|
|
|
|
for e := range ta { |
|
|
for e := range ta { |
|
|
|
|
|
if ta[e].Type != TimeArrowTypeInHolidays && |
|
|
|
|
|
ta[e].Type != TimeArrowTypeAtLastDayHolidays && |
|
|
|
|
|
ta[e].Type != TimeArrowTypeDayOfWeek && |
|
|
|
|
|
ta[e].Type != TimeArrowTypeDayOfMonth && |
|
|
|
|
|
ta[e].Type != TimeArrowTypeDateSlice && |
|
|
|
|
|
ta[e].Type != TimeArrowTypePriorToDayHolidays { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//当天具体时间判断
|
|
|
//当天具体时间判断
|
|
|
if !isInTimeOfDay(t, ta[e]) { |
|
|
if !isInTimeOfDay(t, ta[e]) { |
|
|
continue |
|
|
continue |
|
@ -503,48 +498,36 @@ func (th *TimeArrowHelper) GetHitTimeArrow(t time.Time, group string, expandTags |
|
|
case TimeArrowTypeDayOfWeek: |
|
|
case TimeArrowTypeDayOfWeek: |
|
|
//一周中某一天是否判定
|
|
|
//一周中某一天是否判定
|
|
|
if isInWeekOfDay(t, ta[e]) { |
|
|
if isInWeekOfDay(t, ta[e]) { |
|
|
log.Println("命中DayOfWeek:", ta[e].Type, ta[e].TimeArrowId) |
|
|
|
|
|
log.Println("for循环耗时:", time.Since(forStart)) |
|
|
|
|
|
return &ta[e], nil |
|
|
return &ta[e], nil |
|
|
} |
|
|
} |
|
|
break |
|
|
break |
|
|
case TimeArrowTypeDayOfMonth: |
|
|
case TimeArrowTypeDayOfMonth: |
|
|
//一月中某一天是否判定
|
|
|
//一月中某一天是否判定
|
|
|
if isInDayOfMonth(t, ta[e]) { |
|
|
if isInDayOfMonth(t, ta[e]) { |
|
|
log.Println("命中DayOfMonth:", ta[e].Type, ta[e].TimeArrowId) |
|
|
|
|
|
log.Println("for循环耗时:", time.Since(forStart)) |
|
|
|
|
|
return &ta[e], nil |
|
|
return &ta[e], nil |
|
|
} |
|
|
} |
|
|
break |
|
|
break |
|
|
case TimeArrowTypeDateSlice: |
|
|
case TimeArrowTypeDateSlice: |
|
|
//一月中某一天是否判定
|
|
|
//一月中某一天是否判定
|
|
|
if isInDateSlice(t, ta[e]) { |
|
|
if isInDateSlice(t, ta[e]) { |
|
|
log.Println("命中DateSlice:", ta[e].Type, ta[e].TimeArrowId) |
|
|
|
|
|
log.Println("for循环耗时:", time.Since(forStart)) |
|
|
|
|
|
return &ta[e], nil |
|
|
return &ta[e], nil |
|
|
} |
|
|
} |
|
|
break |
|
|
break |
|
|
case TimeArrowTypeAtLastDayHolidays: |
|
|
case TimeArrowTypeAtLastDayHolidays: |
|
|
//节假日最后一天
|
|
|
//节假日最后一天
|
|
|
if isInAtLastDayHolidays(t) { |
|
|
if isInAtLastDayHolidays(t) { |
|
|
log.Println("命中AtLastDayHolidays:", ta[e].Type, ta[e].TimeArrowId) |
|
|
|
|
|
log.Println("for循环耗时:", time.Since(forStart)) |
|
|
|
|
|
return &ta[e], nil |
|
|
return &ta[e], nil |
|
|
} |
|
|
} |
|
|
break |
|
|
break |
|
|
case TimeArrowTypePriorToDayHolidays: |
|
|
case TimeArrowTypePriorToDayHolidays: |
|
|
//节假日前一天
|
|
|
//节假日前一天
|
|
|
if isInPriorToDayHolidays(t) { |
|
|
if isInPriorToDayHolidays(t) { |
|
|
log.Println("命中PriorToDayHolidays:", ta[e].Type, ta[e].TimeArrowId) |
|
|
|
|
|
log.Println("for循环耗时:", time.Since(forStart)) |
|
|
|
|
|
return &ta[e], nil |
|
|
return &ta[e], nil |
|
|
} |
|
|
} |
|
|
break |
|
|
break |
|
|
case TimeArrowTypeInHolidays: |
|
|
case TimeArrowTypeInHolidays: |
|
|
//节假日
|
|
|
//节假日
|
|
|
if isInHolidays(t) { |
|
|
if isInHolidays(t) { |
|
|
log.Println("命中InHolidays:", ta[e].Type, ta[e].TimeArrowId) |
|
|
|
|
|
log.Println("for循环耗时:", time.Since(forStart)) |
|
|
|
|
|
return &ta[e], nil |
|
|
return &ta[e], nil |
|
|
} |
|
|
} |
|
|
break |
|
|
break |
|
@ -553,6 +536,5 @@ func (th *TimeArrowHelper) GetHitTimeArrow(t time.Time, group string, expandTags |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.Println("for循环耗时:", time.Since(forStart)) |
|
|
|
|
|
return nil, nil |
|
|
return nil, nil |
|
|
} |
|
|
} |