新版本
This commit is contained in:
		
							parent
							
								
									5f9147dc43
								
							
						
					
					
						commit
						a333376c57
					
				
							
								
								
									
										20
									
								
								base.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								base.go
									
									
									
									
									
								
							| @ -7,6 +7,7 @@ import ( | ||||
| 
 | ||||
| 	"github.com/474420502/structure/compare" | ||||
| 	"github.com/474420502/structure/tree/treelist" | ||||
| 	"github.com/klauspost/compress/zstd" | ||||
| 	"go.mongodb.org/mongo-driver/bson" | ||||
| ) | ||||
| 
 | ||||
| @ -22,10 +23,18 @@ func GetAll() (result *treelist.Tree[int64]) { | ||||
| 
 | ||||
| 	f, err := os.Open("./stocks.gob") | ||||
| 	if err == nil { | ||||
| 		err = gob.NewDecoder(f).Decode(&stocks) | ||||
| 		dec, err := zstd.NewReader(f) | ||||
| 		if err != nil { | ||||
| 			panic(err) | ||||
| 		} | ||||
| 		defer dec.Close() | ||||
| 		// dec := f | ||||
| 		err = gob.NewDecoder(dec).Decode(&stocks) | ||||
| 		if err != nil { | ||||
| 			panic(err) | ||||
| 		} | ||||
| 		defer f.Close() | ||||
| 
 | ||||
| 	} else { | ||||
| 		for cur.Next(context.TODO()) { | ||||
| 			var s Stock | ||||
| @ -42,8 +51,15 @@ func GetAll() (result *treelist.Tree[int64]) { | ||||
| 		if err != nil { | ||||
| 			panic(err) | ||||
| 		} | ||||
| 		defer f.Close() | ||||
| 
 | ||||
| 		err = gob.NewEncoder(f).Encode(stocks) | ||||
| 		enc, err := zstd.NewWriter(f) | ||||
| 		if err != nil { | ||||
| 			panic(err) | ||||
| 		} | ||||
| 		defer enc.Close() | ||||
| 		// enc := f | ||||
| 		err = gob.NewEncoder(enc).Encode(&stocks) | ||||
| 		if err != nil { | ||||
| 			panic(err) | ||||
| 		} | ||||
|  | ||||
							
								
								
									
										5
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.go
									
									
									
									
									
								
							| @ -72,6 +72,7 @@ func GetDefaultPage() *rod.Page { | ||||
| var client *mongo.Client | ||||
| var cstock *mongo.Collection | ||||
| var DateStocks *treelist.Tree[int64] | ||||
| var CountedDays map[int]bool | ||||
| var err error | ||||
| 
 | ||||
| func init() { | ||||
| @ -83,6 +84,10 @@ func init() { | ||||
| 	} | ||||
| 	cstock = client.Database("money").Collection("stock") | ||||
| 	DateStocks = GetAll() | ||||
| 	CountedDays = map[int]bool{} | ||||
| 	for i := 1; i < 7; i++ { | ||||
| 		CountedDays[1<<i] = true | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func main() { | ||||
|  | ||||
							
								
								
									
										63
									
								
								main_test.go
									
									
									
									
									
								
							
							
						
						
									
										63
									
								
								main_test.go
									
									
									
									
									
								
							| @ -1,12 +1,15 @@ | ||||
| package moneymoney | ||||
| 
 | ||||
| import ( | ||||
| 	"encoding/gob" | ||||
| 	"log" | ||||
| 	"os" | ||||
| 	"sort" | ||||
| 	"testing" | ||||
| 	"time" | ||||
| 
 | ||||
| 	"github.com/474420502/structure/tree/treelist" | ||||
| 	"github.com/klauspost/compress/zstd" | ||||
| ) | ||||
| 
 | ||||
| const 亿 = 100000000 | ||||
| @ -182,15 +185,11 @@ func TestCase3(t *testing.T) { | ||||
| 		cmpiter := citer.Clone() | ||||
| 
 | ||||
| 		var i = 0 | ||||
| 		var step = 1 | ||||
| 		for ; i < 2; i++ { | ||||
| 			cmpiter.Prev() | ||||
| 		} | ||||
| 
 | ||||
| 		// 向前移动的天数 | ||||
| 		for cmpiter.Valid() { | ||||
| 
 | ||||
| 			todayIter.SeekToFirst() | ||||
| 
 | ||||
| 			cmpday := cmpiter.Value().(*treelist.Tree[int64]) | ||||
| 
 | ||||
| 			for todayIter.Valid() { | ||||
| @ -200,20 +199,64 @@ func TestCase3(t *testing.T) { | ||||
| 				ic, ok := cmpday.Get(s.Code) | ||||
| 				if ok { | ||||
| 					c := ic.(*Stock) | ||||
| 					// TODO 存这个属性 | ||||
| 					(c.ClosingPrice - s.ClosingPrice/c.ClosingPrice) | ||||
| 					if c.Extend == nil { | ||||
| 						c.Extend = &StockExtend{} | ||||
| 					} | ||||
| 					// 满足相邻天数的处理 | ||||
| 					if len(c.Extend.UpsDownsRatioDays) == 0 { | ||||
| 						if _, ok := CountedDays[i]; ok { | ||||
| 							UpsDownsRatioDays := ((c.ClosingPrice - s.ClosingPrice) / c.ClosingPrice) | ||||
| 							c.Extend.UpsDownsRatioDays = append(c.Extend.UpsDownsRatioDays, UpsDownsRatioDays) | ||||
| 						} | ||||
| 					} | ||||
| 
 | ||||
| 					// TODO: 其他的统计处理 | ||||
| 
 | ||||
| 				} | ||||
| 
 | ||||
| 				todayIter.Next() | ||||
| 			} | ||||
| 
 | ||||
| 			step = step << 1 | ||||
| 			for i := 0; i < step; i++ { | ||||
| 				cmpiter.Prev() | ||||
| 			if i >= 1<<7 { | ||||
| 				break | ||||
| 			} | ||||
| 
 | ||||
| 			cmpiter.Prev() | ||||
| 			i++ | ||||
| 		} | ||||
| 		citer.Next() | ||||
| 	} | ||||
| 
 | ||||
| 	var stocks []*Stock | ||||
| 	DateStocks.Traverse(func(s *treelist.Slice[int64]) bool { | ||||
| 		s.Value.(*treelist.Tree[int64]).Traverse(func(s *treelist.Slice[int64]) bool { | ||||
| 			stocks = append(stocks, s.Value.(*Stock)) | ||||
| 			return true | ||||
| 		}) | ||||
| 
 | ||||
| 		return true | ||||
| 	}) | ||||
| 
 | ||||
| 	if stocks != nil { | ||||
| 
 | ||||
| 		f, err := os.OpenFile("./stocks1.gob", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644) | ||||
| 		if err != nil { | ||||
| 			panic(err) | ||||
| 		} | ||||
| 		defer f.Close() | ||||
| 
 | ||||
| 		enc, err := zstd.NewWriter(f) | ||||
| 		if err != nil { | ||||
| 			panic(err) | ||||
| 		} | ||||
| 		defer enc.Close() | ||||
| 
 | ||||
| 		err = gob.NewEncoder(enc).Encode(stocks) | ||||
| 		if err != nil { | ||||
| 			panic(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| func TestCase2(t *testing.T) { | ||||
|  | ||||
							
								
								
									
										8
									
								
								unity.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								unity.go
									
									
									
									
									
								
							| @ -35,6 +35,14 @@ type Stock struct { | ||||
| 	CirculatingMarketValue float64 `json:"流通市值" bson:"流通市值"` | ||||
| 	// 股票数字代码 | ||||
| 	Code int64 `json:"股票数字代码" bson:"股票数字代码"` | ||||
| 
 | ||||
| 	Extend *StockExtend `json:"Extend" bson:"Extend"` | ||||
| } | ||||
| 
 | ||||
| type StockExtend struct { | ||||
| 	UpsDownsRatioDays []float64 `json:"UpsDownsRatioDays" bson:"UpsDownsRatioDays"` | ||||
| 	MaxPriceDays      float64   `json:"MaxPriceDays" bson:"MaxPriceDays"` | ||||
| 	MinPriceDay       float64   `json:"MinPriceDay" bson:"MinPriceDay"` | ||||
| } | ||||
| 
 | ||||
| type StockBase struct { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user