2 Star 7 Fork 10

王布衣/engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cache_report.go 2.91 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-10-19 13:04 . 优化代码结构
package datasets
import (
"context"
"gitee.com/quant1x/engine/cache"
"gitee.com/quant1x/engine/datasets/dfcf"
"gitee.com/quant1x/gotdx/quotes"
"gitee.com/quant1x/gox/api"
"gitee.com/quant1x/gox/logger"
"gitee.com/quant1x/gox/progressbar"
)
// DataQuarterlyReport 季报
type DataQuarterlyReport struct {
cache.DataSummary
Date string
Code string
cache map[string]dfcf.QuarterlyReport
}
func init() {
scheme := mapDataSets[BaseQuarterlyReports]
_ = cache.Register(&DataQuarterlyReport{DataSummary: scheme})
}
func (r *DataQuarterlyReport) Clone(date string, code string) DataSet {
scheme := mapDataSets[BaseQuarterlyReports]
var dest = DataQuarterlyReport{DataSummary: scheme, Date: date, Code: code}
return &dest
}
func (r *DataQuarterlyReport) GetDate() string {
return r.Date
}
func (r *DataQuarterlyReport) GetSecurityCode() string {
return r.Code
}
func (r *DataQuarterlyReport) Print(code string, date ...string) {
//TODO implement me
panic("implement me")
}
func (r *DataQuarterlyReport) Filename(date, code string) string {
//TODO implement me
panic("implement me")
}
func (r *DataQuarterlyReport) Init(ctx context.Context, date string) error {
barIndex := 1
value, ok := ctx.Value(cache.KBarIndex).(int)
if ok {
barIndex = value
}
barIndex++
r.cache = IntegrateQuarterlyReports(barIndex, date)
return nil
}
func (r *DataQuarterlyReport) Checkout(securityCode, date string) {
//TODO implement me
panic("implement me")
}
func (r *DataQuarterlyReport) Check(cacheDate, featureDate string) error {
//TODO implement me
panic("implement me")
}
func (r *DataQuarterlyReport) Update(date string) {
_ = date
}
func (r *DataQuarterlyReport) Repair(date string) {
_ = date
}
func (r *DataQuarterlyReport) Increase(snapshot quotes.Snapshot) {
_ = snapshot
}
// IntegrateQuarterlyReports 更新季报数据
func IntegrateQuarterlyReports(barIndex int, date string) map[string]dfcf.QuarterlyReport {
modName := "季报概要信息"
logger.Info(modName + ", 任务开始启动...")
allReports := []dfcf.QuarterlyReport{}
reports, pages, _ := dfcf.QuarterlyReports(date)
if pages < 1 || len(reports) == 0 {
return nil
}
allReports = append(allReports, reports...)
bar := progressbar.NewBar(barIndex, "执行["+modName+"]", pages-1)
for pageNo := 2; pageNo < pages+1; pageNo++ {
bar.Add(1)
list, pages, err := dfcf.QuarterlyReports(date, pageNo)
if err != nil || pages < 1 {
logger.Error(err)
break
}
count := len(list)
if count == 0 {
break
}
allReports = append(allReports, list...)
if count < dfcf.EastmoneyQuarterlyReportAllPageSize {
break
}
}
mapReports := map[string]dfcf.QuarterlyReport{}
if len(allReports) > 0 {
for _, v := range allReports {
mapReports[v.SecurityCode] = v
}
filename := cache.ReportsFilename(date)
err := api.SlicesToCsv(filename, allReports)
if err != nil {
logger.Errorf("cache %s failed, error: %+v", filename, err)
}
}
return mapReports
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v0.4.9

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385