2025-02-20 14:27:18 +08:00
|
|
|
package models
|
2024-12-15 17:40:14 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Tray struct {
|
2025-02-20 14:19:47 +08:00
|
|
|
InstID string `json:"instId,string"`
|
|
|
|
Period string `json:"period,string"`
|
|
|
|
Count int `json:"count,number"`
|
|
|
|
Scale float64 `json:"scale,number"`
|
|
|
|
LastUpdateTime int64 `json:"lastUpdateTime,number"`
|
|
|
|
SeriesMap map[string]*Series `json:"seriesMap"`
|
2024-12-15 17:40:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type PixelSeries struct {
|
|
|
|
Count int64 `json:"count"`
|
|
|
|
Section int64 `json:"section"`
|
2025-02-20 14:19:47 +08:00
|
|
|
List []*analysis/Pixel `json:"list"`
|
2024-12-15 17:40:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (tr *Tray) Init(instId string) {
|
|
|
|
tr.InstID = instId
|
|
|
|
tr.Count = 24
|
|
|
|
tr.Scale = float64(0.005)
|
|
|
|
// tr.SeriesMap = make(map[string]*Series)
|
|
|
|
}
|
|
|
|
func (tr *Tray) SetToKey(cr *Core) error {
|
|
|
|
js, _ := json.Marshal(tr)
|
|
|
|
keyName := tr.InstID + "|" + tr.Period + "|tray"
|
|
|
|
_, err := cr.RedisLocalCli.Set(keyName, string(js), 0).Result()
|
|
|
|
// fmt.Println(utils.GetFuncName(), "tray SetToKey:", string(js))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO 执行单维度分析,相对应的是跨维度的分析,那个还没想好
|
|
|
|
// 单维度下的分析结果中包含以下信息:
|
|
|
|
// 1.
|
|
|
|
func (tr *Tray) Analytics(cr *Core) {
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO 实例化一个series
|
2025-02-20 14:19:47 +08:00
|
|
|
func (tr *Tray) NewSeries(cr *Core, period string) (*Series, error) {
|
|
|
|
sr := Series{
|
|
|
|
InstID: tr.InstID,
|
|
|
|
Period: period,
|
|
|
|
Count: tr.Count,
|
|
|
|
Scale: tr.Scale,
|
|
|
|
CandleSeries: &PixelList{},
|
|
|
|
Ma7Series: &PixelList{},
|
|
|
|
Ma30Series: &PixelList{},
|
|
|
|
}
|
|
|
|
// 自我更新
|
|
|
|
err := sr.Refresh(cr)
|
|
|
|
tr.SeriesMap["period"+period] = &sr
|
|
|
|
return &sr, err
|
|
|
|
}
|