Skip to content

Commit

Permalink
Graph visualization (#11)
Browse files Browse the repository at this point in the history
* add simple graph

* add node colors

* update lockfile

* Color detections

Co-authored-by: afmagee42 <[email protected]>

---------

Co-authored-by: afmagee42 <[email protected]>
  • Loading branch information
swo and afmagee42 authored Dec 17, 2024
1 parent 48bb870 commit fbe36b7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
24 changes: 20 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme = "README.md"
python = "^3.10"
numpy = "^2.2.0"
streamlit = "^1.41.0"
graphviz = "^0.20.3"


[tool.poetry.group.dev.dependencies]
Expand Down
24 changes: 24 additions & 0 deletions ringvax/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import graphviz
import streamlit as st

from ringvax import Simulation


def make_graph(sim: Simulation):
graph = graphviz.Digraph()
for infectee in sim.query_people():
infector = sim.get_person_property(infectee, "infector")

color = (
"black"
if not sim.get_person_property(infectee, "detected")
else "#068482"
)

graph.node(str(infectee), color=color)

if infector is not None:
graph.edge(str(infector), str(infectee))

return graph


def app():
st.title("Ring vaccination")

Expand Down Expand Up @@ -89,6 +109,10 @@ def app():
s = Simulation(params=params, seed=seed)
s.run()

st.header("Graph of infections")
st.graphviz_chart(make_graph(s))

st.header("Raw results")
for id, content in s.infections.items():
st.text(id)
st.text(content)
Expand Down

0 comments on commit fbe36b7

Please sign in to comment.