Skip to content

Commit

Permalink
Merge branch 'master' into hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
moebiusband73 committed Dec 5, 2024
2 parents 051cc83 + 42e8e37 commit e4d12e3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/resampler/resampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import (
"github.com/ClusterCockpit/cc-backend/pkg/schema"
)

func SimpleResampler(data []schema.Float, old_frequency int64, new_frequency int64) ([]schema.Float, error) {
if old_frequency == 0 || new_frequency == 0 {
return nil, errors.New("either old or new frequency is set to 0")
func SimpleResampler(data []schema.Float, old_frequency int64, new_frequency int64) ([]schema.Float, int64, error) {
if old_frequency == 0 || new_frequency == 0 || new_frequency <= old_frequency {
return data, old_frequency, nil
}

if new_frequency%old_frequency != 0 {
return nil, errors.New("new sampling frequency should be multiple of the old frequency")
return nil, 0, errors.New("new sampling frequency should be multiple of the old frequency")
}

var step int = int(new_frequency / old_frequency)
var new_data_length = len(data) / step

if new_data_length == 0 || len(data) < 100 || new_data_length >= len(data) {
return data, nil
return data, old_frequency, nil
}

new_data := make([]schema.Float, new_data_length)
Expand All @@ -30,14 +30,14 @@ func SimpleResampler(data []schema.Float, old_frequency int64, new_frequency int
new_data[i] = data[i*step]
}

return new_data, nil
return new_data, new_frequency, nil
}

// Inspired by one of the algorithms from https://skemman.is/bitstream/1946/15343/3/SS_MSthesis.pdf
// Adapted from https://github.com/haoel/downsampling/blob/master/core/lttb.go
func LargestTriangleThreeBucket(data []schema.Float, old_frequency int, new_frequency int) ([]schema.Float, int, error) {

if old_frequency == 0 || new_frequency == 0 {
if old_frequency == 0 || new_frequency == 0 || new_frequency <= old_frequency {
return data, old_frequency, nil
}

Expand Down

0 comments on commit e4d12e3

Please sign in to comment.