add mean time
This commit is contained in:
@@ -20,6 +20,21 @@ const orders = ref(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const levelingPlanning: ProductType[] = [
|
||||||
|
'shirt',
|
||||||
|
'shirt',
|
||||||
|
'jeans',
|
||||||
|
'shoes',
|
||||||
|
'hat',
|
||||||
|
'shirt',
|
||||||
|
'shirt',
|
||||||
|
'jeans',
|
||||||
|
'shoes',
|
||||||
|
'hat',
|
||||||
|
'shirt',
|
||||||
|
'jeans'
|
||||||
|
]
|
||||||
|
|
||||||
const orderIndex = (dayIndex: number, hourIndex: number) => {
|
const orderIndex = (dayIndex: number, hourIndex: number) => {
|
||||||
return dayIndex * hoursCount + hourIndex
|
return dayIndex * hoursCount + hourIndex
|
||||||
}
|
}
|
||||||
@@ -86,6 +101,10 @@ const createdAt = new Date('2026-01-01').toLocaleDateString(undefined, {
|
|||||||
<button class="button-outline" @click="heijunkaStore.reset()">
|
<button class="button-outline" @click="heijunkaStore.reset()">
|
||||||
reset
|
reset
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button class="button-outline" @click="orders = levelingPlanning">
|
||||||
|
levelling
|
||||||
|
</button>
|
||||||
</section>
|
</section>
|
||||||
<section class="factory">
|
<section class="factory">
|
||||||
<h2>Factory</h2>
|
<h2>Factory</h2>
|
||||||
@@ -286,6 +305,10 @@ const createdAt = new Date('2026-01-01').toLocaleDateString(undefined, {
|
|||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section class="dashboard">
|
||||||
|
Mean lead time: {{ heijunkaStore.meanLeadTime }}
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
NUMBER_OF_HOURS_PER_DAY
|
NUMBER_OF_HOURS_PER_DAY
|
||||||
} from '@/modules/heijkunka/heijunka-config'
|
} from '@/modules/heijkunka/heijunka-config'
|
||||||
import { ProductType } from '@/modules/heijkunka/types/product-type'
|
import { ProductType } from '@/modules/heijkunka/types/product-type'
|
||||||
import { pickRandomElement } from '@/utils'
|
import { getMean, pickRandomElement } from '@/utils'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
type Order = {
|
type Order = {
|
||||||
@@ -12,7 +12,7 @@ type Order = {
|
|||||||
product: ProductType
|
product: ProductType
|
||||||
}
|
}
|
||||||
|
|
||||||
type Stock = {
|
type Inventory = {
|
||||||
shirt: number
|
shirt: number
|
||||||
jeans: number
|
jeans: number
|
||||||
shoes: number
|
shoes: number
|
||||||
@@ -21,7 +21,7 @@ type Stock = {
|
|||||||
|
|
||||||
type HeijunkaState = {
|
type HeijunkaState = {
|
||||||
money: number
|
money: number
|
||||||
inventory: Stock
|
inventory: Inventory
|
||||||
orders: Order[]
|
orders: Order[]
|
||||||
planning: ProductType[]
|
planning: ProductType[]
|
||||||
validatedPlanning: boolean
|
validatedPlanning: boolean
|
||||||
@@ -30,22 +30,22 @@ type HeijunkaState = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStockByProduct = (
|
const getInventoryByProduct = (
|
||||||
product: ProductType,
|
product: ProductType,
|
||||||
planning: ProductType[],
|
planning: ProductType[],
|
||||||
currentDay: number
|
currentDay: number
|
||||||
): number => {
|
): number => {
|
||||||
const stock = planning.filter(
|
const inventory = planning.filter(
|
||||||
(p, index) =>
|
(p, index) =>
|
||||||
index >= (currentDay - 1) * NUMBER_OF_HOURS_PER_DAY &&
|
index >= (currentDay - 1) * NUMBER_OF_HOURS_PER_DAY &&
|
||||||
index < currentDay * NUMBER_OF_HOURS_PER_DAY &&
|
index < currentDay * NUMBER_OF_HOURS_PER_DAY &&
|
||||||
p === product
|
p === product
|
||||||
).length
|
).length
|
||||||
|
|
||||||
return stock
|
return inventory
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialInventory: Stock = {
|
const initialInventory: Inventory = {
|
||||||
shirt: 0,
|
shirt: 0,
|
||||||
jeans: 0,
|
jeans: 0,
|
||||||
shoes: 0,
|
shoes: 0,
|
||||||
@@ -72,21 +72,21 @@ export const useHeijunkaStore = defineStore('heijunka', {
|
|||||||
|
|
||||||
this.meta.currentHour++
|
this.meta.currentHour++
|
||||||
|
|
||||||
// Add to stock every day
|
// Add to inventory every day
|
||||||
if (this.meta.currentHour % NUMBER_OF_HOURS_PER_DAY === 0) {
|
if (this.meta.currentHour % NUMBER_OF_HOURS_PER_DAY === 0) {
|
||||||
this.inventory = {
|
this.inventory = {
|
||||||
shirt:
|
shirt:
|
||||||
this.inventory.shirt +
|
this.inventory.shirt +
|
||||||
getStockByProduct('shirt', this.planning, this.currentDay),
|
getInventoryByProduct('shirt', this.planning, this.currentDay),
|
||||||
jeans:
|
jeans:
|
||||||
this.inventory.jeans +
|
this.inventory.jeans +
|
||||||
getStockByProduct('jeans', this.planning, this.currentDay),
|
getInventoryByProduct('jeans', this.planning, this.currentDay),
|
||||||
shoes:
|
shoes:
|
||||||
this.inventory.shoes +
|
this.inventory.shoes +
|
||||||
getStockByProduct('shoes', this.planning, this.currentDay),
|
getInventoryByProduct('shoes', this.planning, this.currentDay),
|
||||||
hat:
|
hat:
|
||||||
this.inventory.hat +
|
this.inventory.hat +
|
||||||
getStockByProduct('hat', this.planning, this.currentDay)
|
getInventoryByProduct('hat', this.planning, this.currentDay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,9 +117,9 @@ export const useHeijunkaStore = defineStore('heijunka', {
|
|||||||
|
|
||||||
// Use the inventory to deliver orders
|
// Use the inventory to deliver orders
|
||||||
this.orders = this.orders.map((order, index): Order => {
|
this.orders = this.orders.map((order, index): Order => {
|
||||||
const stock = this.inventory[order.product]
|
const productInventory = this.inventory[order.product]
|
||||||
|
|
||||||
if (stock === 0) {
|
if (productInventory === 0) {
|
||||||
return order
|
return order
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,8 @@ export const useHeijunkaStore = defineStore('heijunka', {
|
|||||||
(o, i) => i < index && o.product !== order.product
|
(o, i) => i < index && o.product !== order.product
|
||||||
).length
|
).length
|
||||||
|
|
||||||
const newStatus = index - offset < stock ? 'received' : 'requested'
|
const newStatus =
|
||||||
|
index - offset < productInventory ? 'received' : 'requested'
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...order,
|
...order,
|
||||||
@@ -151,6 +152,12 @@ export const useHeijunkaStore = defineStore('heijunka', {
|
|||||||
currentDay: (state) =>
|
currentDay: (state) =>
|
||||||
Math.ceil(state.meta.currentHour / NUMBER_OF_HOURS_PER_DAY),
|
Math.ceil(state.meta.currentHour / NUMBER_OF_HOURS_PER_DAY),
|
||||||
gameEnded: (state) =>
|
gameEnded: (state) =>
|
||||||
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
|
||||||
|
.filter((o) => o.status === 'received')
|
||||||
|
.map((o) => o.leadTime)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user