From e6e0cb8cb0e78c990fb480ef322753a6ad3a8a1b Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Fri, 2 Jan 2026 10:43:44 +0100 Subject: [PATCH] fix: with modulos we need to offset by 1 the result --- src/modules/heijkunka/heijunka-store.ts | 28 ++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/modules/heijkunka/heijunka-store.ts b/src/modules/heijkunka/heijunka-store.ts index 7d3c1d6..698c27c 100644 --- a/src/modules/heijkunka/heijunka-store.ts +++ b/src/modules/heijkunka/heijunka-store.ts @@ -37,8 +37,8 @@ const getInventoryByProduct = ( ): number => { const inventory = planning.filter( (p, index) => - index >= ((currentDay % NUMBER_OF_DAYS) - 1) * NUMBER_OF_HOURS_PER_DAY && - index < (currentDay % NUMBER_OF_DAYS) * NUMBER_OF_HOURS_PER_DAY && + index >= (currentDay % NUMBER_OF_DAYS) * NUMBER_OF_HOURS_PER_DAY && + index < ((currentDay % NUMBER_OF_DAYS) + 1) * NUMBER_OF_HOURS_PER_DAY && p === product ).length @@ -148,7 +148,7 @@ export const useHeijunkaStore = defineStore('heijunka', { this.inventory = { ...initialInventory } }, simulateMonth() { - for (let index = 0; index < 30; index++) { + for (let index = 0; index < 80; index++) { this.newHour() } } @@ -156,6 +156,28 @@ export const useHeijunkaStore = defineStore('heijunka', { getters: { currentDay: (state) => Math.ceil(state.meta.currentHour / NUMBER_OF_HOURS_PER_DAY), + remainingInventory: (state): Inventory => ({ + shirt: Math.max( + state.inventory.shirt - + state.orders.filter((o) => o.product === 'shirt').length, + 0 + ), + jeans: Math.max( + state.inventory.jeans - + state.orders.filter((o) => o.product === 'jeans').length, + 0 + ), + shoes: Math.max( + state.inventory.shoes - + state.orders.filter((o) => o.product === 'shoes').length, + 0 + ), + hat: Math.max( + state.inventory.hat - + state.orders.filter((o) => o.product === 'hat').length, + 0 + ) + }), gameEnded: () => false, // state.meta.currentHour >= NUMBER_OF_DAYS * NUMBER_OF_HOURS_PER_DAY, meanLeadTime: (state) => getMean(state.orders.map((o) => o.leadTime))