Skip to content

Commit 193a085

Browse files
committed
Added support of jupytext. Saved sandbox notebook as .py file.
1 parent 85e0d0d commit 193a085

File tree

5 files changed

+31
-58
lines changed

5 files changed

+31
-58
lines changed

jupytext.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
formats = "ipynb,py:percent"

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
ipycanvas
2-
ipykernel
2+
ipykernel
3+
jupytext

src/main.ipynb

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/sandbox_notebook.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ---
2+
# jupyter:
3+
# jupytext:
4+
# formats: ipynb,py:percent
5+
# text_representation:
6+
# extension: .py
7+
# format_name: percent
8+
# format_version: '1.3'
9+
# jupytext_version: 1.13.8
10+
# kernelspec:
11+
# display_name: .venv
12+
# language: python
13+
# name: .venv
14+
# ---
15+
16+
# %% pycharm={"name": "#%%\n"}
17+
from viz.main import run
18+
from ipycanvas import MultiCanvas
19+
20+
canvas = MultiCanvas(4, width=800, height=600)
21+
display(canvas)
22+
run(3, 5, canvas[0], canvas[1], canvas[2])

src/viz/main.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from ipycanvas import hold_canvas
44

5-
from algorithms.single_client_total_replication import SingleClientTotalReplication
5+
from algorithms.single_client_versioned_majority import SingleClientVersionedMajority
66
from engine.client import ClientFactory, Client, ClientType
77
from engine.consistency_checker import ConsistencyChecker
88
from engine.gateway import Gateway
@@ -19,7 +19,7 @@ def run(client_count, nodes_count, background, nodes_layer, signals_layer):
1919
ratio = int(simulator_timer_interval // draw_timer_interval)
2020

2121
gateway = Gateway(server_id="gateway", timer=Timer())
22-
node_factory = NodeFactory(SingleClientTotalReplication, gateway)
22+
node_factory = NodeFactory(SingleClientVersionedMajority, gateway)
2323
client_factory = ClientFactory(gateway)
2424

2525
nodes = []
@@ -28,7 +28,7 @@ def run(client_count, nodes_count, background, nodes_layer, signals_layer):
2828

2929
clients = []
3030
for i in range(0, client_count):
31-
clients.append(client_factory.add_client(client_type=ClientType.Write))
31+
clients.append(client_factory.add_client())
3232

3333
simulator = SimulatorLoop(
3434
timer=Timer(),
@@ -66,10 +66,7 @@ def draw_signals(object_positions, signals, draw_progress, canvas):
6666
# This will not work with both clients and nodes
6767
# canvas.translate(canvas.width // 2, canvas.height // 4)
6868
for s in signals:
69-
if (
70-
s.from_node not in object_positions
71-
or s.to_node not in object_positions
72-
):
69+
if s.from_node not in object_positions or s.to_node not in object_positions:
7370
continue
7471
draw_signal(
7572
canvas,
@@ -87,15 +84,11 @@ def draw_nodes(clients, nodes, gateway, canvas):
8784
object_positions = {}
8885

8986
for idx, c in enumerate(clients):
90-
object_positions[c.id] = draw_client(
91-
canvas, idx, c.id, len(clients)
92-
)
87+
object_positions[c.id] = draw_client(canvas, idx, c.id, len(clients))
9388
object_positions[gateway.id] = draw_gateway(canvas)
9489

9590
# canvas.translate(canvas.width // 2, canvas.height // 4)
9691
center = (canvas.width // 2, canvas.height // 4)
9792
for idx, n in enumerate(nodes):
98-
object_positions[n.id] = draw_node(
99-
canvas, center, idx, n.id, len(nodes)
100-
)
93+
object_positions[n.id] = draw_node(canvas, center, idx, n.id, len(nodes))
10194
return object_positions

0 commit comments

Comments
 (0)