oceanprotocol / pdr-backend

Instructions & code to run predictoors, traders, more.
Apache License 2.0
24 stars 17 forks source link

[Sim] Output sim_engine plots -> streamlit/plotly -> webapp #749

Closed trentmc closed 3 months ago

trentmc commented 4 months ago

Background / motivation

We're on a path to output predictoor analytics plots to webapp, using streamlit + plotly.

Currently the sim engine plots are output on-the-fly directly to the desktop using matplotlib defaults. They're not going to the browser. This was a fine enough starting point.

But there are issues:

The solution: use streamlit.

That will address the issues above, and, a bonus: it helps us prototype for the analytics dapp. (We could even have them all in the same dapp. Pros and cons to this, decision is still TBD.)

Pre-requisites

TODO

Resources

Key ref: https://plotly.com/python/creating-and-updating-figures/

Maybe useful: https://github.com/Paulescu/real-time-data-pipelines-in-python/tree/main

idiom-bytes commented 4 months ago

How to organize all of this towards updating plots in a backend process + serving this via FE webapp

process 1 - etl.py - fetch + etl + update plots
process 2 - sim.py - running sim + updating plots
process 3 - streamlit frontend w/ different pages serving data + artifacts
> page a - predictoor net income
> page b - sim
trentmc commented 4 months ago

process 1 - etl.py - fetch + etl + update plots

This can run as part of sim_engine.py, as it does now. No need to make things more complicated. KISS.

Also: page a & b should be switched. It's the order that the user does things.

And: it shouldn't be "predictoor net income", it should be "predictoor", where net income is the top level metric.

Therefore, how I see it:

process 1 - sim.py - running sim + updating plots
process 2 - streamlit frontend w/ different pages serving data + artifacts
> page 1 - sim
> page 2 - predictoor
trentmc commented 4 months ago

@calina-c fyi I have completed the pre-requisite (refactor sim plot code)

idiom-bytes commented 3 months ago

There is a fork that we have to decide on:

Options:

trentmc commented 3 months ago

We want interactive.

It's ok to move away from matplotlib interface.

calina-c commented 3 months ago

Current behaviour:

Possible streamlit approaches

1. Streamlit using the matplotlib generated subplots

Advantages:

Downsides:

2. Streamlit using its native interface

Advantages:

Disadvantages:

Samples:

https://github.com/oceanprotocol/pdr-backend/assets/4101015/96579e90-0ebd-4405-9ea9-be58bb822bfd

https://github.com/oceanprotocol/pdr-backend/assets/4101015/f31fb54a-288a-4a85-9421-81648acc5b4f

My recommendation

Oh, just one more thing...

(to quote Peter Falk's well-known character)

To run with streamlit, we need to modify commands, i.e. we can not run just pdr. For sim, it would be streamlit run pdr -- sim my_ppss.yaml instead of pdr sim my_ppss.yaml. Is that an issue? I couldn't find another way to start the streamlit server.

trentmc commented 3 months ago

keep matplotlib figures for now and rework them piecemeal later, converting each plot to a native streamlit plot, as we go. It will prevent conflict resolution issues and it's still an improvement to real-time display and the canvas itself.

Sounds good to me

trentmc commented 3 months ago

To run with streamlit, we need to modify commands, i.e. we can not run just pdr. For sim, it would be streamlit run pdr -- sim my_ppss.yaml instead of pdr sim my_ppss.yaml. Is that an issue? I couldn't find another way to start the streamlit server.

That hurts ux for perhaps the most commonly-called command.

Let's think about ways where can we can preserve pdr run __. Eg maybe right after installation, the user defines a bash-level alias mapping "pdr" -> "streamlit run pdr"?

calina-c commented 3 months ago

To run with streamlit, we need to modify commands, i.e. we can not run just pdr. For sim, it would be streamlit run pdr -- sim my_ppss.yaml instead of pdr sim my_ppss.yaml. Is that an issue? I couldn't find another way to start the streamlit server.

That hurts ux for perhaps the most commonly-called command.

I was thinking about that, yes. That's why I thought to ask.

But we can't alias every pdr run, because not all commands need streamlit. Plus, streamlit opens a port and runs the server. Users should take note of that and how to close/kill those processes when they finish using them.

I will check if I can mimic the functionality of streamlit run inside pdr-backend, if possible. I will also look into some sort of aliasing, but if possible just for sim.

idiom-bytes commented 3 months ago

I have moved the discussions around altair and plotly from here, to this other ticket. https://github.com/oceanprotocol/pdr-backend/issues/842

This will enable us to close this ticket and move forward with the altair/plotly discussions separately.