From 1fe3bd65741b66cd81e01f256378ea8dfbe40609 Mon Sep 17 00:00:00 2001 From: Chengxun Lee <24319042+bclswl0827@users.noreply.github.com> Date: Sat, 4 May 2024 14:16:28 +0800 Subject: [PATCH] Use `time.Ticker` to collect geophone counts by second --- CHANGELOG.md | 5 + VERSION | 2 +- feature/archiver/daemon.go | 2 +- feature/geophone/callbacks.go | 27 +- feature/geophone/daemon.go | 22 +- feature/geophone/types.go | 4 +- feature/seedlink/daemon.go | 2 +- frontend/dist/asset-manifest.json | 14 +- frontend/dist/index.html | 2 +- frontend/dist/static/js/154.13af8e6a.chunk.js | 1 + frontend/dist/static/js/154.cebd5677.chunk.js | 1 - frontend/dist/static/js/594.7755917b.chunk.js | 1 - frontend/dist/static/js/594.ccfa0385.chunk.js | 1 + frontend/dist/static/js/600.140630e8.chunk.js | 1 + frontend/dist/static/js/600.23a606ea.chunk.js | 1 - frontend/dist/static/js/708.22872728.chunk.js | 1 - frontend/dist/static/js/708.26ef62d2.chunk.js | 1 + ...8ce4ddb.chunk.js => 846.45094087.chunk.js} | 2 +- frontend/dist/static/js/main.b9d5c092.js | 2 + ...CENSE.txt => main.b9d5c092.js.LICENSE.txt} | 0 frontend/dist/static/js/main.c4da8e75.js | 2 - frontend/src/.env | 4 +- frontend/src/.eslintrc | 30 + frontend/src/.prettierignore | 3 + frontend/src/craco.config.js | 1 - frontend/src/package-lock.json | 549 +++++++- frontend/src/package.json | 17 +- frontend/src/prettier.config.js | 14 + frontend/src/src/App.tsx | 253 ++-- frontend/src/src/components/Banner.tsx | 110 +- frontend/src/src/components/Button.tsx | 30 +- frontend/src/src/components/Chart.tsx | 273 ++-- frontend/src/src/components/Code.tsx | 115 +- frontend/src/src/components/Container.tsx | 44 +- frontend/src/src/components/Footer.tsx | 51 +- frontend/src/src/components/Form.tsx | 193 ++- frontend/src/src/components/Header.tsx | 65 +- frontend/src/src/components/Holder.tsx | 156 +-- frontend/src/src/components/Input.tsx | 94 +- frontend/src/src/components/Label.tsx | 86 +- frontend/src/src/components/MapBox.tsx | 120 +- frontend/src/src/components/Navbar.tsx | 62 +- frontend/src/src/components/Panel.tsx | 46 +- frontend/src/src/components/Progress.tsx | 61 +- frontend/src/src/components/RouterView.tsx | 37 +- frontend/src/src/components/RouterWrapper.tsx | 19 +- frontend/src/src/components/Scroller.tsx | 53 +- frontend/src/src/components/Select.tsx | 122 +- frontend/src/src/components/Sidebar.tsx | 143 +- frontend/src/src/components/Skeleton.tsx | 40 +- frontend/src/src/components/Table.tsx | 219 ++-- frontend/src/src/components/TimePicker.tsx | 131 +- frontend/src/src/config/api.tsx | 265 ++-- frontend/src/src/config/global.tsx | 90 +- frontend/src/src/config/i18n.tsx | 31 +- frontend/src/src/config/menu.tsx | 102 +- frontend/src/src/config/router.tsx | 165 ++- frontend/src/src/config/store.tsx | 68 +- frontend/src/src/custom.d.ts | 4 +- frontend/src/src/helpers/app/getAsciiArt.tsx | 4 +- frontend/src/src/helpers/app/getProtocol.tsx | 20 +- frontend/src/src/helpers/app/getRelease.tsx | 2 +- frontend/src/src/helpers/app/getVersion.tsx | 2 +- frontend/src/src/helpers/hook/useInterval.tsx | 51 +- frontend/src/src/helpers/hook/useSocket.tsx | 107 +- frontend/src/src/helpers/i18n/createI18n.tsx | 40 +- .../src/src/helpers/i18n/getCurrentLocale.tsx | 9 +- .../src/src/helpers/i18n/setUserLocale.tsx | 7 +- .../src/helpers/interact/sendPromiseAlert.tsx | 40 +- .../src/helpers/interact/sendUserAlert.tsx | 16 +- .../src/helpers/interact/sendUserConfirm.tsx | 112 +- .../src/src/helpers/request/connectSocket.tsx | 60 +- .../src/helpers/request/requestRestApi.tsx | 165 ++- .../helpers/seismic/getAccelerationArr.tsx | 23 +- .../src/helpers/seismic/getFilteredCounts.tsx | 62 +- .../src/helpers/seismic/getVelocityArr.tsx | 10 +- .../src/src/helpers/seismic/getVoltageArr.tsx | 18 +- .../src/helpers/seismic/intensityStandard.tsx | 240 ++-- .../src/src/helpers/utils/getDayOfYear.tsx | 8 +- .../src/src/helpers/utils/getTimeString.tsx | 4 +- .../src/helpers/utils/setClipboardText.tsx | 30 +- .../src/src/helpers/utils/userThrottle.tsx | 21 +- frontend/src/src/index.tsx | 35 +- frontend/src/src/stores/adc.tsx | 22 +- frontend/src/src/stores/duration.tsx | 25 +- frontend/src/src/stores/geophone.tsx | 28 +- frontend/src/src/stores/retention.tsx | 25 +- frontend/src/src/stores/scale.tsx | 17 +- frontend/src/src/stores/station.tsx | 32 +- .../src/views/Export/getExportsUpdates.tsx | 28 +- .../src/src/views/Export/handleSetTable.tsx | 35 +- frontend/src/src/views/Export/index.tsx | 275 ++-- .../src/src/views/History/getSACFileName.tsx | 41 +- .../src/src/views/History/handleSetCharts.tsx | 165 ++- .../src/src/views/History/handleSetLabels.tsx | 103 +- frontend/src/src/views/History/index.tsx | 1165 ++++++++--------- .../src/src/views/Home/getStationUpdates.tsx | 26 +- .../src/src/views/Home/handleSetBanner.tsx | 57 +- .../src/src/views/Home/handleSetCharts.tsx | 109 +- .../src/src/views/Home/handleSetLabels.tsx | 33 +- frontend/src/src/views/Home/handleSetMap.tsx | 61 +- frontend/src/src/views/Home/index.tsx | 302 +++-- frontend/src/src/views/NotFound.tsx | 18 +- .../src/views/Realtime/getSocketUpdates.tsx | 13 +- .../src/views/Realtime/handleSetBanner.tsx | 56 +- .../src/views/Realtime/handleSetCharts.tsx | 237 ++-- frontend/src/src/views/Realtime/index.tsx | 499 ++++--- frontend/src/src/views/Setting/index.tsx | 484 ++++--- frontend/src/tsconfig.json | 42 +- publisher/subscribe.go | 2 +- 110 files changed, 4557 insertions(+), 4389 deletions(-) create mode 100644 frontend/dist/static/js/154.13af8e6a.chunk.js delete mode 100644 frontend/dist/static/js/154.cebd5677.chunk.js delete mode 100644 frontend/dist/static/js/594.7755917b.chunk.js create mode 100644 frontend/dist/static/js/594.ccfa0385.chunk.js create mode 100644 frontend/dist/static/js/600.140630e8.chunk.js delete mode 100644 frontend/dist/static/js/600.23a606ea.chunk.js delete mode 100644 frontend/dist/static/js/708.22872728.chunk.js create mode 100644 frontend/dist/static/js/708.26ef62d2.chunk.js rename frontend/dist/static/js/{846.88ce4ddb.chunk.js => 846.45094087.chunk.js} (57%) create mode 100644 frontend/dist/static/js/main.b9d5c092.js rename frontend/dist/static/js/{main.c4da8e75.js.LICENSE.txt => main.b9d5c092.js.LICENSE.txt} (100%) delete mode 100644 frontend/dist/static/js/main.c4da8e75.js create mode 100644 frontend/src/.eslintrc create mode 100644 frontend/src/.prettierignore delete mode 100644 frontend/src/craco.config.js create mode 100644 frontend/src/prettier.config.js 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); + }} + > + + | + ))} +