viewof maintenanceStrategy = Inputs.radio(
["Reactive", "Preventive", "Predictive"],
{
label: "Maintenance Strategy:",
value: "Reactive"
}
)
viewof totalHP = Inputs.range([100, 10000], {
label: "Total Facility Horsepower:",
step: 100,
value: 5000
})
viewof downtimeCostPerHour = Inputs.range([1000, 50000], {
label: "Downtime Cost ($/hour):",
step: 1000,
value: 5000
})
strategyCosts = {
const costs = {
"Reactive": {
costPerHP: 12.5,
downtime: 0.40,
description: "Run-to-failure approach"
},
"Preventive": {
costPerHP: 8,
downtime: 0.20,
description: "Time-based scheduled maintenance"
},
"Predictive": {
costPerHP: 4,
downtime: 0.05,
description: "Sensor-based condition monitoring"
}
};
const selected = costs[maintenanceStrategy];
const annualCost = totalHP * selected.costPerHP;
const avgFailuresPerYear = 8;
const hoursDowntimePerFailure = 12;
const totalDowntimeHours = avgFailuresPerYear * hoursDowntimePerFailure * selected.downtime / 0.40;
const downtimeCost = totalDowntimeHours * downtimeCostPerHour;
const totalCost = annualCost + downtimeCost;
return {
strategy: maintenanceStrategy,
costPerHP: selected.costPerHP,
downtime: selected.downtime,
description: selected.description,
annualMaintenanceCost: annualCost,
annualDowntimeCost: downtimeCost,
totalAnnualCost: totalCost,
downtimeHours: totalDowntimeHours
};
}
html`<div style="background: #f8f9fa; padding: 20px; border-radius: 8px; border-left: 4px solid ${maintenanceStrategy === 'Reactive' ? '#E74C3C' : maintenanceStrategy === 'Preventive' ? '#E67E22' : '#16A085'};">
<h3 style="margin-top: 0; color: #2C3E50;">${maintenanceStrategy} Maintenance</h3>
<p style="color: #7F8C8D; margin: 5px 0;">${strategyCosts.description}</p>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 15px;">
<div>
<div style="color: #7F8C8D; font-size: 0.9em;">Cost per HP</div>
<div style="font-size: 1.5em; font-weight: bold; color: #2C3E50;">$${strategyCosts.costPerHP}/HP/year</div>
</div>
<div>
<div style="color: #7F8C8D; font-size: 0.9em;">Downtime Factor</div>
<div style="font-size: 1.5em; font-weight: bold; color: #2C3E50;">${(strategyCosts.downtime * 100).toFixed(0)}%</div>
</div>
<div>
<div style="color: #7F8C8D; font-size: 0.9em;">Annual Maintenance Cost</div>
<div style="font-size: 1.3em; font-weight: bold; color: #2C3E50;">$${strategyCosts.annualMaintenanceCost.toLocaleString()}</div>
</div>
<div>
<div style="color: #7F8C8D; font-size: 0.9em;">Annual Downtime Cost</div>
<div style="font-size: 1.3em; font-weight: bold; color: #E74C3C;">$${strategyCosts.annualDowntimeCost.toLocaleString()}</div>
</div>
</div>
<div style="margin-top: 15px; padding-top: 15px; border-top: 2px solid #ddd;">
<div style="color: #7F8C8D; font-size: 0.9em;">Total Annual Cost</div>
<div style="font-size: 1.8em; font-weight: bold; color: #2C3E50;">$${strategyCosts.totalAnnualCost.toLocaleString()}</div>
<div style="color: #7F8C8D; font-size: 0.85em; margin-top: 5px;">
${strategyCosts.downtimeHours.toFixed(1)} hours downtime per year
</div>
</div>
</div>`comparison = {
const reactive = {
costPerHP: 12.5,
downtime: 0.40
};
const preventive = {
costPerHP: 8,
downtime: 0.20
};
const predictive = {
costPerHP: 4,
downtime: 0.05
};
const avgFailures = 8;
const hoursPerFailure = 12;
const calc = (strategy) => {
const mainCost = totalHP * strategy.costPerHP;
const downHours = avgFailures * hoursPerFailure * strategy.downtime / 0.40;
const downCost = downHours * downtimeCostPerHour;
return mainCost + downCost;
};
const reactiveCost = calc(reactive);
const preventiveCost = calc(preventive);
const predictiveCost = calc(predictive);
return [
{strategy: "Reactive", cost: reactiveCost, savings: 0},
{strategy: "Preventive", cost: preventiveCost, savings: reactiveCost - preventiveCost},
{strategy: "Predictive", cost: predictiveCost, savings: reactiveCost - predictiveCost}
];
}
Plot.plot({
marginLeft: 100,
marginBottom: 60,
x: {
label: "Annual Cost ($)",
grid: true
},
y: {
label: null
},
marks: [
Plot.barX(comparison, {
y: "strategy",
x: "cost",
fill: d => d.strategy === "Reactive" ? "#E74C3C" : d.strategy === "Preventive" ? "#E67E22" : "#16A085",
tip: true,
title: d => `${d.strategy}\nCost: $${d.cost.toLocaleString()}\nSavings vs Reactive: $${d.savings.toLocaleString()}`
}),
Plot.text(comparison, {
y: "strategy",
x: "cost",
text: d => `$${(d.cost/1000).toFixed(0)}K`,
dx: -30,
fill: "white",
fontSize: 14,
fontWeight: "bold"
}),
Plot.ruleX([0])
],
color: {
legend: false
}
})