Skip to content

Commit c0d7693

Browse files
committed
fixed utilization scaling, and resource scaling interactions + minor ux
1 parent aa6b1a9 commit c0d7693

8 files changed

Lines changed: 38 additions & 24 deletions

File tree

frontend/src/charts/lineChart.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function lineIntersect(
7171

7272
const LineChart: React.FC<{}> = memo(function LineChart() {
7373

74-
const { workload, country, utilization, comparison, intersect, oldSystemOpex, newSystemOpex, breakEven, singleComparison } = useBenchmarkContext();
74+
const { workload, country, currentServer, newServer, comparison, intersect, oldSystemOpex, newSystemOpex, breakEven, singleComparison } = useBenchmarkContext();
7575

7676
// @ts-ignore
7777
const [chart, setChart] = useState<Chart | null>(null);
@@ -106,6 +106,9 @@ const LineChart: React.FC<{}> = memo(function LineChart() {
106106
})
107107
}
108108

109+
const currentUtilization = currentServer.utilization.toFixed(0);
110+
const newUtilization = newServer.utilization.toFixed(0);
111+
109112
const L = oldSystemOpex.length - 1;
110113
const isOneDecimalPlace = oldSystemOpex[L] > 1000 && newSystemOpex[L] > 1000;
111114

@@ -325,7 +328,12 @@ const LineChart: React.FC<{}> = memo(function LineChart() {
325328
<canvas ref={canvas} width={400} height={500}></canvas>
326329
</figure>
327330
<p className="text-center text-sm w-full mx-auto font-serif text-slate-700">
328-
Projected CO2 accumulated emissions of current (blue) and new (orange) hardware for a {workload} workload, {utilization}% utilization with energy sourced from <span className="capitalize">{country}</span>.
331+
{singleComparison ?
332+
`Projected CO2 accumulated emissions of current (blue) hardware for a ${workload} workload, operated at ${currentUtilization}% utilization, with electricity from ${country}.`
333+
:
334+
`Projected CO2 accumulated emissions of current (blue) and new (orange) hardware for a ${workload} workload, operated at ${currentUtilization}% and ${newUtilization}% utilization respectively, with electricity from ${country}.`
335+
336+
}
329337
</p>
330338
</div>
331339
);

frontend/src/partials/BenchmarkSettings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function BenchmarkSettings() {
103103

104104
useEffect(() => {
105105
if (scaling === "Utilization") {
106-
const ratio = newPerformanceIndicator / oldPerformanceIndicator;
106+
const ratio = oldPerformanceIndicator / newPerformanceIndicator;
107107
const scaledUtilization = clamp( currentServer.utilization as number * ratio, 0, 100);
108108
updateServer(newServer, { utilization: scaledUtilization });
109109
}
@@ -165,7 +165,7 @@ return (
165165
/>
166166
</div>
167167
</div>
168-
<div className={`${advancedSettings ? 'h-96' : 'h-96'} duration-300 ease-in-out overflow-hidden relative`}>
168+
<div className={`duration-300 ease-in-out overflow-hidden relative`}>
169169
<GeoMap country={country} setCountry={setCountry} />
170170
</div>
171171
</div>

frontend/src/partials/Compare.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const applyScaledUpdates = (
5252

5353
const ratio = thisPerformanceIndicator / otherPerformanceIndicator;
5454

55-
5655
const scaleKeys: (keyof Pick<ServerType, 'ssd' | 'ram' | 'hdd'>)[] = ['ssd', 'ram', 'hdd'];
5756
const scaledUpdates: Partial<ServerType> = {};
5857

@@ -84,7 +83,7 @@ interface DropdownProps {
8483

8584
const Dropdown: React.FC<DropdownProps> = ({ label, thisServer, otherServer, showAdvanced, advancedOptions}) => {
8685

87-
const { singleComparison, updateServer, setSingleComparison, setAdvancedOptions, getPerformanceIndicator} = useBenchmarkContext();
86+
const { singleComparison, workload, updateServer, setSingleComparison, setAdvancedOptions, setAdvancedSettings, getPerformanceIndicator} = useBenchmarkContext();
8887

8988
const specs_selected :CPUEntry = CPU_DATA[thisServer.cpu];
9089
const specs_compareTo :CPUEntry = CPU_DATA[otherServer.cpu];
@@ -121,9 +120,9 @@ const Dropdown: React.FC<DropdownProps> = ({ label, thisServer, otherServer, sho
121120
if (onlyCPU) {
122121
updates = {
123122
cpu: updates.cpu,
124-
ram: thisServer.ram,
125-
ssd: thisServer.ssd,
126-
hdd: thisServer.hdd,
123+
ram: otherServer.ram,
124+
ssd: otherServer.ssd,
125+
hdd: otherServer.hdd,
127126
}
128127
}
129128

@@ -141,8 +140,8 @@ const Dropdown: React.FC<DropdownProps> = ({ label, thisServer, otherServer, sho
141140
if (advancedOptions === 'Scale' && onlyCPU) {
142141
const scaledUpdates = applyScaledUpdates(
143142
updates,
144-
getPerformanceIndicator(otherServer.cpu),
145143
getPerformanceIndicator(updates.cpu || thisServer.cpu),
144+
getPerformanceIndicator(otherServer.cpu),
146145
);
147146
updateServer(thisServer, scaledUpdates);
148147
return;
@@ -152,8 +151,8 @@ const Dropdown: React.FC<DropdownProps> = ({ label, thisServer, otherServer, sho
152151
if (advancedOptions === 'Scale' && !onlyCPU) {
153152
const scaledUpdates = applyScaledUpdates(
154153
updates,
155-
getPerformanceIndicator(updates.cpu || thisServer.cpu),
156154
getPerformanceIndicator(otherServer.cpu),
155+
getPerformanceIndicator(updates.cpu || thisServer.cpu),
157156
);
158157
updateServer(otherServer, scaledUpdates);
159158
return;
@@ -181,7 +180,7 @@ const Dropdown: React.FC<DropdownProps> = ({ label, thisServer, otherServer, sho
181180
return;
182181
}
183182

184-
}, [advancedOptions])
183+
}, [advancedOptions, workload])
185184

186185
return (
187186
<div className="col-span-1 flex flex-col gap-2 font-light relative">
@@ -202,7 +201,7 @@ const Dropdown: React.FC<DropdownProps> = ({ label, thisServer, otherServer, sho
202201
className="h-5" />
203202
</button>
204203
</div>
205-
<ServerPresetsComponent {...{ presetValue, updateComponent, setAdvancedOptions }} />
204+
<ServerPresetsComponent {...{ presetValue, updateComponent, setAdvancedOptions, setAdvancedSettings }} />
206205
<div className={`${showDropdown ? 'opacity-100' : 'opacity-0 pointer-events-none'} relative duration-150`}>
207206
<select
208207
className="block appearance-none text-base w-full bg-gray-100 border-2 border-gray-400 py-1 px-2 pr-8 rounded focus:outline-none focus:bg-white focus:border-gray-500"
@@ -249,11 +248,12 @@ const Dropdown: React.FC<DropdownProps> = ({ label, thisServer, otherServer, sho
249248
<table className="text-base grow border-collapse">
250249
<tbody>
251250
{Object.entries(DISPLAY).map(([key, prop]) => {
252-
const selectedValue = specs_selected[prop] || 0;
251+
let selectedValue = specs_selected[prop] || 0;
253252
const compareValue = (specs_compareTo?.[prop] ?? selectedValue) || 0;
253+
if (key == 'TDP') selectedValue = selectedValue + ' W';
254254
return (
255255
<tr key={key}>
256-
<td className="w-0 pr-4 align-top text-right">{key}:</td>
256+
<td className="w-0 pr-4 align-top text-left">{key}:</td>
257257
<td className="flex items-center gap-1">
258258
<p>{selectedValue}</p>
259259
{selectedValue > compareValue && !singleComparison && (

frontend/src/partials/GeoMap.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const GeoMap: React.FC<GeomapProps> = ({ country, setCountry }) => {
131131

132132
return (
133133
<>
134-
<div className="w-full relative h-full flex flex-col overflow-hidden rounded-lg border border-slate-500">
134+
<div className="w-full relative h-96 flex flex-col overflow-hidden rounded-lg border border-slate-500">
135135
<MapContainer
136136
center={[30, 0]}
137137
zoom={2}
@@ -171,13 +171,13 @@ const GeoMap: React.FC<GeomapProps> = ({ country, setCountry }) => {
171171
</div>
172172
</div>
173173
</div>
174-
<p className="text-sm font-light text-right -mt-2">
174+
<p className="text-base font-light text-right">
175175
Source:{BLANK_SPACE}
176176
<a
177177
className="text-cyan-700 hover:underline duration-300"
178178
href="https://www.electricitymaps.com/"
179179
>
180-
Electricity Maps
180+
Electricity Maps - Yearly 2024
181181
</a>
182182
</p>
183183
</>

frontend/src/partials/ServerPresets.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ type ServerPresetsComponentProps = {
77
updateComponent: (update: Partial<ServerType>, preset: string) => void;
88
presetValue: keyof ServerPresets | typeof CUSTOM;
99
setAdvancedOptions: (value: null | 'Mirror' | 'Scale') => void;
10+
setAdvancedSettings: (value: boolean) => void;
1011
};
1112

12-
const ServerPresetsComponent = ({ presetValue, updateComponent, setAdvancedOptions }: ServerPresetsComponentProps) => {
13+
const ServerPresetsComponent = ({ presetValue, updateComponent, setAdvancedOptions, setAdvancedSettings }: ServerPresetsComponentProps) => {
1314
const [showPresetMenu, setShowPresetMenu] = useState(false);
1415
const popupRef = useRef<HTMLDivElement>(null);
1516

@@ -35,6 +36,7 @@ const ServerPresetsComponent = ({ presetValue, updateComponent, setAdvancedOptio
3536

3637
const handleSelectPreset = (key: keyof ServerPresets) => {
3738
setAdvancedOptions(null);
39+
setAdvancedSettings(true);
3840
const preset = SERVER_PRESETS[key];
3941

4042
const config: Partial<ServerType> = {

frontend/src/utility/BenchmarkContext.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ export const BenchmarkProvider: React.FC<BenchmarkProviderProps> = ({ children }
145145
CPU_DATA[newCPU].TDP// cpuTdp in Watts
146146
);
147147

148-
console.log(currentServer.utilization, newServer.utilization);
149-
150148
const comparison :ComparisonType = generateSystemsComparison(
151149
(singleComparison ? oldSystem : newSystem), // new system object
152150
oldSystem, // old system object
@@ -187,6 +185,7 @@ export const BenchmarkProvider: React.FC<BenchmarkProviderProps> = ({ children }
187185
return intersect;
188186
}
189187

188+
console.log(comparison)
190189
const intersect = calculateIntersect(singleComparison, comparison.oldSystemOpex, comparison.newSystemOpex)
191190
const breakEven = Math.ceil(intersect ? intersect.x + 1 : 3);
192191

frontend/src/utility/lifecycle_analysis/comparison.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export function generateSystemsComparison(
3737
);
3838
let newSystemOpex = newSystemEmissions.projected
3939

40+
console.log(newSystemEmissions);
41+
42+
4043
const newSystemCapexBreakdown = newSystem.calculateCapexEmissions();
4144
const newSystemCapex = newSystemCapexBreakdown.TOTAL;
4245

@@ -60,8 +63,9 @@ export function generateSystemsComparison(
6063
// Adjust old system OPEX based on performance factor
6164
oldSystemOpex = oldSystemOpex.map((opex) => opex / performanceFactor);
6265
} else {
66+
// utilization scaling
6367
// Adjust new system OPEX based on performance factor
64-
newSystemOpex = newSystemOpex.map((opex) => opex * performanceFactor);
68+
// newSystemOpex = newSystemOpex.map((opex) => opex * performanceFactor);
6569
}
6670

6771
// Add CAPEX to OPEX for the new system at each time step

frontend/src/utility/lifecycle_analysis/system.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ export class System {
136136
const hddEnergyConsumption =
137137
(this.hddCapacity > 0 ? 7 : 0) / 1000; // kW
138138

139-
const totalWatts =
139+
let totalWatts =
140140
cpuEnergyConsumption +
141141
dramEnergyConsumption +
142142
ssdEnergyConsumption +
143143
hddEnergyConsumption;
144+
144145
const totalWattsPerYear = 24 * 7 * 52 * totalWatts; // kWh
145146
const GCI = (GRID_INTENSITY[country] || 0) / 1000;
146147

@@ -150,7 +151,7 @@ export class System {
150151
SSD: ssdEnergyConsumption,
151152
HDD: hddEnergyConsumption,
152153
TOTAL: totalWatts,
153-
opexPerYear: totalWattsPerYear * GCI
154+
opexPerYear: (totalWattsPerYear * GCI)
154155
}
155156
}
156157
}

0 commit comments

Comments
 (0)