2 Star 7 Fork 10

王布衣/engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
features.go 3.51 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-10-13 07:05 . 优化update和repair数据处理流程
package storages
import (
"gitee.com/quant1x/engine/cache"
"gitee.com/quant1x/engine/cachel5"
"gitee.com/quant1x/engine/factors"
"gitee.com/quant1x/engine/market"
"gitee.com/quant1x/engine/smart"
"gitee.com/quant1x/gox/progressbar"
"gitee.com/quant1x/gox/text/runewidth"
"gitee.com/quant1x/gox/util/treemap"
)
// FeaturesUpdate 更新特征
func FeaturesUpdate(barIndex *int, cacheDate, featureDate string, plugins []cache.DataPlugin, op cache.OpKind) {
moduleName := "特征数据"
if op == cache.OpRepair {
moduleName = "修复" + moduleName
} else {
moduleName = "更新" + moduleName
}
moduleName += cacheDate
var cacheList []cachel5.CacheAdapter
maxWidth := 0
for _, plugin := range plugins {
adapter, ok := plugin.(cachel5.CacheAdapter)
if ok {
cacheList = append(cacheList, adapter)
width := runewidth.StringWidth(adapter.Name())
if width > maxWidth {
maxWidth = width
}
}
}
allCodes := market.GetCodeList()
cacheCount := len(cacheList)
barCache := progressbar.NewBar(*barIndex, "执行["+moduleName+"]", cacheCount)
for _, adapter := range cacheList {
mapFeature := treemap.NewWithStringComparator()
codeCount := len(allCodes)
barCode := progressbar.NewBar(*barIndex+1, "执行["+adapter.Name()+"]", codeCount)
dataSource := adapter.Factory(featureDate, "")
_ = dataSource.Init(barIndex, featureDate)
for _, code := range allCodes {
data := adapter.Factory(cacheDate, code).(factors.Feature)
if data.Kind() != factors.FeatureHistory {
history := smart.GetL5History(code, cacheDate)
if history != nil {
data = data.FromHistory(*history)
}
}
if op == cache.OpRepair {
data.Repair(code, cacheDate, featureDate, true)
} else {
data.Update(code, cacheDate, featureDate, true)
}
mapFeature.Put(code, data)
barCode.Add(1)
}
// 加载缓存
adapter.Checkout(cacheDate)
// 合并
adapter.Merge(mapFeature)
barCache.Add(1)
}
}
//// RepairFeatures 修复特征数据
//func RepairFeatures(barIndex *int, cacheDate, featureDate string) {
// moduleName := "修复特征数据" + cacheDate
// // 1. 获取全部注册的数据集插件
// mask := cache.PluginMaskFeature
// //dataSetList := flash.DataSetList()
// plugins := cache.Plugins(mask)
// var cacheList []cachel5.CacheAdapter
// maxWidth := 0
// for _, plugin := range plugins {
// adapter, ok := plugin.(cachel5.CacheAdapter)
// if ok {
// cacheList = append(cacheList, adapter)
// width := runewidth.StringWidth(adapter.Name())
// if width > maxWidth {
// maxWidth = width
// }
// }
// }
// allCodes := market.GetCodeList()
// cacheCount := len(cacheList)
// barCache := progressbar.NewBar(*barIndex, "执行["+moduleName+"]", cacheCount)
// for _, adapter := range cacheList {
// mapFeature := treemap.NewWithStringComparator()
// codeCount := len(allCodes)
// barCode := progressbar.NewBar(*barIndex+1, "执行["+adapter.Name()+"]", codeCount)
// dataSource := adapter.Factory(featureDate, "")
// _ = dataSource.Init(barIndex, featureDate)
// for _, code := range allCodes {
// data := adapter.Factory(cacheDate, code).(factors.Feature)
// if data.Kind() != factors.FeatureHistory {
// history := smart.GetL5History(code, cacheDate)
// if history != nil {
// data = data.FromHistory(*history)
// }
// }
// data.Repair(code, cacheDate, featureDate, true)
// mapFeature.Put(code, data)
// barCode.Add(1)
// }
// // 加载缓存
// adapter.Checkout(cacheDate)
// // 合并
// adapter.Merge(mapFeature)
// _ = adapter
// barCache.Add(1)
// }
// _ = allCodes
//}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v0.2.7

搜索帮助