2 Star 4 Fork 10

王布衣/engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
command_update.go 3.11 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-01-23 09:09 . 调整进度条bar的index
package command
import (
"fmt"
"gitee.com/quant1x/engine/cache"
"gitee.com/quant1x/engine/storages"
cmder "github.com/spf13/cobra"
)
const (
updateCommand = "update"
updateDescription = "更新数据"
)
var (
// CmdUpdate 更新数据
CmdUpdate *cmder.Command = nil
barIndex = 1
)
func initUpdate() {
CmdUpdate = &cmder.Command{
Use: updateCommand,
Example: Application + " " + updateCommand + " --all",
//Args: args.MinimumNArgs(0),
Args: func(cmd *cmder.Command, args []string) error {
return nil
},
Short: updateDescription,
Long: updateDescription,
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 len(flagBaseData.Value) > 0 {
all, keywords := parseFields(flagBaseData.Value)
if all || len(keywords) == 0 {
clear(keywords)
}
handleUpdateBaseDataWithKeywords(cacheDate, featureDate, keywords...)
} else if len(flagFeatures.Value) > 0 {
all, keywords := parseFields(flagFeatures.Value)
if all || len(keywords) == 0 {
clear(keywords)
}
handleUpdateFeaturesWithKeywords(cacheDate, featureDate, keywords...)
} else {
fmt.Println("Error: 非全部更新, 必须携带--features或--base")
_ = cmd.Usage()
}
},
}
commandInit(CmdUpdate, &flagAll)
// 1. 基础数据
plugins := cache.Plugins(cache.PluginMaskBaseData)
flagBaseData.Usage = getPluginsUsage(plugins)
commandInit(CmdUpdate, &flagBaseData)
// 2. 特征数据
plugins = cache.Plugins(cache.PluginMaskFeature)
flagFeatures.Usage = getPluginsUsage(plugins)
commandInit(CmdUpdate, &flagFeatures)
//// 3. 处理异常
//CmdUpdate.SetFlagErrorFunc(func(cmd *cmder.Command, err error) error {
// return nil
//})
}
// 全部更新
func handleUpdateAll(cacheDate, featureDate string) {
handleUpdateBaseData(featureDate)
handleUpdateFeaturesWithKeywords(cacheDate, featureDate)
}
// 更新基础数据
func handleUpdateBaseData(date string) {
// 1. 获取全部注册的数据集插件
mask := cache.PluginMaskBaseData
plugins := cache.Plugins(mask)
// 2. 执行操作
storages.BaseDataUpdate(barIndex, date, plugins, cache.OpUpdate)
}
// 更新基础数据
func handleUpdateBaseDataWithKeywords(cacheDate, featureDate string, keywords ...string) {
plugins := cache.PluginsWithName(cache.PluginMaskBaseData, keywords...)
if len(plugins) == 0 {
// 1. 获取全部注册的数据集插件
mask := cache.PluginMaskBaseData
plugins = cache.Plugins(mask)
}
storages.BaseDataUpdate(barIndex, featureDate, plugins, cache.OpUpdate)
_ = cacheDate
}
// 更新特征组合
func handleUpdateFeaturesWithKeywords(cacheDate, featureDate string, keywords ...string) {
plugins := cache.PluginsWithName(cache.PluginMaskFeature, keywords...)
if len(plugins) == 0 {
// 1. 获取全部注册的数据集插件
mask := cache.PluginMaskFeature
plugins = cache.Plugins(mask)
}
storages.FeaturesUpdate(&barIndex, cacheDate, featureDate, plugins, cache.OpUpdate)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v1.4.1

搜索帮助

Cb406eda 1850385 E526c682 1850385