Skip to content

Commit 38ca1c3

Browse files
committed
fixed single comparison calculation, fixed selecting workload crashes on amd cpus
1 parent 1b86f70 commit 38ca1c3

File tree

5 files changed

+63
-19
lines changed

5 files changed

+63
-19
lines changed

frontend/src/assets/data.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { CPUEntry, INTEL, AMD } from "../partials/BenchmarkSettings";
1+
import { CPUEntry } from "../partials/BenchmarkSettings";
22

33
export interface CPUs {
44
[key: string]: CPUEntry;
55
}
66

7+
export const INTEL = "Intel";
8+
export const AMD = "AMD";
9+
710
export interface CPUMetric {
811
label: Exclude<keyof CPUEntry, "MAKE">;
912
unit: string | null;

frontend/src/partials/BenchmarkSettings.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import CPU_DATA from "../assets/data";
12
import { useBenchmarkContext } from "../utility/BenchmarkContext";
23
import ToggleSelection from "../utility/ToggleSelection";
34
import { addCommaToNumber } from "../utility/UtilityFunctions";
@@ -51,12 +52,26 @@ export const WORKLOAD_MAPPING: WorkloadMappingType = {
5152

5253
function BenchmarkSettings() {
5354

54-
const { workload, utilization, country, oldPerformanceIndicator, newPerformanceIndicator, singleComparison, setWorkload, setUtilization, setCountry } = useBenchmarkContext();
55+
const { currentCPU, newCPU, workload, utilization, country, oldPerformanceIndicator, newPerformanceIndicator, singleComparison, setWorkload, setUtilization, setCountry } = useBenchmarkContext();
5556

5657
const ratio = (newPerformanceIndicator / oldPerformanceIndicator).toFixed(3).replace(/\.000$/, '')
5758
let oldFormatted = oldPerformanceIndicator.toFixed(1).replace(/\.0$/, '');
5859
let newFormatted = newPerformanceIndicator.toFixed(1).replace(/\.0$/, '');
5960

61+
let disabledWorkload: WorkloadType[] = [];
62+
63+
WORKLOAD_TYPES.forEach(workload => {
64+
let push = false
65+
if (CPU_DATA[currentCPU][WORKLOAD_MAPPING[workload]] === null) push = true;
66+
if (CPU_DATA[newCPU][WORKLOAD_MAPPING[workload]] === null) push = true;
67+
68+
// push only if it is not alreal in disableWorkload
69+
if (push && !disabledWorkload.includes(workload)) disabledWorkload.push(workload)
70+
})
71+
72+
// need to reset workload if restriced cpu is selected after workload is set
73+
if (disabledWorkload.includes(workload)) setWorkload(WORKLOAD_TYPES[0])
74+
6075
oldFormatted = addCommaToNumber(Number(oldFormatted));
6176
newFormatted = addCommaToNumber(Number(newFormatted));
6277

@@ -68,6 +83,7 @@ function BenchmarkSettings() {
6883
options={WORKLOAD_TYPES}
6984
currentState={workload}
7085
setState={setWorkload}
86+
disabled={disabledWorkload}
7187
/>
7288
<div className="flex gap-4 items-center">
7389
<label><p>Utilization %:</p></label>

frontend/src/partials/Compare.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ interface DropdownProps {
6262
}
6363

6464
const Dropdown: React.FC<DropdownProps> = ({ label, thisConfig, otherConfig }) => {
65+
66+
const { singleComparison, setSingleComparison} = useBenchmarkContext();
67+
6568
const specs_selected :CPUEntry = CPU_DATA[thisConfig.cpu];
6669
const specs_compareTo :CPUEntry = CPU_DATA[otherConfig.cpu];
6770
const canToggle = label == NEW_LABEL;
@@ -70,11 +73,14 @@ const Dropdown: React.FC<DropdownProps> = ({ label, thisConfig, otherConfig }) =
7073

7174
// This is when new hardware is hidden, we set it equal to current hardware
7275
if (canToggle && !showDropdown) {
73-
thisConfig.setCPU(otherConfig.cpu)
76+
// thisConfig.setCPU(otherConfig.cpu)
77+
// thisConfig.setRAM(otherConfig.ram)
78+
// thisConfig.setHDD(otherConfig.hdd)
7479
}
7580

7681
const toggleShow = () => {
7782
if (!canToggle) return;
83+
setSingleComparison(!singleComparison);
7884
setShowDropdown(!showDropdown);
7985
}
8086

@@ -119,25 +125,28 @@ const Dropdown: React.FC<DropdownProps> = ({ label, thisConfig, otherConfig }) =
119125
</div>
120126
<div className="flex flex-col gap-4 pb-4 px-2">
121127
<ToggleSelection<number>
122-
label="DRAM (GB):"
128+
label="RAM (GB):"
123129
options={RAM_CAPACITIES}
124130
currentState={thisConfig.ram}
125131
setState={thisConfig.setRAM}
126132
extraInput={true}
133+
flexJustify="justify-between"
127134
/>
128135
<ToggleSelection<number>
129136
label="SSD (GB):"
130137
options={SSD_CAPACITIES}
131138
currentState={thisConfig.ssd}
132139
setState={thisConfig.setSSD}
133140
extraInput={true}
141+
flexJustify="justify-between"
134142
/>
135143
<ToggleSelection<number>
136144
label="HDD (GB):"
137145
options={HDD_CAPACITIES}
138146
currentState={thisConfig.hdd}
139147
setState={thisConfig.setHDD}
140148
extraInput={true}
149+
flexJustify="justify-between"
141150
/>
142151
</div>
143152
<div className="flex gap-4">

frontend/src/utility/BenchmarkContext.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ interface BenchmarkContextType {
4848
setWorkload: (value: WorkloadType) => void;
4949
setUtilization: (value: number) => void;
5050
setCountry: (value: Country) => void;
51+
setSingleComparison: (value: boolean) => void;
5152
}
5253

5354
const BenchmarkContext = createContext<BenchmarkContextType | undefined>(undefined);
@@ -57,6 +58,8 @@ interface BenchmarkProviderProps {
5758
}
5859

5960
export const BenchmarkProvider: React.FC<BenchmarkProviderProps> = ({ children }) => {
61+
// need to add a usestate for single comparison cant
62+
6063
// Compare section
6164
const [currentCPU, setCurrentCPU] = useState<string>(CPU_LIST[0]);
6265
const [currentRAM, setCurrentRAM] = useState<number>(RAM_CAPACITIES[0]);
@@ -72,11 +75,12 @@ export const BenchmarkProvider: React.FC<BenchmarkProviderProps> = ({ children }
7275
const [utilization, setUtilization] = useState<number>(40);
7376
const [country, setCountry] = useState<Country>(COUNTRIES[0]);
7477

78+
const [singleComparison, setSingleComparison] = useState<boolean>(true);
79+
7580
const oldPerformanceIndicator = CPU_DATA[currentCPU][WORKLOAD_MAPPING[workload]] || 0;
7681
const newPerformanceIndicator = CPU_DATA[newCPU][WORKLOAD_MAPPING[workload]] || 0;
7782
const oldDieSize = CPU_DATA[currentCPU].DIE_SIZE;
7883
const newDieSize = CPU_DATA[newCPU].DIE_SIZE;
79-
const singleComparison = currentCPU == newCPU;
8084

8185
// Old System
8286
const oldSystem = new System(
@@ -101,7 +105,7 @@ export const BenchmarkProvider: React.FC<BenchmarkProviderProps> = ({ children }
101105
);
102106

103107
const comparison :ComparisonType = generateSystemsComparison(
104-
newSystem, // new system object
108+
(singleComparison ? oldSystem : newSystem), // new system object
105109
oldSystem, // old system object
106110
timeHorizon, // time horizon
107111
country, // country string
@@ -141,7 +145,7 @@ export const BenchmarkProvider: React.FC<BenchmarkProviderProps> = ({ children }
141145
const newSystemOpex = comparison.newSystemOpex.slice(0, breakEven);
142146

143147
return (
144-
<BenchmarkContext.Provider value={{ oldPerformanceIndicator, newPerformanceIndicator, comparison, oldSystemOpex, singleComparison, newSystemOpex, intersect, breakEven, workload, utilization, country, setWorkload, setUtilization, setCountry, currentCPU, setCurrentCPU, newCPU, setNewCPU, currentRAM, currentSSD, newRAM, newSSD, setNewRAM, setNewSSD, setCurrentRAM, setCurrentSSD, currentHDD, setCurrentHDD, newHDD, setNewHDD }}>
148+
<BenchmarkContext.Provider value={{ setSingleComparison, oldPerformanceIndicator, newPerformanceIndicator, comparison, oldSystemOpex, singleComparison, newSystemOpex, intersect, breakEven, workload, utilization, country, setWorkload, setUtilization, setCountry, currentCPU, setCurrentCPU, newCPU, setNewCPU, currentRAM, currentSSD, newRAM, newSSD, setNewRAM, setNewSSD, setCurrentRAM, setCurrentSSD, currentHDD, setCurrentHDD, newHDD, setNewHDD }}>
145149
{children}
146150
</BenchmarkContext.Provider>
147151
);

frontend/src/utility/ToggleSelection.tsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@ interface ToggleSelectionProps<T> {
77
currentState: T;
88
capitalize?: boolean;
99
extraInput?: boolean;
10+
flexJustify?: string;
11+
disabled?: Array<T>;
1012
setState: (value: T) => void;
1113
}
1214

13-
const ToggleSelection = <T,>({ label, options, setState, currentState, capitalize = false, extraInput = false }: ToggleSelectionProps<T>) => {
15+
const ToggleSelection = <T,>({
16+
label,
17+
options,
18+
setState,
19+
currentState,
20+
capitalize = false,
21+
extraInput = false,
22+
flexJustify = "justify-start",
23+
disabled = []
24+
}: ToggleSelectionProps<T>) => {
1425

1526
const [extra, setExtra] = useState('Other');
1627

17-
const extraFocus = (value: any) => {
18-
setExtra(value);
28+
const extraFocus = (value: any, initial: boolean = false) => {
29+
setExtra((initial && value == "Other") ? "" : value);
1930
if (value == Number(value)) setState(value as unknown as T);
2031
}
2132

@@ -33,25 +44,26 @@ const ToggleSelection = <T,>({ label, options, setState, currentState, capitaliz
3344
};
3445

3546
return (
36-
<div className="flex gap-4 items-center flex-wrap">
37-
<p className="border-b-4 border-transparent font-medium">{label}</p>
47+
<div className={`flex gap-4 items-center flex-wrap w-full ${flexJustify}`}>
48+
<p className="border-b-4 border-transparent">{label}</p>
3849
{options.map((option) => (
3950
<button
4051
key={String(option)}
4152
onFocus={() => setState(option)}
42-
className={
43-
`px-3 py-0.5 cursor-pointer border-b-4 duration-150
44-
${currentState === option ? "border-orange-400 font-bold" : "border-b-transparent font-normal hover:border-b-orange-400/30"}
45-
${capitalize ? 'capitalize' : ''}`
46-
}
53+
disabled={disabled.includes(option)}
54+
className={`px-2 min-w-16 border-b-4 duration-150
55+
${currentState === option ? "border-orange-400 font-bold" : "border-b-transparent font-normal hover:border-b-orange-400/30"}
56+
${capitalize ? " capitalize" : ""}
57+
${disabled.includes(option) ? "cursor-not-allowed text-gray-300 hover:border-b-transparent" : "cursor-pointer"}
58+
`}
4759
>
4860
{String(option)}
4961
</button>
5062
))}
5163
{ extraInput &&
5264
<div className="flex items-start">
53-
<input type="text" className={`${currentState == extra ? 'border-orange-400 font-bold' : 'border-b-transparent hover:border-b-orange-400/30'} cursor-pointer text-center duration-150 border-b-4 border-orange-400 focus:outline-none w-14`}
54-
onFocus={(e) => extraFocus(e.target.value)}
65+
<input type="text" className={`${currentState == extra ? 'border-orange-400 font-bold' : 'border-b-transparent hover:border-b-orange-400/30'} cursor-pointer text-center duration-150 border-b-4 focus:outline-orange-400/30 w-14`}
66+
onFocus={(e) => extraFocus(e.target.value, true)}
5567
onChange={(e) => extraFocus(e.target.value)}
5668
onBlur={(e) => extraUnfocus(e.target.value)}
5769
value={extra} />

0 commit comments

Comments
 (0)