|
1 | 1 | # This file contains the data used to seed the test environment for the simulator tests |
| 2 | +from cognite.client.data_classes.simulators.routine_revisions import ( |
| 3 | + SimulationValueUnitInput, |
| 4 | + SimulatorRoutineConfiguration, |
| 5 | + SimulatorRoutineDataSampling, |
| 6 | + SimulatorRoutineInputConstant, |
| 7 | + SimulatorRoutineLogicalCheck, |
| 8 | + SimulatorRoutineOutput, |
| 9 | + SimulatorRoutineRevisionWrite, |
| 10 | + SimulatorRoutineSchedule, |
| 11 | + SimulatorRoutineStage, |
| 12 | + SimulatorRoutineSteadyStateDetection, |
| 13 | + SimulatorRoutineStep, |
| 14 | + SimulatorRoutineStepArguments, |
| 15 | +) |
2 | 16 | from cognite.client.utils._text import random_string |
3 | 17 |
|
4 | 18 | data_set_external_id = "sdk_tests_dwsim1" |
|
236 | 250 | "description": "Simulator Routine - Description Test", |
237 | 251 | } |
238 | 252 |
|
| 253 | +simulator_routine_revision_config_obj = { |
| 254 | + "schedule": {"enabled": True, "cronExpression": "*/10 * * * *"}, |
| 255 | + "dataSampling": {"enabled": True, "samplingWindow": 15, "granularity": 1, "validationWindow": 5}, |
| 256 | + "logicalCheck": [ |
| 257 | + { |
| 258 | + "enabled": True, |
| 259 | + "aggregate": "average", |
| 260 | + "operator": "lt", |
| 261 | + "value": 75.8, |
| 262 | + "timeseriesExternalId": "VAL-45-PT-92608_test", |
| 263 | + } |
| 264 | + ], |
| 265 | + "steadyStateDetection": [ |
| 266 | + { |
| 267 | + "enabled": True, |
| 268 | + "aggregate": "average", |
| 269 | + "minSectionSize": 1, |
| 270 | + "varThreshold": 3.5, |
| 271 | + "slopeThreshold": -7.5, |
| 272 | + "timeseriesExternalId": "VAL-45-PT-92608", |
| 273 | + } |
| 274 | + ], |
| 275 | + "inputs": [ |
| 276 | + { |
| 277 | + "name": "Cold Water Temperature", |
| 278 | + "referenceId": "CWT", |
| 279 | + "value": 10.0, |
| 280 | + "valueType": "DOUBLE", |
| 281 | + "unit": {"name": "C", "quantity": "temperature"}, |
| 282 | + "saveTimeseriesExternalId": "TEST-ROUTINE-INPUT-CWT", |
| 283 | + }, |
| 284 | + { |
| 285 | + "name": "Cold Water Pressure", |
| 286 | + "referenceId": "CWP", |
| 287 | + "value": [3.6], |
| 288 | + "valueType": "DOUBLE_ARRAY", |
| 289 | + "unit": {"name": "bar", "quantity": "pressure"}, |
| 290 | + }, |
| 291 | + ], |
| 292 | + "outputs": [ |
| 293 | + { |
| 294 | + "name": "Shower Temperature", |
| 295 | + "referenceId": "ST", |
| 296 | + "unit": {"name": "C", "quantity": "temperature"}, |
| 297 | + "valueType": "DOUBLE", |
| 298 | + "saveTimeseriesExternalId": "TEST-ROUTINE-OUTPUT-ST", |
| 299 | + }, |
| 300 | + { |
| 301 | + "name": "Shower Pressure", |
| 302 | + "referenceId": "SP", |
| 303 | + "unit": {"name": "bar", "quantity": "pressure"}, |
| 304 | + "valueType": "DOUBLE", |
| 305 | + }, |
| 306 | + ], |
| 307 | +} |
239 | 308 |
|
240 | | -simulator_routine_revision = { |
241 | | - "externalId": None, |
242 | | - "routineExternalId": resource_names["simulator_routine_external_id"], |
243 | | - "configuration": { |
244 | | - "schedule": {"enabled": True, "cronExpression": "*/10 * * * *"}, |
245 | | - "dataSampling": {"enabled": True, "samplingWindow": 15, "granularity": 1}, |
246 | | - "logicalCheck": [], |
247 | | - "steadyStateDetection": [], |
248 | | - "inputs": [ |
| 309 | +simulator_routine_revision_script_obj = [ |
| 310 | + { |
| 311 | + "order": 1, |
| 312 | + "description": "Set Inputs", |
| 313 | + "steps": [ |
249 | 314 | { |
250 | | - "name": "Cold Water Temperature", |
251 | | - "referenceId": "CWT", |
252 | | - "value": 10.0, |
253 | | - "valueType": "DOUBLE", |
254 | | - "unit": {"name": "C", "quantity": "temperature"}, |
255 | | - "saveTimeseriesExternalId": "TEST-ROUTINE-INPUT-CWT", |
| 315 | + "order": 1, |
| 316 | + "stepType": "Set", |
| 317 | + "description": "Set Cold Water Temperature", |
| 318 | + "arguments": {"referenceId": "CWT", "objectName": "Cold water", "objectProperty": "Temperature"}, |
256 | 319 | }, |
257 | 320 | { |
258 | | - "name": "Cold Water Pressure", |
259 | | - "referenceId": "CWP", |
260 | | - "value": [3.6], |
261 | | - "valueType": "DOUBLE_ARRAY", |
262 | | - "unit": {"name": "bar", "quantity": "pressure"}, |
| 321 | + "order": 2, |
| 322 | + "stepType": "Set", |
| 323 | + "description": "Set Cold Water Pressure", |
| 324 | + "arguments": {"referenceId": "CWP", "objectName": "Cold water", "objectProperty": "Pressure"}, |
263 | 325 | }, |
264 | 326 | ], |
265 | | - "outputs": [ |
| 327 | + }, |
| 328 | + { |
| 329 | + "order": 2, |
| 330 | + "description": "Solve the flowsheet", |
| 331 | + "steps": [{"order": 1, "stepType": "Command", "arguments": {"command": "Solve"}}], |
| 332 | + }, |
| 333 | + { |
| 334 | + "order": 3, |
| 335 | + "description": "Set simulation outputs", |
| 336 | + "steps": [ |
266 | 337 | { |
267 | | - "name": "Shower Temperature", |
268 | | - "referenceId": "ST", |
269 | | - "unit": {"name": "C", "quantity": "temperature"}, |
270 | | - "valueType": "DOUBLE", |
271 | | - "saveTimeseriesExternalId": "TEST-ROUTINE-OUTPUT-ST", |
| 338 | + "order": 1, |
| 339 | + "stepType": "Get", |
| 340 | + "arguments": {"referenceId": "ST", "objectName": "Shower", "objectProperty": "Temperature"}, |
272 | 341 | }, |
273 | 342 | { |
274 | | - "name": "Shower Pressure", |
275 | | - "referenceId": "SP", |
276 | | - "unit": {"name": "bar", "quantity": "pressure"}, |
277 | | - "valueType": "DOUBLE", |
| 343 | + "order": 2, |
| 344 | + "stepType": "Get", |
| 345 | + "arguments": {"referenceId": "SP", "objectName": "Shower", "objectProperty": "Pressure"}, |
278 | 346 | }, |
279 | 347 | ], |
280 | 348 | }, |
281 | | - "script": [ |
282 | | - { |
283 | | - "order": 1, |
284 | | - "description": "Set Inputs", |
285 | | - "steps": [ |
286 | | - { |
287 | | - "order": 1, |
288 | | - "stepType": "Set", |
289 | | - "description": "Set Cold Water Temperature", |
290 | | - "arguments": {"referenceId": "CWT", "objectName": "Cold water", "objectProperty": "Temperature"}, |
291 | | - }, |
292 | | - { |
293 | | - "order": 2, |
294 | | - "stepType": "Set", |
295 | | - "description": "Set Cold Water Pressure", |
296 | | - "arguments": {"referenceId": "CWP", "objectName": "Cold water", "objectProperty": "Pressure"}, |
297 | | - }, |
| 349 | +] |
| 350 | + |
| 351 | +simulator_routine_revision_obj = { |
| 352 | + "externalId": None, |
| 353 | + "routineExternalId": resource_names["simulator_routine_external_id"], |
| 354 | + "configuration": simulator_routine_revision_config_obj, |
| 355 | + "script": simulator_routine_revision_script_obj, |
| 356 | +} |
| 357 | + |
| 358 | + |
| 359 | +def create_simulator_routine_revision( |
| 360 | + external_id: str, |
| 361 | + routine_external_id: str, |
| 362 | +) -> SimulatorRoutineRevisionWrite: |
| 363 | + """Create a test simulator routine revision object.""" |
| 364 | + return SimulatorRoutineRevisionWrite( |
| 365 | + external_id=external_id, |
| 366 | + routine_external_id=routine_external_id, |
| 367 | + configuration=SimulatorRoutineConfiguration( |
| 368 | + schedule=SimulatorRoutineSchedule( |
| 369 | + cron_expression=simulator_routine_revision_config_obj["schedule"]["cronExpression"], |
| 370 | + ), |
| 371 | + data_sampling=SimulatorRoutineDataSampling( |
| 372 | + sampling_window=simulator_routine_revision_config_obj["dataSampling"]["samplingWindow"], |
| 373 | + granularity=simulator_routine_revision_config_obj["dataSampling"]["granularity"], |
| 374 | + validation_window=simulator_routine_revision_config_obj["dataSampling"]["validationWindow"], |
| 375 | + ), |
| 376 | + logical_check=[ |
| 377 | + SimulatorRoutineLogicalCheck( |
| 378 | + aggregate=logical_check["aggregate"], |
| 379 | + operator=logical_check["operator"], |
| 380 | + value=logical_check["value"], |
| 381 | + timeseries_external_id=logical_check["timeseriesExternalId"], |
| 382 | + ) |
| 383 | + for logical_check in simulator_routine_revision_config_obj["logicalCheck"] |
298 | 384 | ], |
299 | | - }, |
300 | | - { |
301 | | - "order": 2, |
302 | | - "description": "Solve the flowsheet", |
303 | | - "steps": [{"order": 1, "stepType": "Command", "arguments": {"command": "Solve"}}], |
304 | | - }, |
305 | | - { |
306 | | - "order": 3, |
307 | | - "description": "Set simulation outputs", |
308 | | - "steps": [ |
309 | | - { |
310 | | - "order": 1, |
311 | | - "stepType": "Get", |
312 | | - "arguments": {"referenceId": "ST", "objectName": "Shower", "objectProperty": "Temperature"}, |
313 | | - }, |
314 | | - { |
315 | | - "order": 2, |
316 | | - "stepType": "Get", |
317 | | - "arguments": {"referenceId": "SP", "objectName": "Shower", "objectProperty": "Pressure"}, |
318 | | - }, |
| 385 | + steady_state_detection=[ |
| 386 | + SimulatorRoutineSteadyStateDetection( |
| 387 | + aggregate=steady_state_detection["aggregate"], |
| 388 | + min_section_size=steady_state_detection["minSectionSize"], |
| 389 | + var_threshold=steady_state_detection["varThreshold"], |
| 390 | + slope_threshold=steady_state_detection["slopeThreshold"], |
| 391 | + timeseries_external_id=steady_state_detection["timeseriesExternalId"], |
| 392 | + ) |
| 393 | + for steady_state_detection in simulator_routine_revision_config_obj["steadyStateDetection"] |
319 | 394 | ], |
320 | | - }, |
321 | | - ], |
322 | | -} |
| 395 | + inputs=[ |
| 396 | + SimulatorRoutineInputConstant( |
| 397 | + name=input_cfg["name"], |
| 398 | + reference_id=input_cfg["referenceId"], |
| 399 | + value=input_cfg["value"], |
| 400 | + value_type=input_cfg["valueType"], |
| 401 | + unit=SimulationValueUnitInput( |
| 402 | + name=input_cfg["unit"]["name"], |
| 403 | + quantity=input_cfg["unit"]["quantity"], |
| 404 | + ), |
| 405 | + save_timeseries_external_id=input_cfg.get("saveTimeseriesExternalId"), |
| 406 | + ) |
| 407 | + for input_cfg in simulator_routine_revision_config_obj["inputs"] |
| 408 | + ], |
| 409 | + outputs=[ |
| 410 | + SimulatorRoutineOutput( |
| 411 | + name=output_cfg["name"], |
| 412 | + reference_id=output_cfg["referenceId"], |
| 413 | + unit=SimulationValueUnitInput( |
| 414 | + name=output_cfg["unit"]["name"], |
| 415 | + quantity=output_cfg["unit"]["quantity"], |
| 416 | + ), |
| 417 | + value_type=output_cfg["valueType"], |
| 418 | + save_timeseries_external_id=output_cfg.get("saveTimeseriesExternalId"), |
| 419 | + ) |
| 420 | + for output_cfg in simulator_routine_revision_config_obj["outputs"] |
| 421 | + ], |
| 422 | + ), |
| 423 | + script=[ |
| 424 | + SimulatorRoutineStage( |
| 425 | + order=stage_cfg["order"], |
| 426 | + description=stage_cfg["description"], |
| 427 | + steps=[ |
| 428 | + SimulatorRoutineStep( |
| 429 | + order=step_cfg["order"], |
| 430 | + step_type=step_cfg["stepType"], |
| 431 | + description=step_cfg.get("description"), |
| 432 | + arguments=SimulatorRoutineStepArguments(step_cfg["arguments"]), |
| 433 | + ) |
| 434 | + for step_cfg in stage_cfg["steps"] |
| 435 | + ], |
| 436 | + ) |
| 437 | + for stage_cfg in simulator_routine_revision_script_obj |
| 438 | + ], |
| 439 | + ) |
0 commit comments