feat(inputs.mock): Add baseline option to sine (#15270)
This commit is contained in:
parent
ae50801866
commit
ee9df0a2a6
|
|
@ -40,6 +40,7 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
# name = "wave"
|
# name = "wave"
|
||||||
# amplitude = 1.0
|
# amplitude = 1.0
|
||||||
# period = 0.5
|
# period = 0.5
|
||||||
|
# base_line = 0.0
|
||||||
# [[inputs.mock.step]]
|
# [[inputs.mock.step]]
|
||||||
# name = "plus_one"
|
# name = "plus_one"
|
||||||
# start = 0.0
|
# start = 0.0
|
||||||
|
|
@ -62,7 +63,7 @@ The available algorithms for generating mock data include:
|
||||||
* Constant - generate a field with the given value of type string, float, int
|
* Constant - generate a field with the given value of type string, float, int
|
||||||
or bool
|
or bool
|
||||||
* Random Float - generate a random float, inclusive of min and max
|
* Random Float - generate a random float, inclusive of min and max
|
||||||
* Sine Wave - produce a sine wave with a certain amplitude and period
|
* Sine Wave - produce a sine wave with a certain amplitude, period and baseline
|
||||||
* Step - always add the step value, negative values accepted
|
* Step - always add the step value, negative values accepted
|
||||||
* Stock - generate fake, stock-like price values based on a volatility variable
|
* Stock - generate fake, stock-like price values based on a volatility variable
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ type sineWave struct {
|
||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
Amplitude float64 `toml:"amplitude"`
|
Amplitude float64 `toml:"amplitude"`
|
||||||
Period float64 `toml:"period"`
|
Period float64 `toml:"period"`
|
||||||
|
BaseLine float64 `toml:"base_line"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type step struct {
|
type step struct {
|
||||||
|
|
@ -117,7 +118,7 @@ func (m *Mock) generateRandomFloat64(fields map[string]interface{}) {
|
||||||
// Create sine waves
|
// Create sine waves
|
||||||
func (m *Mock) generateSineWave(fields map[string]interface{}) {
|
func (m *Mock) generateSineWave(fields map[string]interface{}) {
|
||||||
for _, field := range m.SineWave {
|
for _, field := range m.SineWave {
|
||||||
fields[field.Name] = math.Sin(float64(m.counter)*field.Period*math.Pi) * field.Amplitude
|
fields[field.Name] = math.Sin(float64(m.counter)*field.Period*math.Pi)*field.Amplitude + field.BaseLine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ func TestGather(t *testing.T) {
|
||||||
Name: "sine",
|
Name: "sine",
|
||||||
Amplitude: 1.0,
|
Amplitude: 1.0,
|
||||||
Period: 0.5,
|
Period: 0.5,
|
||||||
|
BaseLine: 2.0,
|
||||||
}
|
}
|
||||||
testStep := &step{
|
testStep := &step{
|
||||||
Name: "step",
|
Name: "step",
|
||||||
|
|
@ -87,7 +88,7 @@ func TestGather(t *testing.T) {
|
||||||
require.GreaterOrEqual(t, 6.0, v)
|
require.GreaterOrEqual(t, 6.0, v)
|
||||||
require.LessOrEqual(t, 1.0, v)
|
require.LessOrEqual(t, 1.0, v)
|
||||||
case "sine":
|
case "sine":
|
||||||
require.Equal(t, 0.0, v)
|
require.Equal(t, 2.0, v)
|
||||||
case "step":
|
case "step":
|
||||||
require.Equal(t, 0.0, v)
|
require.Equal(t, 0.0, v)
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
# name = "wave"
|
# name = "wave"
|
||||||
# amplitude = 1.0
|
# amplitude = 1.0
|
||||||
# period = 0.5
|
# period = 0.5
|
||||||
|
# base_line = 0.0
|
||||||
# [[inputs.mock.step]]
|
# [[inputs.mock.step]]
|
||||||
# name = "plus_one"
|
# name = "plus_one"
|
||||||
# start = 0.0
|
# start = 0.0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue