Skip to content

Commit

Permalink
add demand spec
Browse files Browse the repository at this point in the history
  • Loading branch information
timkoopmans committed Feb 4, 2025
1 parent 38fb549 commit a520512
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ function calculateProvisionedCosts() {
cfg.dynamoCostProvisioned = cfg.dynamoCostProvisionedMonthly + cfg.dynamoCostProvisionedUpfront / 12;
}

function calculateDemandCosts() {
export function calculateDemandCosts() {
cfg.readRequestUnitsPerItem = Math.ceil(cfg.itemSizeKB / 4.0);
cfg.writeRequestUnitsPerItem = Math.ceil(cfg.itemSizeKB);

cfg.numberReads = cfg.demand * cfg.readRatio * 3600 * cfg.hoursPerMonth;
cfg.readRequestUnits = (cfg.numberReads * cfg.readEventuallyConsistent * 0.5 * cfg.readRequestUnitsPerItem) +
(cfg.numberReads * cfg.readStronglyConsistent * cfg.readRequestUnitsPerItem) +
Expand Down
37 changes: 36 additions & 1 deletion src/calculator.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { calculateStorageCost } from './calculator.js';
import {calculateStorageCost, calculateDemandCosts, updateCosts} from './calculator.js';
import { cfg } from './config.js';

jest.mock('./chart.js', () => ({
Expand Down Expand Up @@ -35,4 +35,39 @@ describe('calculateStorageCost', () => {
calculateStorageCost();
expect(cfg.dynamoCostStorage).toBe(12.625);
});
});

describe('calculateDemandCosts', () => {
beforeEach(() => {
cfg.pricing = 'demand';
cfg.storageGB = 2048;
cfg.tableClass = 'standard';
cfg.itemSizeB = 1024;
cfg.demand = 100_000;
cfg.readRatio = 0.80;
cfg.writeRatio = 0.20;
cfg.itemSizeKB = cfg.itemSizeB * (1 / 1024);
cfg.itemSizeKB = cfg.itemSizeKB > 1 ? Math.floor(cfg.itemSizeKB) : cfg.itemSizeKB;
cfg.readStronglyConsistent = 1;
cfg.readEventuallyConsistent = 0;
cfg.readTransactional = 0;
cfg.readNonTransactional = 1;
cfg.writeTransactional = 0;
cfg.writeNonTransactional = 1;
cfg.dynamoCostStorage = 0;
cfg.dynamoCostDemandReads = 0;
cfg.dynamoCostDemandWrites = 0;
cfg.dynamoCostTotal = 0;
});

it('should calculate the correct demand costs', () => {
calculateDemandCosts();
calculateStorageCost();

expect(cfg.dynamoCostStorage.toFixed(2)).toBe("512.00");
expect(cfg.dynamoCostDemandReads.toFixed(2)).toBe( "26280.00");
expect(cfg.dynamoCostDemandWrites.toFixed(2)).toBe("32850.00");
cfg.dynamoCostTotal = cfg.dynamoCostStorage + cfg.dynamoCostDemandReads + cfg.dynamoCostDemandWrites;
expect(cfg.dynamoCostTotal.toFixed(2)).toBe("59642.00");
});
});

0 comments on commit a520512

Please sign in to comment.