refacto: remove planning state

This commit is contained in:
Julien Calixte
2026-01-03 11:23:51 +01:00
parent c648fe49a6
commit 1accacdac1
2 changed files with 28 additions and 25 deletions

View File

@@ -19,7 +19,7 @@ import OrderItem from '@/modules/heijkunka/assets/OrderItem.vue'
const days = Array.from({ length: NUMBER_OF_DAYS }, (_, i) => i + 1) const days = Array.from({ length: NUMBER_OF_DAYS }, (_, i) => i + 1)
const hours = Array.from({ length: NUMBER_OF_HOURS_PER_DAY }, (_, i) => i + 1) const hours = Array.from({ length: NUMBER_OF_HOURS_PER_DAY }, (_, i) => i + 1)
const orders = ref( const planning = ref(
Array.from( Array.from(
{ length: days.length * hours.length }, { length: days.length * hours.length },
(): ProductType => pickRandomElement(['shirt', 'jeans', 'shoes', 'hat']) (): ProductType => pickRandomElement(['shirt', 'jeans', 'shoes', 'hat'])
@@ -56,7 +56,7 @@ const levelingPlanning: ProductType[] = [
'jeans' 'jeans'
] ]
const orderIndex = (dayIndex: number, hourIndex: number) => { const planningIndex = (dayIndex: number, hourIndex: number) => {
return dayIndex * hours.length + hourIndex return dayIndex * hours.length + hourIndex
} }
@@ -121,7 +121,7 @@ const createdAt = new Date('2026-01-01').toLocaleDateString(undefined, {
<th scope="row">day {{ day }}</th> <th scope="row">day {{ day }}</th>
<td v-for="(hour, hourIndex) in hours"> <td v-for="(hour, hourIndex) in hours">
<select <select
v-model="orders[orderIndex(dayIndex, hourIndex)]" v-model="planning[planningIndex(dayIndex, hourIndex)]"
:name="`day-${day}-hour-${hour}`" :name="`day-${day}-hour-${hour}`"
:id="`day-${day}-hour-${hour}`" :id="`day-${day}-hour-${hour}`"
> >
@@ -137,7 +137,7 @@ const createdAt = new Date('2026-01-01').toLocaleDateString(undefined, {
</section> </section>
<section class="commands"> <section class="commands">
<button class="button-outline" @click="heijunkaStore.newHour()"> <button class="button-outline" @click="heijunkaStore.newHour(planning)">
next hour next hour
<!-- <!--
<svg <svg
@@ -161,7 +161,7 @@ const createdAt = new Date('2026-01-01').toLocaleDateString(undefined, {
reset reset
</button> </button>
<button class="button-outline" @click="orders = [...levelingPlanning]"> <button class="button-outline" @click="planning = [...levelingPlanning]">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width="24" width="24"
@@ -184,7 +184,7 @@ const createdAt = new Date('2026-01-01').toLocaleDateString(undefined, {
</svg> </svg>
levelling levelling
</button> </button>
<button class="button-outline" @click="orders = [...batchPlanning]"> <button class="button-outline" @click="planning = [...batchPlanning]">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width="24" width="24"
@@ -200,7 +200,10 @@ const createdAt = new Date('2026-01-01').toLocaleDateString(undefined, {
</svg> </svg>
batch batch
</button> </button>
<button class="button-outline" @click="heijunkaStore.simulateMonth()"> <button
class="button-outline"
@click="heijunkaStore.simulateMonth(planning)"
>
simulate a month simulate a month
</button> </button>
</section> </section>
@@ -270,7 +273,7 @@ const createdAt = new Date('2026-01-01').toLocaleDateString(undefined, {
<OrderItem /> <OrderItem />
<span class="numeric"> <span class="numeric">
{{ order.product }} | {{ order.leadTime }} {{ order.product }} {{ order.leadTime }}
</span> </span>
</li> </li>
</ol> </ol>
@@ -319,7 +322,11 @@ const createdAt = new Date('2026-01-01').toLocaleDateString(undefined, {
what you can make per day. what you can make per day.
</p> </p>
<h2>Heijunka is fun</h2> <h2>Heijunka is fun</h2>
<p>There's no ///</p> <p>
For craftspersonns, there's no such thing repeating over and over again
the making of the same product - even if you love doing it - work needs
diversity. This is what the heijunka adds by doing a bit of everything.
</p>
</article> </article>
</template> </template>
@@ -352,6 +359,11 @@ li {
border: 2px solid var(--primary-color); border: 2px solid var(--primary-color);
border-radius: 1rem; border-radius: 1rem;
padding: 0 0.5rem; padding: 0 0.5rem;
width: 100%;
h2 {
text-align: center;
}
& > div { & > div {
flex: 1; flex: 1;

View File

@@ -23,7 +23,6 @@ type HeijunkaState = {
money: number money: number
inventory: Inventory inventory: Inventory
orders: Order[] orders: Order[]
planning: ProductType[]
meta: { meta: {
currentHour: number currentHour: number
} }
@@ -56,18 +55,12 @@ export const useHeijunkaStore = defineStore('heijunka', {
money: 100, money: 100,
inventory: { ...initialInventory }, inventory: { ...initialInventory },
orders: [], orders: [],
planning: [],
meta: { meta: {
currentHour: 0 currentHour: 0
} }
}), }),
actions: { actions: {
newHour() { newHour(planning: ProductType[]) {
// End of the production
if (this.gameEnded) {
return
}
this.meta.currentHour++ this.meta.currentHour++
// Add to inventory every day // Add to inventory every day
@@ -75,16 +68,16 @@ export const useHeijunkaStore = defineStore('heijunka', {
this.inventory = { this.inventory = {
shirt: shirt:
this.inventory.shirt + this.inventory.shirt +
getInventoryByProduct('shirt', this.planning, this.currentDay), getInventoryByProduct('shirt', planning, this.currentDay),
jeans: jeans:
this.inventory.jeans + this.inventory.jeans +
getInventoryByProduct('jeans', this.planning, this.currentDay), getInventoryByProduct('jeans', planning, this.currentDay),
shoes: shoes:
this.inventory.shoes + this.inventory.shoes +
getInventoryByProduct('shoes', this.planning, this.currentDay), getInventoryByProduct('shoes', planning, this.currentDay),
hat: hat:
this.inventory.hat + this.inventory.hat +
getInventoryByProduct('hat', this.planning, this.currentDay) getInventoryByProduct('hat', planning, this.currentDay)
} }
} }
@@ -136,13 +129,12 @@ export const useHeijunkaStore = defineStore('heijunka', {
}, },
reset() { reset() {
this.meta.currentHour = 0 this.meta.currentHour = 0
this.planning = []
this.orders = [] this.orders = []
this.inventory = { ...initialInventory } this.inventory = { ...initialInventory }
}, },
simulateMonth() { simulateMonth(planning: ProductType[]) {
for (let index = 0; index < 80; index++) { for (let index = 0; index < 80; index++) {
this.newHour() this.newHour(planning)
} }
} }
}, },
@@ -171,7 +163,6 @@ export const useHeijunkaStore = defineStore('heijunka', {
0 0
) )
}), }),
gameEnded: () => false,
// state.meta.currentHour >= NUMBER_OF_DAYS * NUMBER_OF_HOURS_PER_DAY, // state.meta.currentHour >= NUMBER_OF_DAYS * NUMBER_OF_HOURS_PER_DAY,
meanLeadTime: (state) => getMean(state.orders.map((o) => o.leadTime)) meanLeadTime: (state) => getMean(state.orders.map((o) => o.leadTime))
} }