diff --git a/CHANGELOG.md b/CHANGELOG.md index 2813d393..a1c76d5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Starting from v2.2.5, all notable changes to this project will be documented in this file. +## v2.12.3 + +- Format frontend code using ESLint and Prettier +- Use `time.Ticker` to collect geophone counts by second + ## v2.12.2 - Always use fallback locale if the preferred locale is not available diff --git a/VERSION b/VERSION index 6f9cc441..58cc4d41 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.12.2 +v2.12.3 diff --git a/feature/archiver/daemon.go b/feature/archiver/daemon.go index be76e15b..a47ba58e 100644 --- a/feature/archiver/daemon.go +++ b/feature/archiver/daemon.go @@ -45,6 +45,7 @@ func (a *Archiver) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou os.Exit(1) } options.Database = pdb + defer dao.Close(pdb) // Start cleanup routine if life cycle bigger than 0 lifeCycle := options.Config.MiniSEED.LifeCycle @@ -75,5 +76,4 @@ func (a *Archiver) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou // Wait for interrupt signals <-sigCh logger.Print(MODULE, "closing database connection", color.FgBlue, true) - dao.Close(pdb) } diff --git a/feature/geophone/callbacks.go b/feature/geophone/callbacks.go index a31ae997..0d564e16 100644 --- a/feature/geophone/callbacks.go +++ b/feature/geophone/callbacks.go @@ -2,7 +2,6 @@ package geophone import ( "github.com/anyshake/observer/feature" - "github.com/anyshake/observer/utils/duration" "github.com/anyshake/observer/utils/logger" "github.com/anyshake/observer/utils/text" "github.com/fatih/color" @@ -17,34 +16,18 @@ func (g *Geophone) OnStop(options *feature.FeatureOptions, v ...any) { } func (g *Geophone) OnReady(options *feature.FeatureOptions, v ...any) { + if len(v) == 0 { + logger.Print(MODULE, "1 full packet received", color.FgGreen, false) + return + } if !options.Status.ReadyTime.IsZero() { - var ( - packet = v[0].(Packet) - currentTime, _ = duration.Timestamp(options.Status.System.Offset) - ) - // Appending packet data to buffer + packet := v[0].(Packet) for i := 0; i < options.Config.Serial.Packet; i++ { options.Status.Buffer.EHZ = append(options.Status.Buffer.EHZ, packet.EHZ[i]) options.Status.Buffer.EHE = append(options.Status.Buffer.EHE, packet.EHE[i]) options.Status.Buffer.EHN = append(options.Status.Buffer.EHN, packet.EHN[i]) } - - // Archive approximately 1 second has passed - timeDiff := duration.Difference(currentTime, options.Status.LastRecvTime) - if timeDiff >= READY_THRESHOLD { - // Set packet timestamp, note that the timestamp in buffer is the start of the packet - options.Status.Buffer.TS = currentTime.UnixMilli() - timeDiff.Milliseconds() - // Set last received time is the current timestamp - options.Status.LastRecvTime = currentTime - options.Status.System.Messages++ - // Copy buffer and reset - options.Status.Geophone = *options.Status.Buffer - options.Status.Buffer.EHZ = []int32{} - options.Status.Buffer.EHE = []int32{} - options.Status.Buffer.EHN = []int32{} - logger.Print(MODULE, "1 full packet received", color.FgGreen, false) - } } else { logger.Print(MODULE, "waiting for time alignment", color.FgYellow, false) } diff --git a/feature/geophone/daemon.go b/feature/geophone/daemon.go index 1bc39302..dbfed11a 100644 --- a/feature/geophone/daemon.go +++ b/feature/geophone/daemon.go @@ -32,6 +32,9 @@ func (g *Geophone) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou } defer serial.Close(port) + g.Ticker = time.NewTicker(READY_THRESHOLD) + defer g.Ticker.Stop() + go func() { // Initialize geophone packet var packet Packet @@ -80,6 +83,24 @@ func (g *Geophone) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou } }() + go func() { + for { + <-g.Ticker.C + currentTime, _ := duration.Timestamp(options.Status.System.Offset) + // Set packet timestamp, note that the timestamp in buffer is the start of the packet + options.Status.Buffer.TS = currentTime.UnixMilli() - time.Second.Milliseconds() + // Set last received time is the current timestamp + options.Status.LastRecvTime = currentTime + options.Status.System.Messages++ + // Copy and reset buffer + options.Status.Geophone = *options.Status.Buffer + options.Status.Buffer.EHZ = []int32{} + options.Status.Buffer.EHE = []int32{} + options.Status.Buffer.EHN = []int32{} + g.OnReady(options) + } + }() + // Receive interrupt signals sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM) @@ -87,5 +108,4 @@ func (g *Geophone) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou // Wait for interrupt signals <-sigCh g.OnStop(options, "closing serial connection") - serial.Close(port) } diff --git a/feature/geophone/types.go b/feature/geophone/types.go index d964b50f..60aa253a 100644 --- a/feature/geophone/types.go +++ b/feature/geophone/types.go @@ -20,7 +20,9 @@ var ( ACK_WORD = [...]byte{0xFC, 0x2B} ) -type Geophone struct{} +type Geophone struct { + Ticker *time.Ticker +} type Packet struct { EHZ []int32 // Vertical diff --git a/feature/seedlink/daemon.go b/feature/seedlink/daemon.go index d35c6be5..84e3b9a5 100644 --- a/feature/seedlink/daemon.go +++ b/feature/seedlink/daemon.go @@ -50,6 +50,7 @@ func (s *SeedLink) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou s.OnError(options, err) return } + defer slGlobal.SeedLinkBuffer.Database.Close() // Accept incoming connections s.OnStart(options, "service has started") @@ -79,5 +80,4 @@ func (s *SeedLink) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou // Wait for interrupt signals <-sigCh logger.Print(MODULE, "closing buffer area", color.FgBlue, true) - slGlobal.SeedLinkBuffer.Database.Close() } diff --git a/frontend/dist/asset-manifest.json b/frontend/dist/asset-manifest.json index 298e4500..cfc3db9f 100644 --- a/frontend/dist/asset-manifest.json +++ b/frontend/dist/asset-manifest.json @@ -1,13 +1,13 @@ { "files": { "main.css": "./static/css/main.7a040865.css", - "main.js": "./static/js/main.c4da8e75.js", + "main.js": "./static/js/main.b9d5c092.js", "static/css/594.d6bfd15f.chunk.css": "./static/css/594.d6bfd15f.chunk.css", - "static/js/594.7755917b.chunk.js": "./static/js/594.7755917b.chunk.js", - "static/js/846.88ce4ddb.chunk.js": "./static/js/846.88ce4ddb.chunk.js", - "static/js/154.cebd5677.chunk.js": "./static/js/154.cebd5677.chunk.js", - "static/js/600.23a606ea.chunk.js": "./static/js/600.23a606ea.chunk.js", - "static/js/708.22872728.chunk.js": "./static/js/708.22872728.chunk.js", + "static/js/594.ccfa0385.chunk.js": "./static/js/594.ccfa0385.chunk.js", + "static/js/846.45094087.chunk.js": "./static/js/846.45094087.chunk.js", + "static/js/154.13af8e6a.chunk.js": "./static/js/154.13af8e6a.chunk.js", + "static/js/600.140630e8.chunk.js": "./static/js/600.140630e8.chunk.js", + "static/js/708.26ef62d2.chunk.js": "./static/js/708.26ef62d2.chunk.js", "static/js/699.e75d4402.chunk.js": "./static/js/699.e75d4402.chunk.js", "static/js/303.28dd2180.chunk.js": "./static/js/303.28dd2180.chunk.js", "static/js/548.b98bfbf6.chunk.js": "./static/js/548.b98bfbf6.chunk.js", @@ -49,6 +49,6 @@ }, "entrypoints": [ "static/css/main.7a040865.css", - "static/js/main.c4da8e75.js" + "static/js/main.b9d5c092.js" ] } \ No newline at end of file diff --git a/frontend/dist/index.html b/frontend/dist/index.html index f3348aa2..5a5d780e 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -1 +1 @@ -
- {item}
-
-
+ {item}
+
+
- {label} - | - ))} - {actions.map(({ label }) => ( -- {label} - | - ))} -
---|---|
- {columns - .filter( - ({ key }) => - key === - columns[_index] - .key - ) - .map( - ({ key }) => - item[key] - ) || _item} - | - ) - )} - {actions.map( - ({ icon, label, onClick }) => ( -{ - onClick && - onClick(item); - }} - > - - | - ) - )} -
+ {label} + | + ))} + {actions.map(({ label }) => ( ++ {label} + | + ))} +
---|---|
+ {columns + .filter( + ({ key }) => key === columns[_index].key + ) + .map(({ key }) => item[key]) || _item} + | + ))} + {actions.map(({ icon, label, onClick }) => ( +{ + onClick && onClick(item); + }} + > + + | + ))} +