Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified parallel structure #57

Merged
merged 43 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5969b4d
add docstrings and annotations
Apr 8, 2024
9a368cc
debug
Apr 8, 2024
3d9ab79
debugging
Apr 8, 2024
0724613
swap from try/except; enhance verbosity
Apr 8, 2024
14e2a55
explain locality
Apr 8, 2024
babf1ac
simplify main runner
Apr 8, 2024
07d5984
Update src/tqdm_publisher/_demos/_parallel_bars/_server.py
CodyCBakerPhD Apr 8, 2024
d4be732
GF updates
garrettmflynn Apr 8, 2024
1d90a0e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 8, 2024
44dd169
Update _handler.py
garrettmflynn Apr 8, 2024
06c701b
Merge branch 'doc_improvements' of https://github.com/catalystneuro/t…
garrettmflynn Apr 8, 2024
b6b5ea5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 8, 2024
27afa89
Show as much metadata as possible from format_dict
garrettmflynn Apr 8, 2024
9079b18
Merge branch 'doc_improvements' into metadata-visualization-improvement
garrettmflynn Apr 8, 2024
4cb2b06
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 8, 2024
920ad34
add docs and simplify logic
CodyCBakerPhD Apr 9, 2024
54f4950
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 9, 2024
65b5ef1
Merge branch 'main' into doc_improvements
CodyCBakerPhD Apr 9, 2024
f634c4f
Merge branch 'doc_improvements' into metadata-visualization-improvement
CodyCBakerPhD Apr 9, 2024
b501b3e
Update _server.py
garrettmflynn Apr 9, 2024
c474dfa
Update _server.py
garrettmflynn Apr 9, 2024
8058bdb
Update _server.py
garrettmflynn Apr 9, 2024
91857a3
change to public method and enhance docstring
CodyCBakerPhD Apr 10, 2024
81e34ad
simplify logic
CodyCBakerPhD Apr 10, 2024
2443e87
Fix id references
garrettmflynn Apr 10, 2024
0106b58
Update _server.py
garrettmflynn Apr 10, 2024
9240235
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 10, 2024
0d4341f
Merge branch 'doc_improvements' into metadata-visualization-improvement
garrettmflynn Apr 10, 2024
788b784
Update elements.js
garrettmflynn Apr 10, 2024
19a7886
Fix client
garrettmflynn Apr 10, 2024
add05c6
Merge branch 'doc_improvements' into metadata-visualization-improvement
garrettmflynn Apr 10, 2024
1b26552
Remove WS demo for parallel demos
garrettmflynn Apr 10, 2024
1e5b039
Merge branch 'main' into metadata-visualization-improvement
garrettmflynn Apr 10, 2024
7627082
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 10, 2024
3857508
Request initial state immediately
garrettmflynn Apr 13, 2024
4594d38
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 13, 2024
95a3c27
Update elements.js
garrettmflynn Apr 14, 2024
03a2259
Merge branch 'metadata-visualization-improvement' of https://github.c…
garrettmflynn Apr 14, 2024
34a51eb
Update elements.js
garrettmflynn Apr 14, 2024
d167e49
Simplified parallel structure
garrettmflynn Apr 15, 2024
49f828b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 15, 2024
54734ca
Update _server.py
garrettmflynn Apr 16, 2024
db58fa0
Merge branch 'main' into simplified-parallel-structure
garrettmflynn Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 65 additions & 13 deletions src/tqdm_publisher/_demos/_client.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
* {
box-sizing: border-box;
}

html, body {
font-family: sans-serif;
box-sizing: border-box;
}

h1 {
Expand All @@ -10,49 +12,99 @@ h1 {
font-size: 1.5rem;
}

h2 {
margin: 0;
padding: 0;
font-size: 1.2rem;
}

header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 0px;
}

body > header {
padding: 20px;
}


#bars {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
flex-wrap: wrap;
padding: 0px 20px;
}

.progress {
.request-container {
width: 100%;
height: 20px;
background-color: #ddd;
box-sizing: border-box;
}

.progress div {
height: 100%;
background-color: #4caf50;
width: 0%;
.bar {
padding: 10px;
}

.progress[data-small="true"] {
height: 10px;
.bar, .progress {
width: 100%;
}

/* Small Bar */
.bar[data-small="true"] {
border-bottom: 1px solid gainsboro;
}

.progress[data-small="true"]:last-child {
.bar > div {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
}


.bar[data-small="true"] .progress {
height: 10px;
}

.bar[data-small="true"] .progress:last-child {
border-bottom: none;
}

.progress[data-small="false"] {
/* Large Bar */
.bar[data-small="false"] {
border-bottom: 1px solid black;
}

.bar[data-small="false"] .progress {
padding: 4px;
}

.progress {
height: 20px;
background-color: #ddd;
}

.progress div {
height: 100%;
background-color: #4caf50;
width: 0%;
}


.bar-container {
border: 1px solid black;
}

small {
font-size: 0.7rem;
color: gray;
width: min-content;
white-space: nowrap;
}

.bar > div:last-child > small:not(:empty) {
font-size: 0.65rem;
margin-top: 5px;
}
4 changes: 0 additions & 4 deletions src/tqdm_publisher/_demos/_demo_command_line_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

from tqdm_publisher._demos._multiple_bars._server import run_multiple_bar_demo
from tqdm_publisher._demos._parallel_bars._server import run_parallel_bar_demo
from tqdm_publisher._demos._parallel_bars._server_ws import (
run_parallel_bar_demo as run_parallel_bar_demo_ws,
)
from tqdm_publisher._demos._single_bar._server import run_single_bar_demo

CLIENT_PORT = 1234
Expand All @@ -17,7 +14,6 @@
"demo_single": dict(subpath="_single_bar", server=run_single_bar_demo),
"demo_multiple": dict(subpath="_multiple_bars", server=run_multiple_bar_demo),
"demo_parallel": dict(subpath="_parallel_bars", server=run_parallel_bar_demo),
"demo_parallel_ws": dict(subpath="_parallel_bars", server=run_parallel_bar_demo_ws),
}

DEMO_BASE_FOLDER_PATH = Path(__file__).parent
Expand Down
4 changes: 3 additions & 1 deletion src/tqdm_publisher/_demos/_multiple_bars/_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const bars = {} // Track progress bars
// Update the specified progress bar when a message is received from the server
const onProgressUpdate = (event) => {
const { request_id, format_dict } = JSON.parse(event.data);
bars[request_id].style.width = 100 * (format_dict.n / format_dict.total) + '%';
const { update } = bars[request_id];
update(format_dict);

}

// Create a new WebSocket client
Expand Down
45 changes: 3 additions & 42 deletions src/tqdm_publisher/_demos/_parallel_bars/_client.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,15 @@
import { EventSourceManager } from '../utils/EventSourceManager.js';
import { WebSocketManager } from '../utils/WebSocketManager.js';
import { createProgressBar } from '../utils/elements.js';
import { getBar } from '../utils/elements.js';

const bars = {} // Track progress bars
const requests = {} // Track request containers

function getRequestContainer(request_id) {
const existing = requests[request_id]
if (existing) return existing;

// Create a new container for the progress bar
const container = document.createElement('div');
container.id = request_id;
container.classList.add('request-container');
const h2 = document.createElement('h2');
h2.innerText = `Request ID: ${request_id}`;
container.append(h2);
document.body.append(container);
const barContainer = document.createElement('div');
barContainer.classList.add('bar-container');
container.append(barContainer);
requests[request_id] = barContainer;

return barContainer;
}

// Create and/or render a progress bar
const getBar = (request_id, id) => {

if (bars[id]) return bars[id];

const container = getRequestContainer(request_id);
const bar = createProgressBar(container);

bar.parentElement.setAttribute('data-small', request_id !== id); // Add a small style to the progress bar if it is not the main request bar

return bars[id] = bar;

}

// Update the specified progress bar when a message is received from the server
const onProgressUpdate = (event) => {
const { request_id, progress_bar_id, format_dict } = JSON.parse(event.data);
const bar = getBar(request_id, progress_bar_id);
bar.style.width = 100 * (format_dict.n / format_dict.total) + '%';
const { update } = getBar(request_id, progress_bar_id);
update(format_dict, { request_id, progress_bar_id });
}

// Create a new message client
const wsClient = new WebSocketManager({ onmessage: onProgressUpdate }, 3);
const client = new EventSourceManager({ onmessage: onProgressUpdate });

// Declare that the HTML Button should create a new progress bar when clicked
Expand All @@ -56,5 +18,4 @@ button.addEventListener('click', async () => {
const request_id = Math.random().toString(36).substring(7); // Create a unique ID for the progress bar
getBar(request_id, request_id); // Create a bar specifically for this request
await client.send({ command: 'start', request_id }).catch(() => {}); // Send a message to the server to start the progress bar
wsClient.send({ command: 'start', request_id }); // Send a message to the server to start the progress bar
})
62 changes: 0 additions & 62 deletions src/tqdm_publisher/_demos/_parallel_bars/_client.py

This file was deleted.

Loading
Loading