Skip to content

Commit

Permalink
Revert.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiorisi committed Oct 29, 2024
1 parent 4d45f0c commit 64ca75e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 63 deletions.
34 changes: 11 additions & 23 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,30 @@
<body>
<h1>Motor Comparison Tool</h1>
<div id="filters">
<label for="diameter-min">Min Diameter (mm):</label>
<label for="diameter-min">Min Diameter:</label>
<input type="number" id="diameter-min">

<label for="diameter-max">Max Diameter (mm):</label>
<label for="diameter-max">Max Diameter:</label>
<input type="number" id="diameter-max">

<label for="torque-min">Min Continuous Torque (Nm):</label>
<input type="number" id="torque-min">

<label for="torque-max">Max Continuous Torque (Nm):</label>
<input type="number" id="torque-max">

<button onclick="filterMotors()">Filter</button>
</div>
<table id="results-table">
<thead>
<tr>
<th>Name</th>
<th>Cooling</th>
<th>Rated Voltage (V)</th>
<th>Continuous Torque (Nm)</th>
<th>Peak Torque (Nm)</th>
<th>Max Power (W)</th>
<th>Max Speed (RPM)</th>
<th>Pole Pairs</th>
<th>Rotor Inertia (kg·cm²)</th>
<th>Model</th>
<th>Series</th>
<th>Diameter (mm)</th>
<th>Length (mm)</th>
<th>Weight (g)</th>
<th>Rotor Inner Diameter (mm)</th>
<th>Voltage</th>
<th>Torque (Nm)</th>
<th>Speed (rpm)</th>
<th>Power (kW)</th>
<th>Weight (kg)</th>
</tr>
</thead>
<tbody id="results-body">
<!-- Filtered results will appear here -->
<!-- Results will be inserted here -->
</tbody>
</table>
<script src="script.js"></script>
</body>
</html>
</html>
36 changes: 14 additions & 22 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
let motorData = [];

// Fetch data from the new JSON file structure
// Fetch data from the JSON file
fetch("motors.json")
.then(response => response.json())
.then(data => {
motorData = data.motors;
})
.catch(error => console.error("Error loading data:", error));

// Filter motors based on user input for diameter and continuous torque
// Filter motors based on user input
function filterMotors() {
const minDiameter = parseFloat(document.getElementById("diameter-min").value);
const maxDiameter = parseFloat(document.getElementById("diameter-max").value);
const minTorque = parseFloat(document.getElementById("torque-min").value);
const maxTorque = parseFloat(document.getElementById("torque-max").value);

const filteredMotors = motorData.filter(motor => {
return (!minDiameter || motor.diameter_mm >= minDiameter) &&
(!maxDiameter || motor.diameter_mm <= maxDiameter) &&
(!minTorque || motor.continuous_torque_nm >= minTorque) &&
(!maxTorque || motor.continuous_torque_nm <= maxTorque);
return (!minDiameter || motor.outer_diameter >= minDiameter) &&
(!maxDiameter || motor.outer_diameter <= maxDiameter);
});

displayResults(filteredMotors);
Expand All @@ -33,20 +29,16 @@ function displayResults(motors) {
motors.forEach(motor => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${motor.name || "-"}</td>
<td>${motor.cooling || "-"}</td>
<td>${motor.rated_voltage_v !== null ? motor.rated_voltage_v : "-"}</td>
<td>${motor.continuous_torque_nm !== null ? motor.continuous_torque_nm : "-"}</td>
<td>${motor.peak_torque_nm !== null ? motor.peak_torque_nm : "-"}</td>
<td>${motor.max_power_w !== null ? motor.max_power_w : "-"}</td>
<td>${motor.max_rotation_speed_rpm !== null ? motor.max_rotation_speed_rpm : "-"}</td>
<td>${motor.pole_pairs !== null ? motor.pole_pairs : "-"}</td>
<td>${motor.rotor_inertia_kg_cm2 !== null ? motor.rotor_inertia_kg_cm2 : "-"}</td>
<td>${motor.diameter_mm !== null ? motor.diameter_mm : "-"}</td>
<td>${motor.length_mm !== null ? motor.length_mm : "-"}</td>
<td>${motor.weight_g !== null ? motor.weight_g : "-"}</td>
<td>${motor.rotor_inner_diameter_mm !== null ? motor.rotor_inner_diameter_mm : "-"}</td>
<td>${motor.model}</td>
<td>${motor.series}</td>
<td>${motor.outer_diameter}</td>
<td>${motor.length}</td>
<td>${motor.voltage}</td>
<td>${motor.continuous_torque_nm}</td>
<td>${motor.rated_speed_rpm}</td>
<td>${motor.rated_power_kw}</td>
<td>${motor.weight_kg}</td>
`;
resultsBody.appendChild(row);
});
}
}
20 changes: 2 additions & 18 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,21 @@ body {
font-family: Arial, sans-serif;
}

h1 {
text-align: center;
}

#filters {
text-align: center;
margin-bottom: 20px;
}

table {
width: 100%;
border-collapse: collapse;
margin: auto;
}

th, td {
padding: 8px;
text-align: center;
text-align: left;
border: 1px solid #ddd;
}

th {
background-color: #f4f4f4;
}

button {
padding: 5px 10px;
font-size: 16px;
cursor: pointer;
}

button:hover {
background-color: #ddd;
}
}

0 comments on commit 64ca75e

Please sign in to comment.