Skip to content

Commit

Permalink
Merge branch 'kyma-project:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-porru authored Nov 29, 2024
2 parents fce682b + eddbdb9 commit 557f805
Show file tree
Hide file tree
Showing 63 changed files with 1,189 additions and 1,384 deletions.
960 changes: 345 additions & 615 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
"private": true,
"homepage": "https://kyma-project.github.io/price-calculator",
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^29.5.1",
"@types/node": "^20.1.4",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@ui5/webcomponents": "^1.13.2",
"@ui5/webcomponents-fiori": "^1.13.2",
"@ui5/webcomponents-icons": "^1.12.2",
"@ui5/webcomponents-react": "^1.15.1",
"@ui5/webcomponents-react-charts": "^1.15.0",
"react": "^18.2.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.14",
"@types/node": "^22.9.1",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@ui5/webcomponents": "^2.4.0",
"@ui5/webcomponents-fiori": "^2.4.0",
"@ui5/webcomponents-icons": "^2.4.0",
"@ui5/webcomponents-react": "^2.4.0",
"@ui5/webcomponents-react-charts": "^2.4.0",
"react": "^18.3.1",
"react-csv": "^2.2.2",
"react-dom": "^18.2.0",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
"recoil": "^0.7.7",
"xlsx": "^0.19.3"
Expand Down Expand Up @@ -52,9 +52,9 @@
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@types/react-csv": "^1.1.3",
"gh-pages": "^5.0.0",
"prettier": "^2.8.8",
"typescript": "^5.0.1"
"@types/react-csv": "^1.1.10",
"gh-pages": "^6.2.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3"
}
}
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function App() {

return (
<div className="App">
<Navbar/>
<MainContentContainer/>
<Navbar />
<MainContentContainer />
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ test('costs of minAutoscaler', () => {
const timeConsumption = 720;
const vmMultiplier = 2;
const minAutoscaler = 4;
const machineTypeFactor = 1;
const baseConfigCosts = calculateBaseConfigCosts({
timeConsumption,
vmMultiplier,
minAutoscaler,
machineTypeFactor,
});

expect(baseConfigCosts).toBe(2833);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import config from '../../config.json';

interface Props {
export interface BaseConfigProps {
timeConsumption: number;
vmMultiplier: number;
minAutoscaler: number;
machineTypeFactor: number;
}

export default function calculateBaseConfigCosts(props: Props): number {
const { timeConsumption, minAutoscaler, vmMultiplier } = props;
export default function calculateBaseConfigCosts(
props: BaseConfigProps,
): number {
const { timeConsumption, minAutoscaler, vmMultiplier, machineTypeFactor } =
props;

const PPU: number = config.baseConfig.PricePerUnit;
const BaseStorageEventsPPU: number =
config.baseConfig.BaseStorageEventsPricePerUnit;

return (
minAutoscaler * timeConsumption * PPU * vmMultiplier + BaseStorageEventsPPU
minAutoscaler * timeConsumption * PPU * vmMultiplier * machineTypeFactor +
BaseStorageEventsPPU
);
}
15 changes: 0 additions & 15 deletions src/calculatorFunctions/nodeCosts/calculateNodeCosts.test.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/calculatorFunctions/nodeCosts/calculateNodeCosts.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import calculateStorageCosts from './calculateStorageCosts';

test('total costs', () => {
const GBQuantity = 1056;
const premiumGBQuantity = 1056;
const timeConsumption = 516;

const nodeCosts = calculateStorageCosts({ GBQuantity, timeConsumption });
const nodeCosts = calculateStorageCosts({
GBQuantity,
premiumGBQuantity,
timeConsumption,
});

expect(nodeCosts).toBe(307.45);
expect(nodeCosts).toBe(1229.8);
});
17 changes: 13 additions & 4 deletions src/calculatorFunctions/storageCosts/calculateStorageCosts.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import config from '../../config.json';

interface Props {
export interface StorageCostProps {
GBQuantity: number;
premiumGBQuantity: number;
timeConsumption: number;
}

export default function calculateStorageCosts(props: Props): number {
const { GBQuantity, timeConsumption } = props;
export default function calculateStorageCosts(props: StorageCostProps): number {
const { GBQuantity, premiumGBQuantity, timeConsumption } = props;
const PPU: number = config.Storage.PricePerUnit;
const PPUdivider: number = config.Storage.PricePerUnitDivider;
const PPUdivider2: number = config.Storage.PricePerUnitDivider2;
const premiumPPU: number = config.PremiumStorage.PricePerUnit;
const premiumPPUdivider: number = config.PremiumStorage.PricePerUnitDivider;
const premiumPPUdivider2: number = config.PremiumStorage.PricePerUnitDivider2;

return (PPU / PPUdivider / PPUdivider2) * timeConsumption * GBQuantity;
return (
(PPU / PPUdivider / PPUdivider2) * timeConsumption * GBQuantity +
(premiumPPU / premiumPPUdivider / premiumPPUdivider2) *
timeConsumption *
premiumGBQuantity
);
}
22 changes: 13 additions & 9 deletions src/calculatorFunctions/totalCosts/calculateTotalCosts.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import calculateBaseConfigCosts from '../baseConfigCosts/calculateBaseConfigCosts';
import calculateNodeCosts from '../nodeCosts/calculateNodeCosts';
import calculateStorageCosts from '../storageCosts/calculateStorageCosts';
import calculateTotalCosts from './calculateTotalCosts';

Expand All @@ -8,28 +7,33 @@ test('total costs', () => {
const minAutoscaler = 3;
const timeConsumption = 450;
const vmMultiplier = 4; // 16 CPU 64gb RAM
// Node
const vmQuantity = 3;
const machineTypeFactor = 1;
// Storage
const GBQuantity = 1024;
const premiumGBQuantity = 1024;

const conversionRatio = 0.35;
const additionalCosts = 1;

const baseConfigCosts = calculateBaseConfigCosts({
timeConsumption,
vmMultiplier,
minAutoscaler,
machineTypeFactor,
});
const nodeCosts = calculateNodeCosts({
vmQuantity,
vmMultiplier,
const storageCosts = calculateStorageCosts({
GBQuantity,
premiumGBQuantity,
timeConsumption,
});
const storageCosts = calculateStorageCosts({ GBQuantity, timeConsumption });

const totalCosts = calculateTotalCosts({
baseConfigCosts,
nodeCosts,
storageCosts,
additionalCosts,
conversionRatio,
});

expect(totalCosts).toBe(5515);
expect(totalCosts.CU).toBe(3701);
expect(totalCosts.CC).toBe(1295.35);
});
20 changes: 15 additions & 5 deletions src/calculatorFunctions/totalCosts/calculateTotalCosts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
interface Props {
export interface TotalCostsProps {
baseConfigCosts: number;
nodeCosts: number;
storageCosts: number;
additionalCosts: number;
conversionRatio: number;
}

export default function calculateTotalCosts(props: Props): number {
const { baseConfigCosts, nodeCosts, storageCosts } = props;
return baseConfigCosts + nodeCosts + storageCosts;
export interface TotalCosts {
CU: number;
CC: number;
}

export default function calculateTotalCosts(
props: TotalCostsProps,
): TotalCosts {
const { baseConfigCosts, storageCosts, additionalCosts, conversionRatio } =
props;
const costInCU = baseConfigCosts + storageCosts + additionalCosts;
return { CU: costInCU, CC: costInCU * conversionRatio };
}
12 changes: 3 additions & 9 deletions src/components/CostWizard/Buttons/CSVDownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { baseConfigCostsState } from '../../../state/costs/baseConfigCostsState'
import { timeConsumptionBaseConfigState } from '../../../state/baseConfig/timeConsumptionState';
import { VMSize, VMsizeState } from '../../../state/baseConfig/VMsizeState';
import { minAutoscalerState } from '../../../state/baseConfig/minAutoscalerState';
import { nodeCostsState } from '../../../state/costs/nodeCostsState';
import { timeConsumptionNodeState } from '../../../state/node/timeConsumptionState';
import { storageCostsState } from '../../../state/costs/storageCostsState';
import { GBQuantityState } from '../../../state/storage/GBQuantityState';
import { timeConsumptionStorageState } from '../../../state/storage/timeConsumptionState';
import { additionalCostsState } from '../../../state/costs/additionalCostsState';
import { totalCostsState } from '../../../state/costs/totalCostsState';
import { VMQuantityState } from '../../../state/node/VMQuantityState';
import './DownloadButton.css';
import '@ui5/webcomponents-icons/dist/download.js';
import exportCSV from '../Functions/exportCSV';
Expand All @@ -23,14 +21,12 @@ export default function CSVDownloadButton() {
const baseTime: number = useRecoilValue<number>(
timeConsumptionBaseConfigState,
);
const nodeCosts: number = useRecoilValue<number>(nodeCostsState);
const vmQuantity: number = useRecoilValue<number>(VMQuantityState);
const nodeTime: number = useRecoilValue<number>(timeConsumptionNodeState);
const storageCosts: number = useRecoilValue<number>(storageCostsState);
const storageQuantity: number = useRecoilValue<number>(GBQuantityState);
const storageTime: number = useRecoilValue<number>(
timeConsumptionStorageState,
);
const additionalCosts: number = useRecoilValue<number>(additionalCostsState);
const totalCosts = useRecoilValue<number>(totalCostsState);

return (
Expand All @@ -43,12 +39,10 @@ export default function CSVDownloadButton() {
baseTime,
baseVMSize,
baseMinAutoscaler,
nodeCosts,
vmQuantity,
nodeTime,
storageCosts,
storageQuantity,
storageTime,
additionalCosts,
totalCosts,
})
}
Expand Down
12 changes: 3 additions & 9 deletions src/components/CostWizard/Buttons/XlsxDownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import { baseConfigCostsState } from '../../../state/costs/baseConfigCostsState'
import { timeConsumptionBaseConfigState } from '../../../state/baseConfig/timeConsumptionState';
import { VMSize, VMsizeState } from '../../../state/baseConfig/VMsizeState';
import { minAutoscalerState } from '../../../state/baseConfig/minAutoscalerState';
import { nodeCostsState } from '../../../state/costs/nodeCostsState';
import { timeConsumptionNodeState } from '../../../state/node/timeConsumptionState';
import { storageCostsState } from '../../../state/costs/storageCostsState';
import { GBQuantityState } from '../../../state/storage/GBQuantityState';
import { timeConsumptionStorageState } from '../../../state/storage/timeConsumptionState';
import { totalCostsState } from '../../../state/costs/totalCostsState';
import { VMQuantityState } from '../../../state/node/VMQuantityState';
import './DownloadButton.css';
import '@ui5/webcomponents-icons/dist/download.js';
import exportXLSX from '../Functions/exportXLSX';
import { additionalCostsState } from '../../../state/costs/additionalCostsState';

export default function XlsxDownloadButton() {
const baseCosts: number = useRecoilValue<number>(baseConfigCostsState);
Expand All @@ -23,11 +21,9 @@ export default function XlsxDownloadButton() {
const baseTime: number = useRecoilValue<number>(
timeConsumptionBaseConfigState,
);
const nodeCosts: number = useRecoilValue<number>(nodeCostsState);
const vmQuantity: number = useRecoilValue<number>(VMQuantityState);
const nodeTime: number = useRecoilValue<number>(timeConsumptionNodeState);
const storageCosts: number = useRecoilValue<number>(storageCostsState);
const storageQuantity: number = useRecoilValue<number>(GBQuantityState);
const additionalCosts: number = useRecoilValue<number>(additionalCostsState);
const storageTime: number = useRecoilValue<number>(
timeConsumptionStorageState,
);
Expand All @@ -42,12 +38,10 @@ export default function XlsxDownloadButton() {
baseTime,
baseVMSize,
baseMinAutoscaler,
nodeCosts,
vmQuantity,
nodeTime,
storageCosts,
storageQuantity,
storageTime,
additionalCosts,
totalCosts,
})
}
Expand Down
1 change: 1 addition & 0 deletions src/components/CostWizard/CostWizard.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#CostWizard {
height: 600px;
overflow-x: hidden;
}

.ButtonContainer {
Expand Down
4 changes: 2 additions & 2 deletions src/components/CostWizard/CostWizard.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
import { Wizard } from '@ui5/webcomponents-react';
import BaseConfigStep from './WizardSteps/BaseConfigStep';
import NodeStep from './WizardSteps/NodeStep';
import AdditionalConfig from './WizardSteps/AdditionalConfig';
import StorageStep from './WizardSteps/StorageStep';
import './CostWizard.css';

export default function CostWizard() {
return (
<Wizard id="CostWizard">
<BaseConfigStep />
<NodeStep />
<StorageStep />
<AdditionalConfig />
</Wizard>
);
}
Loading

0 comments on commit 557f805

Please sign in to comment.