gitee.com/quant1x/engine@v1.8.4/factors/adapter.go (about) 1 package factors 2 3 import ( 4 "fmt" 5 "gitee.com/quant1x/engine/cache" 6 "gitee.com/quant1x/gox/util/treemap" 7 "strings" 8 "sync" 9 ) 10 11 const ( 12 // 闪存路径 13 cache1dPrefix = "flash" 14 // 默认证券代码为上证指数 15 defaultSecurityCode = "sh000001" 16 ) 17 18 // 返回文件路径, 指定关键字和日期 19 func getCache1DFilepath(key, date string) string { 20 cachePath, key, found := strings.Cut(key, "/") 21 if !found { 22 key = cachePath 23 cachePath = cache1dPrefix 24 } 25 cachePath = cache.GetRootPath() + "/" + cachePath 26 year := date[:4] 27 filename := fmt.Sprintf("%s/%s/%s.%s", cachePath, year, key, date) 28 return filename 29 } 30 31 // FeatureRotationAdapter 特征缓存日旋转适配器 32 // 33 // 一天一个特征组合缓存文件 34 type FeatureRotationAdapter interface { 35 // Name 名称 36 Name() string 37 // Checkout 加载指定日期的缓存 38 Checkout(date ...string) 39 // Merge 合并数据 40 Merge(p *treemap.Map) 41 // Factory 工厂 42 Factory(date, securityCode string) Feature 43 } 44 45 var ( 46 __mutexFeatureRotationAdapters sync.Mutex 47 __mapFeatureRotationAdapters = map[string]FeatureRotationAdapter{} 48 ) 49 50 func RegisterFeatureRotationAdapter(key string, adapter FeatureRotationAdapter) { 51 __mutexFeatureRotationAdapters.Lock() 52 defer __mutexFeatureRotationAdapters.Unlock() 53 __mapFeatureRotationAdapters[key] = adapter 54 } 55 56 // SwitchDate 统一切换数据的缓存日期 57 func SwitchDate(date string) { 58 __mutexFeatureRotationAdapters.Lock() 59 defer __mutexFeatureRotationAdapters.Unlock() 60 for _, v := range __mapFeatureRotationAdapters { 61 v.Checkout(date) 62 } 63 } 64 65 func Get(key string) FeatureRotationAdapter { 66 return __mapFeatureRotationAdapters[key] 67 }