diff --git a/base.go b/base.go index 05217fe..710e162 100644 --- a/base.go +++ b/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) } diff --git a/main.go b/main.go index 647bc55..72ee1d1 100644 --- a/main.go +++ b/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<= 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) { diff --git a/unity.go b/unity.go index 9b18bd7..8d590f0 100644 --- a/unity.go +++ b/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 {