Skip to content

Commit

Permalink
feat: improve speed calculation (after rate change) (#88)
Browse files Browse the repository at this point in the history
fixes #84
  • Loading branch information
jbrodriguez authored Apr 16, 2024
1 parent b00ad1e commit e13da30
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 161 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
fetch-tags: true

- name: set up go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: 1.22

- name: set up node
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 21.x
cache: "npm"
cache-dependency-path: "ui/package-lock.json"

Expand Down
1 change: 1 addition & 0 deletions daemon/services/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func (c *Core) SetVerbosity(value int) *domain.Config {

func (c *Core) SetRefreshRate(value int) *domain.Config {
c.ctx.Config.RefreshRate = value
c.resetSamples(c.state.Operation)
if err := c.saveSettings(); err != nil {
logger.Yellow("setRefreshRate: unable to save settings: %s", err)
}
Expand Down
13 changes: 13 additions & 0 deletions daemon/services/core/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,19 @@ func (c *Core) updateSamples(operation *domain.Operation, transferred uint64) {
operation.PrevSample = transferred
}

func (c *Core) resetSamples(operation *domain.Operation) {
if operation == nil {
return
}

for i := range operation.Samples {
operation.Samples[i] = 0
}

operation.SampleIndex = 0
operation.PrevSample = 0
}

func (c *Core) calculateSpeed(operation *domain.Operation, rate time.Duration) float64 {
var sum uint64
var countNonZero int
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module unbalance

go 1.21.4
go 1.22

require (
github.com/alecthomas/kong v0.8.1
Expand Down
Loading

0 comments on commit e13da30

Please sign in to comment.