Skip to content
Snippets Groups Projects
Commit 9ca47c44 authored by Gomez Goiri, Aitor's avatar Gomez Goiri, Aitor
Browse files

Estimating composition ranges after aggregating slags

parent ca89295d
Branches
No related tags found
No related merge requests found
......@@ -27,7 +27,10 @@ const signInAs = async (apiClient, userMail, password) => {
const createAssetAndSendToCone = async (apiClient, name) => {
const assetId = await createAsset(apiClient, name)
await editComposition(apiClient, { assetId })
await editComposition(apiClient, {
assetId,
caoPercentage: faker.datatype.number({ min: 40, max: 70 })
})
return sendToCone(apiClient, { assetId })
}
......
......@@ -15,7 +15,7 @@ const createAsset = async (apiClient, { assetName }) => {
id: `asst_${faker.datatype.uuid()}`,
type: TYPES.RESIDUO_PROCESOS_TERMICOS,
units: "kg",
quantity: faker.datatype.number({ min: 0, max: 5000 }),
quantity: faker.datatype.number({ min: 400, max: 5000 }),
fields: {
description: "Escoria",
name: assetName,
......@@ -69,6 +69,24 @@ const editComposition = async (
console.log("New composition measure for", assetId)
}
const updateBatchRange = (batch = {}, individualSlag = {}) => {
const { cao = null } = (individualSlag.fields || {}).composition || {}
const { cao: caoRange = null } = (batch.fields || {}).composition || {}
if (cao === null) {
return caoRange
}
if (caoRange === null) {
return { min: cao, max: cao }
}
return {
min: cao < caoRange.min ? cao : caoRange.min,
max: cao > caoRange.max ? cao : caoRange.max
}
}
const sendToCone = async (apiClient, { assetId: paramAssetId }) => {
const assetId =
paramAssetId ||
......@@ -81,13 +99,12 @@ const sendToCone = async (apiClient, { assetId: paramAssetId }) => {
))
const assetToBeSent = await apiClient.getAsset(assetId)
const assetsInCone = await apiClient.richQuery({
const [firstAsset = false] = await apiClient.richQuery({
fields: {
status: STATUSES.SLAG_BATCH
}
})
const [firstAsset] = assetsInCone
const newConeQuantity =
assetToBeSent.quantity + (firstAsset ? firstAsset.quantity : 0)
......@@ -97,29 +114,50 @@ const sendToCone = async (apiClient, { assetId: paramAssetId }) => {
{ parentsShouldExist: false, bidirectional: true },
{
type: TYPES.RESIDUO_HIERRO_ACERO,
location:
assetsInCone.length === 0
? assetToBeSent.location
: assetsInCone[0].location,
location: firstAsset ? firstAsset.location : assetToBeSent.location,
units: "kg",
quantity: newConeQuantity,
fields: {
name: "Slag batch (in cone)",
status: STATUSES.SLAG_BATCH
status: STATUSES.SLAG_BATCH,
composition: {
cao: updateBatchRange(firstAsset, assetToBeSent)
}
}
}
)
// Archive individual slag and previous cone
await apiClient.deleteAsset(assetId)
if (assetsInCone.length > 0) await apiClient.deleteAsset(assetsInCone[0].id)
if (firstAsset) await apiClient.deleteAsset(firstAsset.id)
console.log("Moved to cone", coneAsset.id)
return coneAsset.id
}
const sendToStock = async (apiClient, { assetId: paramAssetId }) => {
const updateStockRange = (stock = {}, batch = {}) => {
const { cao: caoRange = null } = (stock.fields || {}).composition || {}
const { cao: newCaoRange = null } = (batch.fields || {}).composition || {}
if (caoRange === null) {
return newCaoRange
}
if (newCaoRange === null) {
return caoRange
}
return {
min: newCaoRange.min < caoRange.min ? newCaoRange.min : caoRange.min,
max: newCaoRange.max > caoRange.max ? newCaoRange.max : caoRange.max
}
}
const sendToStock = async (
apiClient,
{ assetId: paramAssetId, stockId: paramStockId }
) => {
const assetId =
paramAssetId ||
(await promptAssetSelection(
......@@ -136,7 +174,9 @@ const sendToStock = async (apiClient, { assetId: paramAssetId }) => {
return
}
const selectedStockId = await promptAssetSelection(
const selectedStockId =
paramStockId ||
(await promptAssetSelection(
[
...(await apiClient.richQuery({
fields: {
......@@ -150,14 +190,14 @@ const sendToStock = async (apiClient, { assetId: paramAssetId }) => {
}
],
"Select the stock where the cone will be merged"
)
))
if (!selectedStockId) {
console.error("You must select a stock")
return
}
let previousStock = false
let previousStock = undefined
if (selectedStockId !== "newStock") {
previousStock = await apiClient.getAsset(selectedStockId)
}
......@@ -179,7 +219,10 @@ const sendToStock = async (apiClient, { assetId: paramAssetId }) => {
quantity: newStockQuantity,
fields: {
status: STATUSES.STOCK,
name: "Stock"
name: "Stock",
composition: {
cao: updateStockRange(previousStock, assetToBeSent)
}
}
}
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment