Calc - Import and Export

Importing and exporting calculations from system to system.

Description

CalcImportExport.exe is a tool for exporting and importing calculations. Exporting and importing can be done remotely and locally. Before importing, it is assumed that target machines already have relevant equipment types defined for calculations.

Typical Workflow

  1. Export calculations from the local machine.
  2. Define types and create instances and variables in the target machine. (using e.g. ExcelPopulateEquipment.exe or ExcelPopulateClass.exe)
  3. Import calculations to the target machine.

Notice: Go to CalcCatalog to check possible errors. After the corrections just re-enable. Typical errors are:

  1. No write permissions on instances or variables
  2. Variable name mismatch.
  3. Instance name mismatch.

Example 1: Import A Simple Calculation

For starters, let's import a simple addition to a simple model. The model has three properties: propertyA, propertyB, and propertyC. And the calculation is propertyC = propertyA + propertyB. The model and calculations are already provided below: example1model.json and example1calc.json

{
  "ClassData": [
    {
      "Class": "Equipment",
      "Instances": [
        {
          "Id": "7b915007-7165-47bd-8d3d-d07d683e472b",
          "Name": "SimpleModel",
          "ClassName": "Path_SimpleModel"
        }
      ]
    },
    {
      "Class": "EquipmentPropertyInfo",
      "Instances": [
        {
          "Id": "0dd2ba67-98e6-478a-a1d9-379fdb0f2217",
          "DisplayName": "PropertyA",
          "Equipment": "7b915007-7165-47bd-8d3d-d07d683e472b",
          "Type": 14,
          "Historized": true
        },
        {
          "Id": "1e9abfa6-57e5-48d7-98ed-e4ba0f73bdd4",
          "DisplayName": "PropertyB",
          "Equipment": "7b915007-7165-47bd-8d3d-d07d683e472b",
          "Type": 14,
          "Historized": false
        },
        {
          "Id": "fcc82b71-3d55-4409-b9bb-e2e74f623bae",
          "DisplayName": "PropertyC",
          "Equipment": "7b915007-7165-47bd-8d3d-d07d683e472b",
          "Type": 14,
          "Historized": true
        }
      ]
    },
    {
      "Class": "Path_SimpleModel",
      "Instances": [
        {
          "Id": "8c341824-9340-44c7-abbb-cdb1a10bfe1b",
          "Name": "SimpleTree.simplemodel",
          "PropertyB": "2"
        }
      ]
    }
  ]
}
{
	"ClassData": [
		{
			"Class": "CalcParameter",
			"Instances": [
				{
					"ArrayDimensions": 0,
					"Definition": "64d12823-d751-49cd-98e3-6f160949eb7f",
					"Id": "3532b5da-7d9e-405d-cdc1-e8a5be8b68bc",
					"IsOutput": false,
					"Name": "PropertyA",
					"Type": "ee083765-a2b0-4f7f-ae5a-e29669782f33"
				},
				{
					"ArrayDimensions": 0,
					"Definition": "64d12823-d751-49cd-98e3-6f160949eb7f",
					"Id": "947dcbc3-eeba-423c-addd-29736e6ba34d",
					"IsOutput": true,
					"Name": "PropertyC",
					"Type": "ee083765-a2b0-4f7f-ae5a-e29669782f33"
				},
				{
					"ArrayDimensions": 0,
					"Definition": "64d12823-d751-49cd-98e3-6f160949eb7f",
					"Id": "b5635cd6-bdac-413e-97ab-9cb482f4b45b",
					"IsOutput": false,
					"Name": "PropertyB",
					"Type": "5a92da04-75f9-4ab5-aee1-5bdc8c32c4bf"
				}
			]
		},
		{
			"Class": "CalcParameterType",
			"Instances": [
				{
					"EquipmentDatasource": "00000000-0000-0000-0000-000000000000",
					"EquipmentType": null,
					"Id": "ee083765-a2b0-4f7f-ae5a-e29669782f33",
					"Name": "CalcVariable<double>",
					"TypeName": "ABB.Vtrin.CalcEngine.CalcVariable`1[[System.Double]], CalcVariable"
				}
			]
		},
		{
			"Class": "CalcParameterType",
			"Instances": [
				{
					"EquipmentDatasource": "00000000-0000-0000-0000-000000000000",
					"EquipmentType": null,
					"Id": "5a92da04-75f9-4ab5-aee1-5bdc8c32c4bf",
					"Name": "double",
					"TypeName": "System.Double"
				}
			]
		},
		{
			"Class": "CalcDefinition",
			"Instances": [
				{
					"Code": "// Automatically generated scaffolding for the calculation code\n//\n// Code name: no code name defined, put code name on the input box above this code editor\n// List of variables that you can use based on parameters that you have added:\n// CalcVariable<double> PropertyC, CalcVariable<double> PropertyA, double PropertyB\n\nusing System.Linq;\nusing System;\n\nnamespace ABB.Vtrin.CalcEngine\n{\n\tpublic class CalcClass_sumcode : CalcInstance\n\t{\n\t\t// put your constructor here\n\t\t\n\t\tpublic void Calculate(CalcVariable<double> PropertyC, CalcVariable<double> PropertyA, double PropertyB)\n\t\t{\n\t\t\t// put your calculation code here\n\t\t\tPropertyC.Last = PropertyA.Last + PropertyB;\n\t\t}\n\t}\n}",
					"CodeType": 1,
					"Description": "",
					"Disabled": false,
					"Group": "\\RTDB-admin",
					"Id": "64d12823-d751-49cd-98e3-6f160949eb7f",
					"Name": "sumcode"
				}
			]
		},
		{
			"Class": "CalcTask",
			"Instances": [
				{
					"BaseTime": "9466776000000000",
					"CalcPeriod": null,
					"CalcPeriodUnit": null,
					"ConstructorParameters": "",
					"Debug": false,
					"Definition": "64d12823-d751-49cd-98e3-6f160949eb7f",
					"Description": "",
					"DiagUpdateIntervalSeconds": null,
					"Disabled": false,
					"ErrorMessage": "{}",
					"Group": "\\RTDB-admin",
					"Id": "b1c42e23-10a1-47f4-e39a-85ed0fe2adbd",
					"MaxRunSecondsBeforeKilled": 120,
					"Name": "sumcalc",
					"PeriodOffset": null,
					"PeriodOffsetUnit": null,
					"Process": "21d87629-9d58-4b99-f9ed-8cb948867fc7"
				}
			]
		},
		{
			"Class": "CalcTaskTrigger",
			"Instances": [
				{
					"ClassLevelListener": false,
					"Disabled": false,
					"EventProperties": null,
					"Id": "a6aa29d4-916d-4c35-d22c-9d54420e3072",
					"ImplicitForEach": false,
					"Mapping": null,
					"PollingIntervalSecs": 0,
					"Scheduler": "1552307e-003a-4a42-8fbc-ba9c611d0361",
					"Task": "b1c42e23-10a1-47f4-e39a-85ed0fe2adbd",
					"TriggeredByTask": null,
					"Type": 0,
					"Warnings": ""
				}
			]
		},
		{
			"Class": "CalcParameterMapping",
			"Instances": [
				{
					"Defaulthistory": null,
					"Id": [
						"b1c42e23-10a1-47f4-e39a-85ed0fe2adbd",
						"3532b5da-7d9e-405d-cdc1-e8a5be8b68bc"
					],
					"ImplicitForEach": false,
					"Mapping": "91358e5b-e837-48db-aea0-a3b139b61e58",
					"Parameter": "3532b5da-7d9e-405d-cdc1-e8a5be8b68bc",
					"PeriodLengthOverride": null,
					"PeriodLengthUnitOverride": null,
					"SelectProperty": "PropertyA",
					"Task": "b1c42e23-10a1-47f4-e39a-85ed0fe2adbd"
				},
				{
					"Defaulthistory": null,
					"Id": [
						"b1c42e23-10a1-47f4-e39a-85ed0fe2adbd",
						"947dcbc3-eeba-423c-addd-29736e6ba34d"
					],
					"ImplicitForEach": false,
					"Mapping": "98c70ed2-6b2d-4286-e762-decf26f4411d",
					"Parameter": "947dcbc3-eeba-423c-addd-29736e6ba34d",
					"PeriodLengthOverride": null,
					"PeriodLengthUnitOverride": null,
					"SelectProperty": "PropertyC",
					"Task": "b1c42e23-10a1-47f4-e39a-85ed0fe2adbd"
				},
				{
					"Defaulthistory": null,
					"Id": [
						"b1c42e23-10a1-47f4-e39a-85ed0fe2adbd",
						"b5635cd6-bdac-413e-97ab-9cb482f4b45b"
					],
					"ImplicitForEach": false,
					"Mapping": "98c70ed2-6b2d-4286-e762-decf26f4411d",
					"Parameter": "b5635cd6-bdac-413e-97ab-9cb482f4b45b",
					"PeriodLengthOverride": null,
					"PeriodLengthUnitOverride": null,
					"SelectProperty": "PropertyB",
					"Task": "b1c42e23-10a1-47f4-e39a-85ed0fe2adbd"
				}
			]
		},
		{
			"Class": "CalcMapping",
			"Instances": [
				{
					"ClassName": "Path_SimpleModel",
					"ConstantValue": null,
					"Datasource": "00000000-0000-0000-0000-000000000000",
					"Description": "Path_SimpleModel/SimpleTree.simplemodel|864db635-03b9-471a-a0e2-9731b47189f7",
					"Id": "91358e5b-e837-48db-aea0-a3b139b61e58",
					"WhereString": "Name='SimpleTree.simplemodel'"
				}
			]
		},
		{
			"Class": "CalcMapping",
			"Instances": [
				{
					"ClassName": "Path_SimpleModel",
					"ConstantValue": null,
					"Datasource": "00000000-0000-0000-0000-000000000000",
					"Description": "Path_SimpleModel/SimpleTree.simplemodel|864db635-03b9-471a-a0e2-9731b47189f7",
					"Id": "98c70ed2-6b2d-4286-e762-decf26f4411d",
					"WhereString": "Name='SimpleTree.simplemodel'"
				}
			]
		},
		{
			"Class": "CalcProcess",
			"Instances": [
				{
					"Disabled": false,
					"Id": "21d87629-9d58-4b99-f9ed-8cb948867fc7",
					"Name": "For:sumcalc|21d87629-9d58-4b99-f9ed-8cb948867fc7",
					"NumThreads": 0,
					"PriorityClass": 2,
					"Restart": false,
					"RunAs32Bit": false
				}
			]
		},
		{
			"Class": "CalcScheduler",
			"Instances": [
				{
					"BaseTime": "9466848000000000",
					"Disabled": false,
					"EndTime": null,
					"ExecutionInterval": 1,
					"ExecutionIntervalUnit": 3,
					"Id": "1552307e-003a-4a42-8fbc-ba9c611d0361",
					"Name": "1Sec",
					"SkipMissed": true,
					"StartTime": "-116444736000000000"
				}
			]
		}
	]
}

Import both JSON files provided above:

#1. import the model
VtrinCmd.exe --importjson <example1model.json> --user <username>  --acceptnewkeys --connectionstring <rtdb location>
#Notice: After importing the equipment model
#RTDB_CalcService create a new row automatically in CalcParameterType for that model.

#2. import the calculation
CalcImportExport.exe --import <example1calcs.json> --user <username> --continueonerror --replace --connectionstring <rtdb location>

#Note: Direct connectionstring (path to rtdb) doesn't require username nor password

Finally, navigate to SimpleTree.simplemodel and change propertyA value to something else to see the addition in the target machine. Let's understand some command line arguments:
acceptnewkeys:
Accept new server keys. Without this, establishing a connection might raise a certification error.

continueonerror:
Use with --import. Continue operation when an error occurs, for example, trying to import data that already exists.

replace:
Replace or merge into existing class instances.

Example 2 : Exporting

Example of exporting calculations from the previous example:

CalcImportExport.exe --export <output JSON file> --user <username> --connectionstring <rtdb location>

By default, the command exports all calculations. However, users may choose which definitions will be exported using definitionname argument. See more in CalcImportExport.exe --help.

Example 3 : Remapping

If other sites have different process paths and variables names, then it is possible to remap paths and variables before importing. Either modify directly WhereString-property in JSON file or command-line user interface. Let's assume the example model has imported another machine and the instance path is changed to SimpleTreeNew.simplemodelNew, then we can remap:

CalcImportExport.exe --continueonerror --replace --user <username> --import <example1calcs.json> --connectionstring <rtdb location> --remapseparator '>' --remap 'SimpleTree.simplemodel>SimpleTreeNew.simplemodelNew'

Command Line User interface can modify simple WhereString-property, having an assignment e.g. "Name='SimpleTree.simplemodel". Old and new names are separated by --remapseparator and --separator is used to add more mappings. For more complex remapping, modify WhereString-property in the JSON file manually or existing tool.