Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
bfd6cb1
Add code runtime metrics to ntTopics and export function
mmgokhale Mar 5, 2025
90e7492
Add runtime data handling and graph visualization to robot view
mmgokhale Mar 5, 2025
75271d0
Add styling for graph container in CSS
mmgokhale Mar 5, 2025
b1f6db2
Add robot runtime graph visualization and data handling. remove the o…
mmgokhale Mar 12, 2025
e22a329
Refactor runtime graph implementation: remove old page runtime graph,…
mmgokhale Mar 13, 2025
93aeff0
Implement line chart for runtime data visualization with real-time up…
mmgokhale Mar 14, 2025
5fad1eb
Adjust graph container and chart dimensions for improved layout and s…
mmgokhale Mar 14, 2025
9d37695
Add debugging log for raw chart data in chart.js -- but not printing …
mmgokhale Mar 14, 2025
5fdcb20
Add runtime graph canvas initialization and error handling
mmgokhale Mar 14, 2025
36680c0
Enhance runtime chart: add annotation for 20 ms threshold, improve st…
mmgokhale Mar 19, 2025
4be7693
Refactor runtime chart: update title, adjust canvas size, add annotat…
mmgokhale Mar 26, 2025
83a9d99
Refactor robot view: adjust runtime graph position, update styling, a…
mmgokhale Mar 27, 2025
4325054
Add new web socket connection for robot runtime data and clean up HTM…
mmgokhale Apr 7, 2025
44deded
Remove runtime graph setup and add WebSocket listener for robot runti…
mmgokhale Apr 8, 2025
7c4d1f0
Refactor runtime chart rendering: replace fetch with WebSocket listen…
mmgokhale Apr 11, 2025
d9c3de3
Update dependencies: add socket.io-client and engine.io-client to pac…
mmgokhale Apr 11, 2025
f7c57cd
Enhance robot runtime display: update WebSocket listener and fetch fu…
mmgokhale Apr 15, 2025
48f51c4
Refactor socket initialization: ensure single declaration and attach …
mmgokhale Apr 25, 2025
d408b91
Refactor socket initialization: ensure single declaration and remove …
mmgokhale May 5, 2025
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
28 changes: 23 additions & 5 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,26 @@ div.twitchstream iframe {
}

.runtime {
background-color: #24252a;
margin: 10px;
text-align: left;
color: #ffffff;
border-radius: 10px;
font-family: "Source Code Pro", monospace;
border: 2px solid white; /* Adjust thickness as needed */
background: none; /* remove filled background */
border: none; /* remove complete border */
border-bottom: 2px solid white; /* line graph baseline */
width: calc(35vw / 2);
height: 20vh;
height: auto; /* remove fixed height */
float: left;
position: relative;
}

.runtime::after {
content: "";
position: absolute;
top: 50%;
left: 0;
width: 100%;
height: 0; /* no extra height */
}

.voltage {
Expand Down Expand Up @@ -369,4 +379,12 @@ div.twitchstream iframe {
.checklist {
font-family: "Source Code Pro", monospace;
font-size: 15px;
}
}

.graph-container {
border: 2px solid #fff;
padding: 5px;
margin: 5px 0;
width: 300px;
height: 200px;
}
102 changes: 78 additions & 24 deletions assets/js/robot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
* contains client-side JavaScript functions
* (primarily event handlers to fetch data from the Node server)
*/
const socket = window.io();

// Ensure `socket` is declared only once and avoid redeclaration

window.socket = window.io(); // Attach `socket` to the global `window` object

const socket = window.socket;

socket.on("temperatures", (entry) => {
const temperatures = document.querySelector("div.temp");
Expand All @@ -14,14 +19,77 @@ socket.on("pdhCurrents", (entry) => {
pdhDisplay.innerHTML = entry;
});

socket.on("powerStats", (stats) => {
const runtimeDisplay = document.querySelector("div.runtime");
const voltageDisplay = document.querySelector("div.voltage");
// new web socket connection for robot runtime data
// web dev code vid

// Remove Chart.js setup and runtime graph logic
// const ctx = document.getElementById("runtimeGraph").getContext("2d");
// const runtimeChart = new Chart(ctx, {
// type: "line",
// data: {
// labels: [], // timestamps
// datasets: [
// {
// label: "Robot Code Runtime",
// data: [],
// borderColor: "rgba(75, 192, 192, 1)",
// fill: false,
// },
// ],
// },

// options: {
// scales: {
// x: { display: true },
// y: {
// beginAtZero: true,
// },
// },
// plugins: {
// annotation: {
// annotations: {
// line1: {
// type: "line",
// yMin: 20,
// yMax: 20,
// borderColor: "red",
// borderWidth: 2,
// label: {
// content: "20 ms",
// enabled: true,
// position: "center",
// },
// },
// },
// },
// },
// responsive: false,
// },
// });

runtimeDisplay.innerHTML = stats.currentDisplay;
voltageDisplay.innerHTML = stats.voltageDisplay;
// Add WebSocket listener for robotRuntime event
socket.on("robotRuntime", (data) => {
const runtimeDisplay = document.querySelector("div.runtime");
runtimeDisplay.innerHTML = `Runtime: Timestamp: ${data.timestamp}, Runtime: ${data.runtime} ms`;
});

async function fetchRuntime() {
const runtimeDisplay = document.querySelector("div.runtime");
const response = await fetch("/runtime");
if (response.ok) {
runtimeDisplay.innerHTML = `Runtime: ${await response.text()}`;
} else {
console.error("Error fetching runtime data");
}
}

// Call the function to fetch runtime info on page load
// add a check to see if runtime data was fetched

fetchRuntime();
const data = fetchRuntime();
console.log("Fetched runtime data:", data); // Debugging statement

async function fetchTemperatures() {
const temperatures = document.querySelector("div.temp");
const response = await fetch("/temperatures");
Expand All @@ -41,40 +109,26 @@ async function fetchPDHCurrents() {
console.log("error fetching PDH currents");
}
}

async function fetchPowerStats() {
const runtimeDisplay = document.querySelector("div.runtime");
const voltageDisplay = document.querySelector("div.voltage");
const response = await fetch("/powerStats");
if (response.ok) {
const stats = await response.json();
runtimeDisplay.innerHTML = stats.currentDisplay;
voltageDisplay.innerHTML = stats.voltageDisplay;
} else {
console.log("error fetching power stats");
}
}

// change the data
fetchTemperatures();
fetchPDHCurrents();
fetchPowerStats();

// Select all checkboxes with a data-key attribute for persistence
const checklist = document.querySelectorAll('input[type="checkbox"][data-key]');

checklist.forEach((checkbox) => {
// Load persisted state on page load
const key = checkbox.getAttribute('data-key');
const key = checkbox.getAttribute("data-key");
const saved = localStorage.getItem(key);
if (saved === 'true') {
if (saved === "true") {
checkbox.checked = true;
}

checkbox.addEventListener("click", (event) => {
const label = event.target.closest("label");
const taskText = label.textContent.trim();
const isChecked = event.target.checked;
const key = event.target.getAttribute('data-key');
const key = event.target.getAttribute("data-key");
// Save state to localStorage
localStorage.setItem(key, isChecked);
socket.emit("checklist", { taskText, isChecked });
Expand Down
12 changes: 12 additions & 0 deletions js/robot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Ensure the rest of the code uses the `socket` variable declared in the main HTML file

// Example usage of the socket variable
socket.on("connect", () => {
console.log("Connected to server");
});

socket.on("disconnect", () => {
console.log("Disconnected from server");
});

// Add other socket event listeners and handlers as needed
60 changes: 60 additions & 0 deletions node_modules/.package-lock.json

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

Loading