2 Star 5 Fork 10

王布衣/engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
adapter.go 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-01-17 08:57 . 调整数据适配器部分结构名
package factors
import (
"fmt"
"gitee.com/quant1x/engine/cache"
"gitee.com/quant1x/gox/util/treemap"
"strings"
"sync"
)
const (
// 闪存路径
cache1dPrefix = "flash"
// 默认证券代码为上证指数
defaultSecurityCode = "sh000001"
)
// 返回文件路径, 指定关键字和日期
func getCache1DFilepath(key, date string) string {
cachePath, key, found := strings.Cut(key, "/")
if !found {
key = cachePath
cachePath = cache1dPrefix
}
cachePath = cache.GetRootPath() + "/" + cachePath
year := date[:4]
filename := fmt.Sprintf("%s/%s/%s.%s", cachePath, year, key, date)
return filename
}
// FeatureRotationAdapter 特征缓存日旋转适配器
//
// 一天一个特征组合缓存文件
type FeatureRotationAdapter interface {
// Name 名称
Name() string
// Checkout 加载指定日期的缓存
Checkout(date ...string)
// Merge 合并数据
Merge(p *treemap.Map)
// Factory 工厂
Factory(date, securityCode string) Feature
}
var (
__mutexFeatureRotationAdapters sync.Mutex
__mapFeatureRotationAdapters = map[string]FeatureRotationAdapter{}
)
func RegisterFeatureRotationAdapter(key string, adapter FeatureRotationAdapter) {
__mutexFeatureRotationAdapters.Lock()
defer __mutexFeatureRotationAdapters.Unlock()
__mapFeatureRotationAdapters[key] = adapter
}
// SwitchDate 统一切换数据的缓存日期
func SwitchDate(date string) {
__mutexFeatureRotationAdapters.Lock()
defer __mutexFeatureRotationAdapters.Unlock()
for _, v := range __mapFeatureRotationAdapters {
v.Checkout(date)
}
}
func Get(key string) FeatureRotationAdapter {
return __mapFeatureRotationAdapters[key]
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v1.7.2

搜索帮助