gitee.com/quant1x/engine@v1.8.4/factors/dataset_report.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/gotdx/quotes"
     8  	"gitee.com/quant1x/gox/api"
     9  	"gitee.com/quant1x/gox/logger"
    10  	"gitee.com/quant1x/gox/progressbar"
    11  )
    12  
    13  // DataQuarterlyReport 季报
    14  type DataQuarterlyReport struct {
    15  	cache.DataSummary
    16  	Date  string
    17  	Code  string
    18  	cache map[string]dfcf.QuarterlyReport
    19  }
    20  
    21  func init() {
    22  	summary := __mapDataSets[BaseQuarterlyReports]
    23  	_ = cache.Register(&DataQuarterlyReport{DataSummary: summary})
    24  }
    25  
    26  func (r *DataQuarterlyReport) Clone(date string, code string) DataSet {
    27  	summary := __mapDataSets[BaseQuarterlyReports]
    28  	var dest = DataQuarterlyReport{DataSummary: summary, Date: date, Code: code}
    29  	return &dest
    30  }
    31  
    32  func (r *DataQuarterlyReport) GetDate() string {
    33  	return r.Date
    34  }
    35  
    36  func (r *DataQuarterlyReport) GetSecurityCode() string {
    37  	return r.Code
    38  }
    39  
    40  func (r *DataQuarterlyReport) Print(code string, date ...string) {
    41  	//TODO implement me
    42  	panic("implement me")
    43  }
    44  
    45  func (r *DataQuarterlyReport) Filename(date, code string) string {
    46  	//TODO implement me
    47  	panic("implement me")
    48  }
    49  
    50  func (r *DataQuarterlyReport) Init(ctx context.Context, date string) error {
    51  	barIndex := 1
    52  	value, ok := ctx.Value(cache.KBarIndex).(int)
    53  	if ok {
    54  		barIndex = value
    55  	}
    56  	barIndex++
    57  	r.cache = IntegrateQuarterlyReports(barIndex, date)
    58  	return nil
    59  }
    60  
    61  func (r *DataQuarterlyReport) Checkout(securityCode, date string) {
    62  	//TODO implement me
    63  	panic("implement me")
    64  }
    65  
    66  func (r *DataQuarterlyReport) Check(cacheDate, featureDate string) error {
    67  	//TODO implement me
    68  	panic("implement me")
    69  }
    70  
    71  func (r *DataQuarterlyReport) Update(date string) {
    72  	_ = date
    73  }
    74  
    75  func (r *DataQuarterlyReport) Repair(date string) {
    76  	_ = date
    77  }
    78  
    79  func (r *DataQuarterlyReport) Increase(snapshot quotes.Snapshot) {
    80  	_ = snapshot
    81  }
    82  
    83  // IntegrateQuarterlyReports 更新季报数据
    84  func IntegrateQuarterlyReports(barIndex int, date string) map[string]dfcf.QuarterlyReport {
    85  	modName := "季报概要信息"
    86  	logger.Info(modName + ", 任务开始启动...")
    87  
    88  	allReports := []dfcf.QuarterlyReport{}
    89  	reports, pages, _ := dfcf.QuarterlyReports(date)
    90  	if pages < 1 || len(reports) == 0 {
    91  		return nil
    92  	}
    93  	allReports = append(allReports, reports...)
    94  	bar := progressbar.NewBar(barIndex, "执行["+modName+"]", pages-1)
    95  	for pageNo := 2; pageNo < pages+1; pageNo++ {
    96  		bar.Add(1)
    97  		list, pages, err := dfcf.QuarterlyReports(date, pageNo)
    98  		if err != nil || pages < 1 {
    99  			logger.Error(err)
   100  			break
   101  		}
   102  		count := len(list)
   103  		if count == 0 {
   104  			break
   105  		}
   106  		allReports = append(allReports, list...)
   107  		if count < dfcf.EastmoneyQuarterlyReportAllPageSize {
   108  			break
   109  		}
   110  	}
   111  	mapReports := map[string]dfcf.QuarterlyReport{}
   112  	if len(allReports) > 0 {
   113  		for _, v := range allReports {
   114  			mapReports[v.SecurityCode] = v
   115  		}
   116  		_, qEnd := api.GetQuarterDayByDate(date)
   117  		filename := cache.ReportsFilename(qEnd)
   118  		err := api.SlicesToCsv(filename, allReports)
   119  		if err != nil {
   120  			logger.Errorf("cache %s failed, error: %+v", filename, err)
   121  		}
   122  	}
   123  	return mapReports
   124  }