Implemented history writer
This commit is contained in:
@@ -67,6 +67,18 @@ type zoomPoints struct {
|
||||
V []float64 `json:"v"`
|
||||
}
|
||||
|
||||
type historyInfoMsg struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
DurationHours float64 `json:"durationHours"`
|
||||
Decimation uint32 `json:"decimation"`
|
||||
Signals map[string]struct {
|
||||
T0 float64 `json:"t0"`
|
||||
T1 float64 `json:"t1"`
|
||||
Count uint32 `json:"count"`
|
||||
Capacity uint32 `json:"capacity"`
|
||||
} `json:"signals"`
|
||||
}
|
||||
|
||||
type event struct {
|
||||
Type string `json:"type"`
|
||||
Sources json.RawMessage `json:"sources"`
|
||||
@@ -187,9 +199,11 @@ type client struct {
|
||||
configs map[string][]signalInfo // sourceId → signals
|
||||
pushes []*pushFrame
|
||||
stats map[string]statInfo
|
||||
zooms map[uint32]map[string]zoomPoints
|
||||
trigSt []string // observed triggerState sequence
|
||||
captures []*captureFrame
|
||||
zooms map[uint32]map[string]zoomPoints
|
||||
histZooms map[uint32]map[string]zoomPoints
|
||||
historyInfo *historyInfoMsg
|
||||
trigSt []string // observed triggerState sequence
|
||||
captures []*captureFrame
|
||||
}
|
||||
|
||||
func (c *client) send(v interface{}) {
|
||||
@@ -263,6 +277,18 @@ func (c *client) pump() {
|
||||
if err := json.Unmarshal(data, &body); err == nil {
|
||||
c.zooms[ev.ReqID] = body.Signals
|
||||
}
|
||||
case "historyZoom":
|
||||
var body struct {
|
||||
Signals map[string]zoomPoints `json:"signals"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &body); err == nil {
|
||||
c.histZooms[ev.ReqID] = body.Signals
|
||||
}
|
||||
case "historyInfo":
|
||||
var hi historyInfoMsg
|
||||
if err := json.Unmarshal(data, &hi); err == nil {
|
||||
c.historyInfo = &hi
|
||||
}
|
||||
case "triggerState":
|
||||
c.trigSt = append(c.trigSt, ev.State)
|
||||
}
|
||||
@@ -302,10 +328,11 @@ func main() {
|
||||
defer ws.Close()
|
||||
|
||||
c := &client{
|
||||
ws: ws,
|
||||
deadline: time.Now().Add(*timeout),
|
||||
configs: map[string][]signalInfo{},
|
||||
zooms: map[uint32]map[string]zoomPoints{},
|
||||
ws: ws,
|
||||
deadline: time.Now().Add(*timeout),
|
||||
configs: map[string][]signalInfo{},
|
||||
zooms: map[uint32]map[string]zoomPoints{},
|
||||
histZooms: map[uint32]map[string]zoomPoints{},
|
||||
}
|
||||
|
||||
// ── 1. sources ────────────────────────────────────────────────────────
|
||||
@@ -409,6 +436,41 @@ func main() {
|
||||
return true
|
||||
})
|
||||
|
||||
// ── 5b. historyInfo — check the hub broadcast it on connect ─────────
|
||||
if c.historyInfo != nil && c.historyInfo.Enabled {
|
||||
log.Printf("OK historyInfo: enabled, %.1fh, decimation=%d, %d signals",
|
||||
c.historyInfo.DurationHours, c.historyInfo.Decimation,
|
||||
len(c.historyInfo.Signals))
|
||||
|
||||
// ── 5c. historyZoom round-trip ──────────────────────────────────
|
||||
const hReqID = 4243
|
||||
c.send(map[string]interface{}{
|
||||
"type": "historyZoom", "reqId": hReqID,
|
||||
"t0": t0, "t1": t1, "n": 200,
|
||||
"signals": zoomKey,
|
||||
})
|
||||
c.waitFor(fmt.Sprintf("historyZoom reply (reqId=%d, %s)", hReqID, zoomKey),
|
||||
10*time.Second, func() bool {
|
||||
sigs, ok := c.histZooms[hReqID]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
pts, ok := sigs[zoomKey]
|
||||
if !ok || len(pts.T) < 1 {
|
||||
// History data may still be sparse right after startup
|
||||
return true
|
||||
}
|
||||
for _, ht := range pts.T {
|
||||
if ht < t0-1e-6 || ht > t1+1e-6 {
|
||||
fail("historyZoom point outside range: t=%.9f not in [%.9f,%.9f]", ht, t0, t1)
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
log.Println(" (history not enabled — skipping historyZoom test)")
|
||||
}
|
||||
|
||||
// ── 6. trigger: arm → capture ────────────────────────────────────────
|
||||
// Trigger on an *oscillating* signal at its mean observed value: a
|
||||
// monotonic ramp (counter, time array) crosses its past mean only once,
|
||||
|
||||
Reference in New Issue
Block a user