Service - Transform Units: Difference between revisions

From Izara Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 37: Line 37:
calculatedProperties: { // calculates a property added to the outputUnits
calculatedProperties: { // calculates a property added to the outputUnits
{propertyName}: {
{propertyName}: {
calculationType: "multiplyQuantityValue", // can add other types later
calculationType: "calculateValue", // can add other types later
multipleByProperties: [ // can set many inputType properties, all products get summed
combinationEquation: "[propertyA]+[propertyB]", // optional, method of combining multiple calculateByProperties together, defaults to adding/sum
calculateByProperties: [ // can set many inputType properties
{
{
inputUnitTypeId: "xxx",
inputUnitTypeId: "xxx", // different unitTypeIds can have different properties/calculations
propertyName: "xxx", // property that gets multiplied with the quantity of that Unit used for each outputUnit
propertyName: "xxx", // property that gets inserted into calculation
calculation: "[property]*[quantity]",
},
},
// ..
// ..
Line 53: Line 55:
}
}
</syntaxhighlight>
</syntaxhighlight>
== Calculating values ==
combinationEquation and calculateByProperties.calculation fields replace out special tags first like [propertyA]/[propertyB]/[property]/[quantity], the parse through an evaluation library, eg:
* https://mathjs.org/
* https://www.npmjs.com/package/string-math
* https://www.npmjs.com/package/exact-math
* https://www.codeproject.com/Articles/12116/JavaScript-Mathematical-Expression-Evaluator
Must make sure equation is validated/sanitized first, be careful of eval or new Function which can invoke arbritrary commands


= Transform request =
= Transform request =

Latest revision as of 13:22, 12 August 2023

Overview

Transformations are used to convert a number of input Units into sets of output Units.

Repository

https://bitbucket.org/izara-supply-units/izara-supply-units-transform-units

DynamoDB tables

Standard Config Table Per Service

Configuration tags

{
	configTag: "SupplyGraphServiceName"
	configKey: "SupplyGraphServiceName"
	configValue: xxx // eg: "SupplyGraph"
}

transformConfig structure

{
	inputUnitTypes: {
		{unitTypeId}: {
			stageId: "xx", // optional stage that Units get updated to
			quantityProperty: "xx", // optional, name of property that is used as quantity to spread across output Units, if none set then quantity is 1
			splitIntegerOnly: false, // default false, if true splits can only be integers, will not process transformation if split per outputUnit is not integer
		}, //
	},
	outputUnitTypes: {
		{unitTypeId}: {
			stageId: "xx", // required initial stage Units are set to
			calculatedProperties: { // calculates a property added to the outputUnits
				{propertyName}: {
					calculationType: "calculateValue", // can add other types later
					combinationEquation: "[propertyA]+[propertyB]", // optional, method of combining multiple calculateByProperties together, defaults to adding/sum
					calculateByProperties: [ // can set many inputType properties
						{
							inputUnitTypeId: "xxx", // different unitTypeIds can have different properties/calculations
							propertyName: "xxx", // property that gets inserted into calculation
							calculation: "[property]*[quantity]",
						},
						// ..
					]
				}, 
				//..
			}
		}, 
		//..
	},
}

Calculating values

combinationEquation and calculateByProperties.calculation fields replace out special tags first like [propertyA]/[propertyB]/[property]/[quantity], the parse through an evaluation library, eg:

Must make sure equation is validated/sanitized first, be careful of eval or new Function which can invoke arbritrary commands

Transform request

  • Input Units might have multiple Unit records of the same UnitType, and each record has it's quantityProperty which might be >1
  • All quantityProperty will be used completely in one transformation, no partial quantities handled
  • Do not differentiate which inputUnits are used on which outputUnits, if want to do that need to split into multiple transformations
  • When we calculate calculatedProperties we sum all inputUnits calculations together to work out a value per quantity, then apply the ratio set for each outputUnit to calculate each outputUnits property
  • outputUnits are split by itemType, but each itemType is split by sets so different calculatedProperties can be done (eg calcualting cost for sizes of different clothing)
  • each itemType sets the quantity (number of Units) that are created
  • each itemType set defaults to even ratio usage of inputUnit total quantity
  • each itemType set can set to override default ratio with a set value (total or per Unit) for each input ItemType, as long as all input quantities are used in full (either by having >0 sets use remaining ratio, or override accurately to use all quantity)
  • if multiple

Graph database

Service - Supply Graph

Nodes

{
	nodeLabel: "{transformUnitsLib.TRANSFORM_UNITS_GRAPH_NODE_LABEL}", // transformUnits
	schema: {
		identifier: true,
		restrictProperties: true,
		restrictRelationships: true,
		properties: {
			transformConfigId: {
				identifier: true, //(random uuid)
			},
		},
	}
}
  • One transform units task
{
	nodeLabel: "{transformUnitsLib.TRANSFORM_UNITS_CONFIG_GRAPH_NODE_LABEL}", // transformUnitsConfig
	schema: {
		identifier: true,
		restrictProperties: true,
		restrictRelationships: true,
		properties: {
			transformConfigId: {
				identifier: true, //(random uuid)
			},
		},
	}
}
  • Main Transform Confirm object

Versioned data

transformUnitsConfigSettings

  • At the moment a stage Adjustment can only be edited by the user who created it (use standard createdBy relationship), in future could make RBAC per stageAdjustment
{
	properties: {
		inputUnitTypes: [],
		outputUnitTypes: [],
	},
}

Relationships

{
	relationshipType: "{transformUnitsLib.TO_TRANSFORM_TRANSFORM_UNITS_FROM_GRAPH_REL_TYPE}", // "toTransform_TransformUnits"
	schema: {
		elementCanBeRemoved: false,
		allPropertiesImmutable: true,
		restrictProperties: true,
		properties: {
			originTimestamp: //timestamp the request to create/change this relationship was sent
		},
	}
}
  • connects inputUnits to transformUnits node
{
	relationshipType: "{transformUnitsLib.FROM_TRANSFORM_TRANSFORM_UNITS_FROM_GRAPH_REL_TYPE}", // "fromTransform_TransformUnits"
	schema: {
		elementCanBeRemoved: false,
		allPropertiesImmutable: true,
		restrictProperties: true,
		properties: {
			originTimestamp: //timestamp the request to create/change this relationship was sent
		},
	}
}
  • connects outputUnits to transformUnits node

Working documents

Transform Units