key_features.go 929 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package sub_helper
  2. // KeyFeatures 钥匙的组合特征
  3. type KeyFeatures struct {
  4. Big Feature // 大锯齿
  5. Middle Feature // 中锯齿
  6. Small Feature // 小锯齿
  7. }
  8. func NewKeyFeatures(big, middle, small Feature) KeyFeatures {
  9. return KeyFeatures{
  10. big, middle, small,
  11. }
  12. }
  13. // Feature 钥匙锯齿的特征
  14. type Feature struct {
  15. BigThanTime float64 // 大于这个时间
  16. LessThanTime float64 // 小于这个时间
  17. LeastCount int // 至少有几个特征
  18. NowCount int // 用于计数
  19. }
  20. // NewFeature 时间如果传入的是 -1,那么就跳过这个判断
  21. func NewFeature(BigThanTime, LessThanTime float64, LeastCount int) Feature {
  22. return Feature{
  23. BigThanTime, LessThanTime, LeastCount, 0,
  24. }
  25. }
  26. // Match 判断这个间隔是否符合要求
  27. func (f Feature) Match(interval float64) bool {
  28. if interval > f.BigThanTime && interval < f.LessThanTime {
  29. return true
  30. } else {
  31. return false
  32. }
  33. }