Last active
December 15, 2021 10:34
-
-
Save muratgozel/177599fa6a6edd26429c337fa9d4eaa0 to your computer and use it in GitHub Desktop.
Sheet size and cost computation of the machine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function constants() { | |
const data = { | |
T: { // levha kalınlıkları | |
single: 3, | |
double: 5 | |
}, | |
tCostFactor: { // levha maliyetleri | |
single: 5.5, | |
double: 8.5 | |
}, | |
widthRange: [ | |
800, 900, 1000, 1100, 1200, 1300, 1400, 1500 | |
], | |
cutMargin: 3, // kesim payı, bulunan en'e eklenir. | |
expenseFactor: 2.6, // m2 başına genel giderler | |
profitFactor: 1.25 // kar faktörü | |
} | |
const validkeys = Object.keys(data) | |
function configure(obj) { | |
validkeys.map(function(k) { | |
if (obj.hasOwnProperty(k)) data[k] = obj[k] | |
}) | |
} | |
return Object.assign({}, data, {configure: configure}) | |
} | |
export default constants() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import models from './models' | |
import constants from './constants' | |
function computeSheetSizes({w, h, l, isDouble, model}) { | |
const t = isDouble ? constants.T.double : constants.T.single | |
const tCostFactor = constants.tCostFactor[isDouble ? 'double' : 'single'] | |
const a = h+13 | |
const computedWidth = model.widthFn(h*10, w*10, l*10, t, a) + constants.cutMargin | |
const computedHeight = model.heightFn(h*10, w*10, l*10, t, a) | |
const techDeficit = 10 - computedWidth%10 | |
const actualWidth = techDeficit < 10 ? computedWidth + techDeficit : computedWidth | |
if (actualWidth > Math.max.apply(Math, constants.widthRange)) { | |
return {error: 'Lütfen daha küçük ölçüler deneyin.'} | |
} | |
const minRemaining = Math.min.apply(Math, | |
constants.widthRange.filter(wi => wi > actualWidth).map(wi => wi % actualWidth)) | |
const inputMaterialWidth = constants.widthRange.filter(wi => wi % actualWidth == minRemaining)[0] | |
const costlyWidth = Math.ceil(inputMaterialWidth / Math.floor(inputMaterialWidth / actualWidth)) | |
return { | |
sheetWidth: costlyWidth, | |
sheetHeight: computedHeight, | |
thickness: t, | |
thicknessCostFactor: tCostFactor | |
} | |
} | |
function computeCost({qty, sheetWidth, sheetHeight, thicknessCostFactor}) { | |
return qty * constants.profitFactor * ( | |
(sheetWidth/1000) * (sheetHeight/1000) * (thicknessCostFactor + constants.expenseFactor) | |
) | |
} | |
export { | |
constants, | |
models, | |
computeSheetSizes, | |
computeCost | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {asset} from '@frondjs/frond' | |
import {Parser} from 'expr-eval' | |
import cms from '../../cms' | |
const parser = new Parser() | |
function models() { | |
const list = [] | |
function configure(products) { | |
products.map(function(p) { | |
const up = cms.getProductMediaByTag(p.id, 'Cover', {fallbackToImage: asset.get('no-img.png')}) | |
list.push({ | |
id: p.id, | |
code: p.code, | |
name: p.name, | |
media: [ | |
typeof up == 'string' ? up : cms.getAssetLink(up.outputs_by_tag.t.src) | |
], | |
widthFn: function(h, b, l, t, a) { | |
return parser.parse(p.attributes['En Formülü']).evaluate({ h, b, l, t, a }) | |
}, | |
heightFn: function(h, b, l, t, a) { | |
return parser.parse(p.attributes['Boy Formülü']).evaluate({ h, b, l, t, a }) | |
}, | |
desiFn: function(w, l, t, qty) { | |
return parser.parse(p.attributes['Desi Formülü']).evaluate({w, l, t, qty}) | |
} | |
}) | |
}) | |
} | |
return { | |
configure: configure, | |
list: list | |
} | |
} | |
export default models() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment