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