2 Star 14 Fork 16

王布衣/engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
command_update.go 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-10-13 07:05 +08:00 . 优化update和repair数据处理流程
package command
import (
"fmt"
"gitee.com/quant1x/engine/cache"
"gitee.com/quant1x/engine/storages"
cmder "github.com/spf13/cobra"
)
var (
updateModules = []cmdFlag[bool]{}
)
// CmdUpdate 更新数据
var CmdUpdate = &cmder.Command{
Use: "update",
Example: Application + " update --all",
//Args: args.MinimumNArgs(0),
Args: func(cmd *cmder.Command, args []string) error {
return nil
},
Short: "更新股市数据",
Long: `更新股市数据`,
Run: func(cmd *cmder.Command, args []string) {
fmt.Println()
currentDate := cache.DefaultCanUpdateDate()
cacheDate, featureDate := cache.CorrectDate(currentDate)
if flagAll.Value {
// 全部更新
handleUpdateAll(cacheDate, featureDate)
} else if flagBaseData.Value {
handleUpdateBaseData(cacheDate, featureDate)
} else if flagFeatures.Value {
keywords := []string{}
for _, m := range updateModules {
if m.Value {
keywords = append(keywords, m.Name)
break
}
}
handleUpdateFeatures(cacheDate, featureDate, keywords...)
}
},
}
func initUpdate() {
commandInit(CmdUpdate, &flagAll)
commandInit(CmdUpdate, &flagBaseData)
commandInit(CmdUpdate, &flagFeatures)
plugins := cache.Plugins(cache.PluginMaskFeature)
updateModules = make([]cmdFlag[bool], len(plugins))
for i, plugin := range plugins {
key := plugin.Key()
usage := plugin.Usage()
updateModules[i] = cmdFlag[bool]{Name: key, Usage: plugin.Provider() + ": " + usage, Value: false}
CmdUpdate.Flags().BoolVar(&(updateModules[i].Value), updateModules[i].Name, updateModules[i].Value, printModules[i].Usage)
}
}
// 全部更新
func handleUpdateAll(cacheDate, featureDate string) {
handleUpdateBaseData(cacheDate, featureDate)
handleUpdateFeatures(cacheDate, featureDate)
}
// 更新基础数据
func handleUpdateBaseData(cacheDate, featureDate string) {
// 1. 获取全部注册的数据集插件
mask := cache.PluginMaskFeature
plugins := cache.Plugins(mask)
// 2. 执行操作
storages.BaseDataUpdate(barIndex, cacheDate, featureDate, plugins, cache.OpUpdate)
}
// 更新特征组合
func handleUpdateFeatures(cacheDate, featureDate string, keywords ...string) {
plugins := cache.PluginsWithName(cache.PluginMaskFeature, keywords...)
if len(plugins) == 0 {
// 1. 获取全部注册的数据集插件
mask := cache.PluginMaskFeature
//dataSetList := flash.DataSetList()
plugins = cache.Plugins(mask)
}
storages.FeaturesUpdate(&barIndex, cacheDate, featureDate, plugins, cache.OpUpdate)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v0.3.0

搜索帮助