-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Preprocess Data #5
Comments
Interesting idea. The other two alternatives I see are:
But I do like the convinice your idea would bring |
Let's take the normalization on the latest value and assume to have N lines (e.g. different stocks) in the chart. Then I'd like to see all lines in the chart ending up to 100% allowing mapping functions sounds interessting |
I'm thinking of something like this: example of normalisation wrt to lasttype: custom:plotly-graph
entities:
- entity: sensor.my_sensor
lambda: |-
(ys) => ys.map(y => y/ys[ys.length-1]) example of normalisation wrt to first fetched value - entity: sensor.my_sensor
lambda: |-
(ys) => ys.map(y => y/ys[0]) So basically a js function that receives all the data for that entity, and you can do whatever you want. The problem is that the unit_of_measurement would also need to be tweakable. Here some more examples, including example of accumulated value - entity: sensor.my_sensor
unit_of_measurement: "total pulses"
lambda: |-
(ys) => {
let accumulator = 0;
return ys.map(y => accumulator + y)
} example of derivative - entity: sensor.my_sensor
unit_of_measurement: "pulses / second"
lambda: |-
(ys, xs) => {
let last = {
x: new Date(),
y: 0,
}
return ys.map((y, index) => {
const x = xs[index];
const dateDelta = x - last.x;
accumulator += (y - last.y) / dateDelta;
last = { x, y };
return accumulator;
})
} example of right hand riemann integration - entity: sensor.my_sensor
unit_of_measurement: "kWh"
lambda: |-
(ys, xs) => {
let accumulator = 0;
let last = {
x: new Date(),
y: 0,
}
return ys.map((y, index) => {
const x = xs[index]
const dateDelta = x - last.x;
accumulator += last.y * dateDelta;
last = { x, y };
return accumulator;
})
} What do you think? Regarding normalising against the first value, you should consider that the "first value" will be just the 1st known value, which will change if you scroll the plot and older data is fetched edit: changed variable names to x and y |
Looks great! |
Cool, then I'll give it a go tomorrow :) |
@lein1013 done in v0.5.0! |
Thanks for implementation! |
Would it be possible to enable a normaliz function on the data on the latest value? (or on the first/average value of the selected timeframe 1day, 1 week,..)
e.g. if you have a 5 stock charts with a large difference in their stock value, this would allow to compare the trends of the stocks
The text was updated successfully, but these errors were encountered: