flojoy-ai / nodes

Plug & play nodes for the Flojoy visual scripting platform
https://docs.flojoy.io/custom-nodes/creating-custom-node/
MIT License
13 stars 7 forks source link

Timeseries node cannot be plotted with LINE node #96

Open Ben-Epstein opened 1 year ago

Ben-Epstein commented 1 year ago

Given this flow

flojoy.txt

After being executed, the timeseries plot won't load.

image

I took the dc_input from the LINE node of the timeseries, and saved it to disk. I loaded it in jupyter and the plot rendered just fine, both using px.express and px.graph_object

image image

Not sure why the UI can't render the timeseries plot, but it has something to do with the x being timeseries data. If I replace it with None or np.random.rand in the TIMESERIES node code, it renders as expected

jackparmer commented 1 year ago

Hmm, yeah, TIMESERIES and LINE are both early era nodes that haven't been updated in a while.

The solution that I would recommend:

  1. The TIMESERIES generator is updated to output a DataContainer of type timeseries, which we define as a Pandas dataframe with an index of type DatetimeIndex (see, https://jakevdp.github.io/PythonDataScienceHandbook/03.11-working-with-time-series.html)

https://github.com/flojoy-io/nodes/blob/main/GENERATORS/SIMULATIONS/TIMESERIES/TIMESERIES.py

  1. LINE is updated to recognize the timeseries DataContainer type, and make sure that the DatetimeIndex is correctly converted to plotly's preferred string format for dates (' YYYY-MM-DD hh:mm:ss '). IIRC both pandas and plotly should be capable of nanosecond precision but worth testing: https://pandas.pydata.org/docs/reference/api/pandas.DatetimeIndex.nanosecond.html

https://github.com/flojoy-io/nodes/blob/main/VISUALIZERS/PLOTLY/LINE/LINE.py#L16