|
54 | 54 | padding: 6px 12px; |
55 | 55 | font-size: 14px; |
56 | 56 | } |
57 | | - @keyframes pulse { |
58 | | - 0% { |
59 | | - box-shadow: 0 0 0 0 rgba(0, 123, 255, 0.7); |
60 | | - } |
61 | | - 70% { |
62 | | - box-shadow: 0 0 0 10px rgba(0, 123, 255, 0); |
63 | | - } |
64 | | - 100% { |
65 | | - box-shadow: 0 0 0 0 rgba(0, 123, 255, 0); |
66 | | - } |
| 57 | + #loader { |
| 58 | + display: none; |
| 59 | + width: 15px; |
| 60 | + height: 15px; |
| 61 | + margin: 0; |
| 62 | + border: 8px solid #f3f3f3; |
| 63 | + border-radius: 50%; |
| 64 | + border-top: 8px solid #3498db; |
| 65 | + -webkit-animation: spin 2s linear infinite; |
| 66 | + animation: spin 2s linear infinite; |
| 67 | + } |
| 68 | + @-webkit-keyframes spin { |
| 69 | + 0% { -webkit-transform: rotate(0deg); } |
| 70 | + 100% { -webkit-transform: rotate(360deg); } |
| 71 | + } |
| 72 | + @keyframes spin { |
| 73 | + 0% { transform: rotate(0deg); } |
| 74 | + 100% { transform: rotate(360deg); } |
67 | 75 | } |
68 | | - .pulse { |
69 | | - animation: pulse 1.5s infinite; |
70 | | - border-color: #007bff; |
71 | | - outline: none; |
| 76 | + .foo { |
| 77 | + display: flex; |
| 78 | + flex-direction: row; |
| 79 | + justify-content: flex-start; |
| 80 | + align-items: center; |
| 81 | + } |
| 82 | + #popup { |
| 83 | + display: none; |
| 84 | + background-color: rgba(0,0,0,0.5); |
| 85 | + position: fixed; |
| 86 | + z-index: 999; |
| 87 | + width: 100%; |
| 88 | + height: 100vh; |
| 89 | + flex-direction: column; |
| 90 | + justify-content: center; |
| 91 | + align-items: center; |
| 92 | + margin: 0 auto; |
| 93 | + .popup { |
| 94 | + background: white; |
| 95 | + color: #fff; |
| 96 | + padding: 10px; |
| 97 | + border-radius: 5px; |
| 98 | + display: flex; |
| 99 | + flex-direction: column; |
| 100 | + align-items: center; |
| 101 | + width: 200px; |
| 102 | + #text { |
| 103 | + color: black; |
| 104 | + } |
| 105 | + } |
72 | 106 | } |
73 | 107 | </style> |
74 | 108 | </head> |
75 | 109 | <body> |
76 | | - <button id="run-btn">Run</button> |
| 110 | + <div id="popup"> |
| 111 | + <div class="popup"> |
| 112 | + <p id="text"></p> |
| 113 | + <button id="ok-btn">OK</button> |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + <div class="foo"> |
| 117 | + <button id="run-btn">Run</button> |
| 118 | + <div id="loader"></div> |
| 119 | + </div> |
77 | 120 | <div id="container"></div> |
78 | 121 | <script src="https://d3js.org/d3.v7.min.js"></script> |
79 | 122 | <script> |
|
83 | 126 |
|
84 | 127 | const container = d3.select("#container"); |
85 | 128 |
|
86 | | - function render(data) { |
87 | | - const grouped = {}; |
88 | | - for (const worker of data.workers) { |
89 | | - if (!grouped[worker.runner_name]) { |
90 | | - grouped[worker.runner_name] = []; |
91 | | - } |
92 | | - grouped[worker.runner_name].push(worker.worker_name); |
93 | | - } |
| 129 | + function sleep(ms) { |
| 130 | + return new Promise(resolve => setTimeout(resolve, ms)); |
| 131 | + } |
94 | 132 |
|
| 133 | + window.prev_data = {}; |
| 134 | + function render(data) { |
95 | 135 | const container = d3.select("#container"); |
96 | 136 |
|
97 | | - const nodeColumns = container.selectAll(".node-column").data(Object.entries(grouped), (d) => d[0]); |
| 137 | + // In case some runners didn't respond due to being buse, use the previous value for that runner |
| 138 | + const new_data = {...window.prev_data, ...data}; |
| 139 | + window.prev_data = {...data}; |
| 140 | + |
| 141 | + const data_list = Object.entries(new_data).sort((a, b) => { |
| 142 | + return a[0].localeCompare(b[0]); |
| 143 | + }); |
| 144 | + |
| 145 | + const nodeColumns = container.selectAll(".node-column").data(data_list, (d) => d[0]); |
98 | 146 | nodeColumns.exit().remove(); |
99 | 147 |
|
100 | 148 | const nodeColumnsEnter = nodeColumns.enter().append("div").attr("class", "node-column"); |
|
154 | 202 | }); |
155 | 203 | } |
156 | 204 |
|
| 205 | + document.getElementById("ok-btn").addEventListener("click", async function () { |
| 206 | + const popup = document.getElementById("popup"); |
| 207 | + popup.style.display = "none" |
| 208 | + }); |
| 209 | + |
157 | 210 | document.getElementById("run-btn").addEventListener("click", async function () { |
158 | 211 | const button = this; |
159 | | - button.classList.add("pulse"); |
| 212 | + const loader = document.getElementById("loader"); |
| 213 | + const popup = document.getElementById("popup"); |
| 214 | + const text = document.getElementById("text"); |
| 215 | + button.disabled = true; |
| 216 | + loader.style.display = "block"; |
| 217 | + |
160 | 218 | try { |
| 219 | + const start = Date.now(); |
161 | 220 | const response = await fetch("/analyze", { method: "POST" }); |
162 | 221 | const response_json = await response.json(); |
| 222 | + const end = Date.now(); |
163 | 223 | console.log("Analysis: ", response_json); |
| 224 | + text.innerHTML = `Success in: ${Math.floor((end - start) / 1000)} s`; |
164 | 225 | } catch (error) { |
165 | 226 | console.error("Error fetching /analyze:", error); |
| 227 | + text.innerHTML = "Error" |
166 | 228 | } finally { |
167 | | - button.classList.remove("pulse"); |
| 229 | + loader.style.display = "none"; |
| 230 | + await sleep(1500); |
| 231 | + popup.style.display = "flex" |
| 232 | + button.disabled = false; |
168 | 233 | } |
169 | 234 | }); |
170 | 235 |
|
|
174 | 239 | const response = await fetch("/runners/workers"); |
175 | 240 | if (response.ok) { |
176 | 241 | const response_json = await response.json(); |
177 | | - console.log("Workers: ", response_json); |
| 242 | + const now = new Date(); |
| 243 | + console.log(now.toLocaleTimeString(), "Workers:", response_json); |
178 | 244 | render(response_json); |
179 | 245 | } |
180 | 246 | } catch (e) { |
|
0 commit comments