mirror of
https://github.com/ClusterCockpit/cc-metric-store.git
synced 2024-12-26 00:49:05 +01:00
fix: SimpleResampler fixed
This commit is contained in:
parent
bfeba8803d
commit
723200fabd
2
.gitignore
vendored
2
.gitignore
vendored
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
aditya.creds
|
aditya.creds
|
||||||
test.creds
|
test.creds
|
||||||
config.json
|
/config.json
|
||||||
|
|
||||||
migrateTimestamps.pl
|
migrateTimestamps.pl
|
||||||
test_ccms_api.sh
|
test_ccms_api.sh
|
||||||
|
@ -8,20 +8,20 @@ import (
|
|||||||
"github.com/ClusterCockpit/cc-metric-store/internal/util"
|
"github.com/ClusterCockpit/cc-metric-store/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SimpleResampler(data []util.Float, old_frequency int64, new_frequency int64) ([]util.Float, error) {
|
func SimpleResampler(data []util.Float, old_frequency int64, new_frequency int64) ([]util.Float, int64, error) {
|
||||||
if old_frequency == 0 || new_frequency == 0 || new_frequency <= old_frequency {
|
if old_frequency == 0 || new_frequency == 0 || new_frequency <= old_frequency {
|
||||||
return nil, errors.New("either old or new frequency is set to 0")
|
return data, old_frequency, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if new_frequency%old_frequency != 0 {
|
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 step int = int(new_frequency / old_frequency)
|
||||||
var new_data_length = len(data) / step
|
var new_data_length = len(data) / step
|
||||||
|
|
||||||
if new_data_length == 0 || len(data) < 100 || new_data_length >= len(data) {
|
if new_data_length == 0 || len(data) < 100 || new_data_length >= len(data) {
|
||||||
return data, nil
|
return data, old_frequency, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
new_data := make([]util.Float, new_data_length)
|
new_data := make([]util.Float, new_data_length)
|
||||||
@ -30,7 +30,7 @@ func SimpleResampler(data []util.Float, old_frequency int64, new_frequency int64
|
|||||||
new_data[i] = data[i*step]
|
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
|
// Inspired by one of the algorithms from https://skemman.is/bitstream/1946/15343/3/SS_MSthesis.pdf
|
||||||
|
Loading…
Reference in New Issue
Block a user