Giter Club home page Giter Club logo

Comments (7)

dbuezas avatar dbuezas commented on May 22, 2024 1

I'm thinking of something like this:

example of normalisation wrt to last

type: 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 unit_of_measurement (to show along the y axis and in the tooltips).

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

from lovelace-plotly-graph-card.

dbuezas avatar dbuezas commented on May 22, 2024 1

Cool, then I'll give it a go tomorrow :)
Thanks for the cool ideas!
I use my own hardcoded "hacked" version to do things like these.
With your feedback, I think we nailed a configurable way 👍

from lovelace-plotly-graph-card.

lein1013 avatar lein1013 commented on May 22, 2024 1

Thanks for implementation!
Works as specified :-)

from lovelace-plotly-graph-card.

dbuezas avatar dbuezas commented on May 22, 2024

Interesting idea.
Can you post examples as you imagine the configuration would look like?

The other two alternatives I see are:

  • To guide people towards the statistics sensor
  • To allow for an arbitrary JavaScript mapping function

But I do like the convinice your idea would bring

from lovelace-plotly-graph-card.

lein1013 avatar lein1013 commented on May 22, 2024

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%
n=1,..,N
values[n][:] = values[n][:]/values[n][-1]
by that kind of normalizsation you can see the trend of the stocks, independent from the selected timeframe (4h, 1d, 1w)
alternatively we can also normalize with the first value (values[n][:]/values[n][0]), then we see the trend based on the selected timeframe -> how much percent did the stock perform better than the other one

allowing mapping functions sounds interessting

from lovelace-plotly-graph-card.

lein1013 avatar lein1013 commented on May 22, 2024

Looks great!
With these examples, it looks like a real nice playground to experiment with visualisations directly in the lovelace config!

from lovelace-plotly-graph-card.

dbuezas avatar dbuezas commented on May 22, 2024

@lein1013 done in v0.5.0!
try it out and let me know if it works as you needed :)

from lovelace-plotly-graph-card.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.