gitee.com/quant1x/engine@v1.8.4/factors/dataset_report_preview.go (about) 1 package factors 2 3 import ( 4 "context" 5 "gitee.com/quant1x/engine/cache" 6 "gitee.com/quant1x/engine/datasource/dfcf" 7 "gitee.com/quant1x/exchange" 8 "gitee.com/quant1x/gotdx/quotes" 9 "gitee.com/quant1x/gox/api" 10 "gitee.com/quant1x/gox/logger" 11 "gitee.com/quant1x/gox/progressbar" 12 ) 13 14 // DataPreviewReport 业绩预告(Listed Companies'Performance Forecast) 15 type DataPreviewReport struct { 16 Manifest 17 } 18 19 func init() { 20 summary := __mapDataSets[BasePerformanceForecast] 21 _ = cache.Register(&DataPreviewReport{Manifest: Manifest{DataSummary: summary}}) 22 } 23 24 func (this *DataPreviewReport) Clone(date string, code string) DataSet { 25 summary := __mapDataSets[BasePerformanceForecast] 26 var dest = DataPreviewReport{ 27 Manifest: Manifest{ 28 DataSummary: summary, 29 Date: date, 30 Code: code, 31 }, 32 } 33 return &dest 34 } 35 36 func (this *DataPreviewReport) Init(ctx context.Context, date string) error { 37 barIndex := 1 38 value, ok := ctx.Value(cache.KBarIndex).(int) 39 if ok { 40 barIndex = value 41 } 42 barIndex++ 43 modName := "业绩预告" 44 logger.Info(modName + ", 任务开始启动...") 45 46 var allReports []dfcf.PreviewQuarterlyReport 47 // 确定更新日期 48 qBegin, _ := api.GetQuarterDayByDate(date, 0) 49 quarterBeginDate := exchange.FixTradeDate(qBegin) 50 list, pages, _, _ := dfcf.FinanceReports(quarterBeginDate, 1) 51 if pages < 1 || len(list) == 0 { 52 return nil 53 } 54 allReports = append(allReports, list...) 55 56 barSub := progressbar.NewBar(barIndex, "评估["+modName+"]", pages) 57 for pageNo := 2; pageNo < pages+1; pageNo++ { 58 barSub.Add(1) 59 list, pages, count, err := dfcf.FinanceReports(quarterBeginDate, pageNo) 60 if err != nil || pages < 1 { 61 logger.Error(err) 62 break 63 } 64 if count == 0 { 65 break 66 } 67 allReports = append(allReports, list...) 68 if count < dfcf.EastmoneyFinanceReportsPageSize { 69 break 70 } 71 } 72 if len(allReports) > 0 { 73 filename := cache.PreviewReportFilename(quarterBeginDate) 74 _ = api.SlicesToCsv(filename, allReports) 75 } 76 logger.Info(modName + ", 任务开始结束...") 77 return nil 78 } 79 80 func (this *DataPreviewReport) Update(date string) { 81 _ = date 82 } 83 84 func (this *DataPreviewReport) Repair(date string) { 85 _ = date 86 } 87 88 func (this *DataPreviewReport) Increase(snapshot quotes.Snapshot) { 89 _ = snapshot 90 } 91 92 func (this *DataPreviewReport) Print(code string, date ...string) { 93 _ = code 94 _ = date 95 }