I have a listener which is constantly logging received messages in the following way --
class Listener:
recorded = defaultdict(lambda: defaultdict(list))
def on_message_received(self, msg):
self.recorded[msg.id]["timestamp"].append(msg.timestamp)
self.recorded[msg.id]["data"].append(msg.data)
It can be assumed both the timestamp and data are floats.
For a single id, I can plot the data with --
import altair as alt
import pandas as pd
import streamlit as st
listener = Listener()
plt, frame = st.empty(), st.empty()
def plot():
c = listener.recorded.copy()
df = pd.DataFrame.from_dict(c[100]) # using id: 100 as an example
chart = alt.Chart(df).mark_line().encode(x="timestamp", y="data")
frame.write(df)
plt.altair_chart(chart)
Which produces a dataframe and plot of:
So my question is, how would I back up a level and generate a dataframe/plot from the dictionary listener.recorded
so that each unique id is plotting correctly with a legend? I cannot seem to quite get there on my own...