Browse Source

update

master
public_host 3 days ago
parent
commit
c8172608e0
  1. 36
      core.go

36
core.go

@ -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) {
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)
dataEndTime := time.Now()
log.Println("GetData耗时:", dataEndTime.Sub(dataStartTime))
if err != nil {
return nil, err
}
sliceStartTime := time.Now()
sort.Slice(ta, func(i, j int) bool {
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 {
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]) {
continue
@ -503,48 +498,36 @@ func (th *TimeArrowHelper) GetHitTimeArrow(t time.Time, group string, expandTags
case TimeArrowTypeDayOfWeek:
//一周中某一天是否判定
if isInWeekOfDay(t, ta[e]) {
log.Println("命中DayOfWeek:", ta[e].Type, ta[e].TimeArrowId)
log.Println("for循环耗时:", time.Since(forStart))
return &ta[e], nil
}
break
case TimeArrowTypeDayOfMonth:
//一月中某一天是否判定
if isInDayOfMonth(t, ta[e]) {
log.Println("命中DayOfMonth:", ta[e].Type, ta[e].TimeArrowId)
log.Println("for循环耗时:", time.Since(forStart))
return &ta[e], nil
}
break
case TimeArrowTypeDateSlice:
//一月中某一天是否判定
if isInDateSlice(t, ta[e]) {
log.Println("命中DateSlice:", ta[e].Type, ta[e].TimeArrowId)
log.Println("for循环耗时:", time.Since(forStart))
return &ta[e], nil
}
break
case TimeArrowTypeAtLastDayHolidays:
//节假日最后一天
if isInAtLastDayHolidays(t) {
log.Println("命中AtLastDayHolidays:", ta[e].Type, ta[e].TimeArrowId)
log.Println("for循环耗时:", time.Since(forStart))
return &ta[e], nil
}
break
case TimeArrowTypePriorToDayHolidays:
//节假日前一天
if isInPriorToDayHolidays(t) {
log.Println("命中PriorToDayHolidays:", ta[e].Type, ta[e].TimeArrowId)
log.Println("for循环耗时:", time.Since(forStart))
return &ta[e], nil
}
break
case TimeArrowTypeInHolidays:
//节假日
if isInHolidays(t) {
log.Println("命中InHolidays:", ta[e].Type, ta[e].TimeArrowId)
log.Println("for循环耗时:", time.Since(forStart))
return &ta[e], nil
}
break
@ -553,6 +536,5 @@ func (th *TimeArrowHelper) GetHitTimeArrow(t time.Time, group string, expandTags
}
}
log.Println("for循环耗时:", time.Since(forStart))
return nil, nil
}
Loading…
Cancel
Save