metadata

package
v0.0.0-...-fb1bee7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ClientCollector pb_collector.CollectorClient
	ClientStorage   pb_storage.StorageClient
)
View Source
var (
	BoldGreen = color.New(color.FgGreen, color.Bold)
	BoldRed   = color.New(color.FgRed, color.Bold)
)
View Source
var CrawlCommand = &cobra.Command{
	Use:   "crawl",
	Short: "抓取数据",
	Run: func(cmd *cobra.Command, args []string) {
		stub, closeFunc, err := client.NewCollectorWithTarget(fmt.Sprintf("%s:50003", IPVar))
		if err != nil {
			log.Printf("create collector client failure, nest error: %v", err)
			return
		}
		defer closeFunc()
		ClientCollector = stub

		if err := crawl(context.Background()); err != nil {
			log.Printf("crawl data failure, nest error: %v", err)
			return
		}
	},
}
View Source
var (
	IPVar string
)
View Source
var ReportCommand = &cobra.Command{
	Use:   "report",
	Short: "报告数据",
	Run: func(cmd *cobra.Command, args []string) {
		var (
			begin = time.Now()
			err   error
		)
		if beginVar != "" {
			begin, err = time.Parse(time.DateTime, fmt.Sprintf("%s 00:00:01", beginVar))
			if err != nil {
				log.Printf("[F] 转换日期失败, nest error: %v, begin: %s", err, beginVar)
				return
			}
		}

		if err := report(context.Background(), "daily", begin.Format(time.DateOnly)); err != nil {
			log.Printf("[F] Report failure, nest error: %v", err)
		} else {
			log.Printf("=> 日期:%s,报告已生成,请查看 ntfy 通知 app.", begin.Format(time.DateOnly))
		}
	},
}
View Source
var ShowCommand = &cobra.Command{
	Use:   "show",
	Short: "统计数据",
	Run: func(cmd *cobra.Command, args []string) {
		end, err := time.Parse(time.DateTime, fmt.Sprintf("%s 23:59:59", endVar))
		if err != nil {
			log.Printf("[F] 转换结束日期失败, nest error: %v, end: %s", err, end)
			return
		}

		begin := end.Add(-30 * 25 * time.Hour)
		if beginVar != "" {
			begin, err = time.Parse(time.DateTime, fmt.Sprintf("%s 00:00:01", beginVar))
			if err != nil {
				log.Printf("[F] 转换开始日期失败, nest error: %v, begin: %s", err, begin)
				return
			}
		}

		stub, closeFunc, err := client.NewStorageWithTarget(fmt.Sprintf("%s:50001", IPVar))
		if err != nil {
			log.Printf("create storage client failure, nest error: %v", err)
			return
		}
		defer closeFunc()
		ClientStorage = stub

		for begin.Before(end) {
			date := begin.Format(time.DateOnly)

			status := BoldGreen.Sprint("正常")
			days, weeks, err := show(context.Background(), date)
			if err != nil {
				log.Printf("数据统计失败, nest error: %v, date: %v", err, date)
			} else {
				if days == 0 && (begin.Weekday() == time.Monday ||
					begin.Weekday() == time.Tuesday ||
					begin.Weekday() == time.Wednesday ||
					begin.Weekday() == time.Thursday ||
					begin.Weekday() == time.Friday) {
					status = BoldRed.Sprint("缺失")
				}
				fmt.Printf("=> 数据统计, 日期: %v(%v), 日交易数据: %4v, 周交易数据: %4v, 状态: (%v)\r\n", date, timeutil.ParseWeekday(begin), days, weeks, status)
			}
			begin = begin.Add(24 * time.Hour)
		}
	},
}
View Source
var StoreCommand = &cobra.Command{
	Use:   "store",
	Short: "归档数据",
	Run: func(cmd *cobra.Command, args []string) {
		begin, err := time.Parse(time.DateTime, fmt.Sprintf("%s 00:00:01", beginVar))
		if err != nil {
			log.Printf("[F] 转换开始日期失败, nest error: %v, begin: %s", err, begin)
			return
		}
		end, err := time.Parse(time.DateTime, fmt.Sprintf("%s 23:59:59", endVar))
		if err != nil {
			log.Printf("[F] 转换结束日期失败, nest error: %v, end: %s", err, end)
			return
		}

		stubCollector, closeFunc, err := client.NewCollectorWithTarget(fmt.Sprintf("%s:50003", IPVar))
		if err != nil {
			log.Printf("create collector client failure, nest error: %v", err)
			return
		}
		defer closeFunc()
		ClientCollector = stubCollector

		stubStorage, closeFunc, err := client.NewStorageWithTarget(fmt.Sprintf("%s:50001", IPVar))
		if err != nil {
			log.Printf("create storage client failure, nest error: %v", err)
			return
		}
		defer closeFunc()
		ClientStorage = stubStorage

		for begin.Before(end) {
			var (
				date = begin.Format(time.DateOnly)
				now  = time.Now()
			)

			stocks, days, weeks, err := store(context.Background(), date)
			if err != nil {
				log.Printf("归档失败, nest error: %v, date: %v", err, date)
			} else {
				fmt.Printf("归档完成, 日期: %v, 股票数: %v, 日交易数据: %v, 周交易数据: %v, 花费: %v\r\n", date, stocks, days, weeks, time.Since(now))
			}
			begin = begin.Add(24 * time.Hour)
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL