@dnv-plant/typescriptpws 1.0.27 → 1.0.38-alpha.1846913

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3521 @@
1
+ /***********************************************************************
2
+ * This file has been auto-generated by a code generation tool.
3
+ * Version: 1.0.38
4
+ * Date/time: 24 Mar 2025 16:46:20
5
+ * Template: templates/typescriptpws/calculations.razor.
6
+ ***********************************************************************/
7
+
8
+
9
+
10
+ import * as Enums from "../enums";
11
+ import * as Entities from "../entities";
12
+ import * as EntitySchemas from "../entity-schemas";
13
+ import { getAnalyticsApiTarget, getClientAliasId, postRequest } from "../utilities";
14
+
15
+ import Joi from "joi";
16
+ import { AxiosResponse } from "axios";
17
+
18
+
19
+ class CalculationRequestBase {
20
+ /**
21
+ * Calculation request base class.
22
+ */
23
+ constructor() {
24
+ // Base class initialization code
25
+ }
26
+ }
27
+
28
+ class CalculationBase {
29
+ resultCode?: Enums.ResultCode = Enums.ResultCode.SUCCESS;
30
+ messages: string[] = [];
31
+ calculationElapsedTime?: number = 0.0;
32
+ operationId?: string = "";
33
+
34
+ /**
35
+ * Post JSON to URL and time the call
36
+ */
37
+ async postRequest(url: string, data: string): Promise<AxiosResponse> {
38
+ return postRequest(url, data);
39
+ }
40
+
41
+ /**
42
+ * Utility method to print the messages returned by the calculation.
43
+ */
44
+ printMessages(): void {
45
+ if (this.messages && this.messages.length > 0) {
46
+ this.messages.forEach((message) => console.log(message));
47
+ } else {
48
+ console.log("No messages");
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Utility method to handle a failed response.
54
+ */
55
+ handleFailedResponse(response: AxiosResponse): void {
56
+ try {
57
+ const validatedFailedResponse = new CalculationFailedResponseSchema().validate(response.data);
58
+
59
+ this.resultCode = validatedFailedResponse.resultCode;
60
+ this.messages.push(...(validatedFailedResponse.messages ?? []));
61
+ this.calculationElapsedTime = validatedFailedResponse.calculationElapsedTime;
62
+ this.operationId = validatedFailedResponse.operationId;
63
+ } catch (error) {
64
+ if (error instanceof Error) {
65
+ this.messages.push(`Failed to parse response: ${error.message}`);
66
+ } else {
67
+ this.messages.push("An unknown error occurred during response parsing.");
68
+ }
69
+ console.error("Failed to parse response:", error);
70
+ } finally {
71
+ this.messages.push(`${response.statusText} (Status code: ${response.status})`);
72
+ }
73
+ }
74
+ }
75
+
76
+ class CalculationResponseBase {
77
+ resultCode?: Enums.ResultCode;
78
+ messages?: string[];
79
+ calculationElapsedTime?: number;
80
+ operationId?: string;
81
+
82
+ /**
83
+ * Calculation response base class.
84
+ */
85
+ constructor(
86
+ resultCode?: Enums.ResultCode,
87
+ messages?: string[],
88
+ calculationElapsedTime?: number,
89
+ operationId?: string
90
+ ) {
91
+ this.resultCode = resultCode;
92
+ this.messages = messages;
93
+ this.calculationElapsedTime = calculationElapsedTime;
94
+ this.operationId = operationId;
95
+ }
96
+ }
97
+
98
+ class CalculationFailedResponse extends CalculationResponseBase {
99
+ /**
100
+ * Calculation failed response class.
101
+ */
102
+ constructor(
103
+ resultCode?: Enums.ResultCode,
104
+ messages: string[] = [],
105
+ calculationElapsedTime: number = 0,
106
+ operationId: string = ""
107
+ ) {
108
+ super(resultCode, messages, calculationElapsedTime, operationId);
109
+ }
110
+ }
111
+
112
+ class CalculationFailedResponseSchema {
113
+ schema: Joi.ObjectSchema;
114
+
115
+ /**
116
+ * Calculation failed response schema.
117
+ */
118
+ constructor() {
119
+ this.schema = Joi.object({
120
+ resultCode: Joi.string()
121
+ .valid(...Object.values(Enums.ResultCode))
122
+ .required(),
123
+ messages: Joi.array().items(Joi.string()).required(),
124
+ calculationElapsedTime: Joi.number().required(),
125
+ operationId: Joi.string().required(),
126
+ }).unknown(true);
127
+ }
128
+
129
+ validate(data: {
130
+ resultCode: Enums.ResultCode;
131
+ messages: string[];
132
+ calculationElapsedTime: number;
133
+ operationId: string;
134
+ }) {
135
+ const { error, value } = this.schema.validate(data);
136
+ if (error) throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
137
+ return this.makeCalculationFailedResponse(value);
138
+ }
139
+
140
+ makeCalculationFailedResponse(data: {
141
+ resultCode: Enums.ResultCode;
142
+ messages: string[];
143
+ calculationElapsedTime: number;
144
+ operationId: string;
145
+ }) {
146
+ return new CalculationFailedResponse(data.resultCode, data.messages, data.calculationElapsedTime, data.operationId);
147
+ }
148
+ }
149
+
150
+ export interface DistancesAndEllipsesToRadiationLevelsCalculationRequestSchemaData {
151
+ flameResult: Entities.FlameResult;
152
+ flameRecords: Entities.FlameRecord[];
153
+ flameRecordCount: number;
154
+ weather: Entities.Weather;
155
+ flammableParameters: Entities.FlammableParameters;
156
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
157
+ flammableOutputConfigCount: number;
158
+ }
159
+
160
+ class DistancesAndEllipsesToRadiationLevelsCalculationRequest extends CalculationRequestBase {
161
+ flameResult: Entities.FlameResult;
162
+ flameRecords: Entities.FlameRecord[];
163
+ flameRecordCount: number;
164
+ weather: Entities.Weather;
165
+ flammableParameters: Entities.FlammableParameters;
166
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
167
+ flammableOutputConfigCount: number;
168
+
169
+ /**
170
+ * DistancesAndEllipsesToRadiationLevels calculation request class.
171
+ *
172
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
173
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
174
+ * @param {number} flameRecordCount - Number of Flame Records.
175
+ * @param {Entities.Weather} weather - A Weather entity.
176
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
177
+ * @param {Entities.FlammableOutputConfig[]} flammableOutputConfigs - Array of Flammable Output Configs.
178
+ * @param {number} flammableOutputConfigCount - Number of radiation levels.
179
+ */
180
+ constructor(
181
+ flameResult: Entities.FlameResult,
182
+ flameRecords: Entities.FlameRecord[],
183
+ flameRecordCount: number,
184
+ weather: Entities.Weather,
185
+ flammableParameters: Entities.FlammableParameters,
186
+ flammableOutputConfigs: Entities.FlammableOutputConfig[],
187
+ flammableOutputConfigCount: number
188
+ ) {
189
+ super();
190
+ this.flameResult = flameResult;
191
+ this.flameRecords = flameRecords;
192
+ this.flameRecordCount = flameRecordCount;
193
+ this.weather = weather;
194
+ this.flammableParameters = flammableParameters;
195
+ this.flammableOutputConfigs = flammableOutputConfigs;
196
+ this.flammableOutputConfigCount = flammableOutputConfigCount;
197
+ }
198
+ }
199
+
200
+ export class DistancesAndEllipsesToRadiationLevelsCalculationRequestSchema {
201
+ schema: Joi.ObjectSchema;
202
+ propertyTypes: Record<string, string>;
203
+
204
+ /**
205
+ * Schema for the DistancesAndEllipsesToRadiationLevels calculation request.
206
+ */
207
+ constructor() {
208
+ this.schema = Joi.object({
209
+ flameResult: new EntitySchemas.FlameResultSchema().schema,
210
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
211
+ flameRecordCount: Joi.number().integer(),
212
+ weather: new EntitySchemas.WeatherSchema().schema,
213
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
214
+ flammableOutputConfigs: Joi.array().items(new EntitySchemas.FlammableOutputConfigSchema().schema).allow(null),
215
+ flammableOutputConfigCount: Joi.number().integer(),
216
+ }).unknown(true);
217
+
218
+ this.propertyTypes = {
219
+ flameResult: "Entities.FlameResult",
220
+ flameRecords: "Entities.FlameRecord[]",
221
+ flameRecordCount: "number",
222
+ weather: "Entities.Weather",
223
+ flammableParameters: "Entities.FlammableParameters",
224
+ flammableOutputConfigs: "Entities.FlammableOutputConfig[]",
225
+ flammableOutputConfigCount: "number",
226
+ };
227
+ }
228
+
229
+ validate(data: DistancesAndEllipsesToRadiationLevelsCalculationRequestSchemaData): DistancesAndEllipsesToRadiationLevelsCalculationRequest {
230
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
231
+ if (error) {
232
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
233
+ }
234
+ return this.makeCalculationRequest(value);
235
+ }
236
+
237
+ makeCalculationRequest(data: DistancesAndEllipsesToRadiationLevelsCalculationRequestSchemaData): DistancesAndEllipsesToRadiationLevelsCalculationRequest {
238
+ return new DistancesAndEllipsesToRadiationLevelsCalculationRequest(
239
+ data.flameResult,
240
+ data.flameRecords,
241
+ data.flameRecordCount,
242
+ data.weather,
243
+ data.flammableParameters,
244
+ data.flammableOutputConfigs,
245
+ data.flammableOutputConfigCount
246
+ );
247
+ }
248
+ }
249
+
250
+ export class DistancesAndEllipsesToRadiationLevelsCalculation extends CalculationBase {
251
+ flameResult: Entities.FlameResult;
252
+ flameRecords: Entities.FlameRecord[];
253
+ flameRecordCount: number;
254
+ weather: Entities.Weather;
255
+ flammableParameters: Entities.FlammableParameters;
256
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
257
+ flammableOutputConfigCount: number;
258
+ distances?: number[];
259
+ contourPoints?: Entities.LocalPosition[];
260
+ nContourPoints?: number[];
261
+ areas?: number[];
262
+
263
+ /**
264
+ * Calculates the distances and ellipses to specified radiation intensity levels from a flame model. This calculation can be called after fireball and jet fire calculation.
265
+ *
266
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
267
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
268
+ * @param {number} flameRecordCount - Number of Flame Records.
269
+ * @param {Entities.Weather} weather - A Weather entity.
270
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
271
+ * @param {Entities.FlammableOutputConfig[]} flammableOutputConfigs - Array of Flammable Output Configs.
272
+ * @param {number} flammableOutputConfigCount - Number of radiation levels.
273
+ */
274
+ constructor(
275
+ flameResult: Entities.FlameResult,
276
+ flameRecords: Entities.FlameRecord[],
277
+ flameRecordCount: number,
278
+ weather: Entities.Weather,
279
+ flammableParameters: Entities.FlammableParameters,
280
+ flammableOutputConfigs: Entities.FlammableOutputConfig[],
281
+ flammableOutputConfigCount: number
282
+ ) {
283
+ super();
284
+ this.flameResult = flameResult;
285
+ this.flameRecords = flameRecords;
286
+ this.flameRecordCount = flameRecordCount;
287
+ this.weather = weather;
288
+ this.flammableParameters = flammableParameters;
289
+ this.flammableOutputConfigs = flammableOutputConfigs;
290
+ this.flammableOutputConfigCount = flammableOutputConfigCount;
291
+ }
292
+
293
+ async run() {
294
+ try {
295
+ const request = new DistancesAndEllipsesToRadiationLevelsCalculationRequest(
296
+ this.flameResult,
297
+ this.flameRecords,
298
+ this.flameRecordCount,
299
+ this.weather,
300
+ this.flammableParameters,
301
+ this.flammableOutputConfigs,
302
+ this.flammableOutputConfigCount
303
+ );
304
+
305
+ const schema = new DistancesAndEllipsesToRadiationLevelsCalculationRequestSchema();
306
+ const validatedRequest = schema.validate(request);
307
+
308
+ const requestJson = JSON.stringify(validatedRequest);
309
+ const url = `${getAnalyticsApiTarget()}calculatedistancesandellipsestoradiationlevels?clientId=${getClientAliasId()}`;
310
+
311
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
312
+
313
+ const response = await this.postRequest(url, requestJson);
314
+
315
+ if (response.status >= 200 && response.status < 300) {
316
+ const schema = new DistancesAndEllipsesToRadiationLevelsCalculationResponseSchema();
317
+ const validatedResponse = schema.validate(response.data);
318
+
319
+ this.resultCode = validatedResponse.resultCode;
320
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
321
+ this.distances = validatedResponse.distances;
322
+ this.contourPoints = validatedResponse.contourPoints;
323
+ this.nContourPoints = validatedResponse.nContourPoints;
324
+ this.areas = validatedResponse.areas;
325
+ this.resultCode = validatedResponse.resultCode;
326
+ this.messages = validatedResponse.messages ?? [];
327
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
328
+ this.operationId = validatedResponse.operationId;
329
+ } else {
330
+ this.messages.push(...(validatedResponse.messages ?? []));
331
+ }
332
+ } else {
333
+ this.handleFailedResponse(response);
334
+ }
335
+ } catch (error) {
336
+ if (error instanceof Error) {
337
+ this.messages.push(`Error: ${error.message}`);
338
+ } else {
339
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
340
+ }
341
+ console.error(error);
342
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
343
+ }
344
+
345
+ return this.resultCode;
346
+ }
347
+
348
+ toString() {
349
+ const parts = ["* DistancesAndEllipsesToRadiationLevels"];
350
+
351
+ parts.push("*** distances:");
352
+ parts.push(
353
+ this.distances && this.distances.length > 0
354
+ ? this.distances.map((point) => `distancesElement: ${point}`).join("\n")
355
+ : "distances does not contain any elements"
356
+ );
357
+ parts.push("*** contourPoints:");
358
+ parts.push(
359
+ this.contourPoints && this.contourPoints.length > 0
360
+ ? this.contourPoints.map((point) => `contourPointsElement: ${point}`).join("\n")
361
+ : "contourPoints does not contain any elements"
362
+ );
363
+ parts.push("*** nContourPoints:");
364
+ parts.push(
365
+ this.nContourPoints && this.nContourPoints.length > 0
366
+ ? this.nContourPoints.map((point) => `nContourPointsElement: ${point}`).join("\n")
367
+ : "nContourPoints does not contain any elements"
368
+ );
369
+ parts.push("*** areas:");
370
+ parts.push(
371
+ this.areas && this.areas.length > 0
372
+ ? this.areas.map((point) => `areasElement: ${point}`).join("\n")
373
+ : "areas does not contain any elements"
374
+ );
375
+ parts.push(`resultCode: ${String(this.resultCode)}`);
376
+ parts.push("*** messages:");
377
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
378
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
379
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
380
+
381
+ return parts.join("\n");
382
+ }
383
+ }
384
+
385
+ export class DistancesAndEllipsesToRadiationLevelsCalculationResponse extends CalculationResponseBase {
386
+ distances: number[];
387
+ contourPoints: Entities.LocalPosition[];
388
+ nContourPoints: number[];
389
+ areas: number[];
390
+
391
+ /**
392
+ * DistancesAndEllipsesToRadiationLevels calculation response class.
393
+ *
394
+ * @param {number[]} distances - An array of distances to radiation levels, corresponding to the Flammable Output Configs.
395
+ * @param {Entities.LocalPosition[]} contourPoints - Contour points of radiation ellipses to radiation levels.
396
+ * @param {number[]} nContourPoints - An array of the number of contour points, corresponding to the Flammable Output Configs.
397
+ * @param {number[]} areas - An array of areas of the ellipses to radiation levels, corresponding to the Flammable Output Configs.
398
+ */
399
+ constructor(
400
+ distances: number[],
401
+ contourPoints: Entities.LocalPosition[],
402
+ nContourPoints: number[],
403
+ areas: number[],
404
+ resultCode: Enums.ResultCode,
405
+ messages: string[],
406
+ calculationElapsedTime: number,
407
+ operationId: string
408
+ ) {
409
+ super();
410
+ this.distances = distances;
411
+ this.contourPoints = contourPoints;
412
+ this.nContourPoints = nContourPoints;
413
+ this.areas = areas;
414
+ this.resultCode = resultCode;
415
+ this.messages = messages;
416
+ this.calculationElapsedTime = calculationElapsedTime;
417
+ this.operationId = operationId;
418
+ }
419
+
420
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
421
+ if (data.distances && Array.isArray(data.distances)) {
422
+ this.distances = data.distances.map((item) => parseFloat(item));
423
+ }
424
+ if (data.contourPoints && Array.isArray(data.contourPoints)) {
425
+ this.contourPoints = data.contourPoints.map(
426
+ (item) => {
427
+ const record = new Entities.LocalPosition();
428
+ record.initialiseFromDictionary(item);
429
+ return record;
430
+ }
431
+ );
432
+ }
433
+ if (data.nContourPoints && Array.isArray(data.nContourPoints)) {
434
+ this.nContourPoints = data.nContourPoints.map((item) => parseInt(item));
435
+ }
436
+ if (data.areas && Array.isArray(data.areas)) {
437
+ this.areas = data.areas.map((item) => parseFloat(item));
438
+ }
439
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
440
+ this.resultCode = data.resultCode as Enums.ResultCode;
441
+ }
442
+ this.messages = this.messages ?? [];
443
+ if (data.messages && Array.isArray(data.messages)) {
444
+ this.messages.push(...data.messages);
445
+ }
446
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
447
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
448
+ }
449
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
450
+ this.operationId = data.operationId as string;
451
+ }
452
+ }
453
+ }
454
+
455
+ export interface DistancesAndEllipsesToRadiationLevelsCalculationResponseSchemaData {
456
+ distances: number[];
457
+ contourPoints: Entities.LocalPosition[];
458
+ nContourPoints: number[];
459
+ areas: number[];
460
+ resultCode: Enums.ResultCode;
461
+ messages: string[];
462
+ calculationElapsedTime: number;
463
+ operationId: string;
464
+ }
465
+
466
+ export class DistancesAndEllipsesToRadiationLevelsCalculationResponseSchema {
467
+ schema: Joi.ObjectSchema;
468
+ propertyTypes: Record<string, string>;
469
+
470
+ /**
471
+ * Schema for the DistancesAndEllipsesToRadiationLevels calculation response.
472
+ */
473
+ constructor() {
474
+ this.schema = Joi.object({
475
+ distances: Joi.array().items(Joi.number().unsafe()).allow(null),
476
+ contourPoints: Joi.array().items(new EntitySchemas.LocalPositionSchema().schema).allow(null),
477
+ nContourPoints: Joi.array().items(Joi.number().integer()).allow(null),
478
+ areas: Joi.array().items(Joi.number().unsafe()).allow(null),
479
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
480
+ messages: Joi.array().items(Joi.string()),
481
+ calculationElapsedTime: Joi.number().unsafe(),
482
+ operationId: Joi.string().uuid().allow(null),
483
+ }).unknown(true);
484
+
485
+ this.propertyTypes = {
486
+ distances: "number[]",
487
+ contourPoints: "Entities.LocalPosition[]",
488
+ nContourPoints: "number[]",
489
+ areas: "number[]",
490
+ };
491
+ }
492
+
493
+ validate(data: DistancesAndEllipsesToRadiationLevelsCalculationResponseSchemaData): DistancesAndEllipsesToRadiationLevelsCalculationResponse {
494
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
495
+ if (error) {
496
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
497
+ }
498
+ return this.makeCalculationResponse(value);
499
+ }
500
+
501
+ makeCalculationResponse(data: DistancesAndEllipsesToRadiationLevelsCalculationResponseSchemaData): DistancesAndEllipsesToRadiationLevelsCalculationResponse {
502
+ return new DistancesAndEllipsesToRadiationLevelsCalculationResponse(
503
+ data.distances,
504
+ data.contourPoints,
505
+ data.nContourPoints,
506
+ data.areas,
507
+ data.resultCode,
508
+ data.messages,
509
+ data.calculationElapsedTime,
510
+ data.operationId
511
+ );
512
+ }
513
+ }
514
+
515
+ export interface DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationRequestSchemaData {
516
+ poolFireFlameResult: Entities.PoolFireFlameResult;
517
+ flameRecords: Entities.FlameRecord[];
518
+ flameRecordCount: number;
519
+ weather: Entities.Weather;
520
+ flammableParameters: Entities.FlammableParameters;
521
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
522
+ flammableOutputConfigCount: number;
523
+ }
524
+
525
+ class DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationRequest extends CalculationRequestBase {
526
+ poolFireFlameResult: Entities.PoolFireFlameResult;
527
+ flameRecords: Entities.FlameRecord[];
528
+ flameRecordCount: number;
529
+ weather: Entities.Weather;
530
+ flammableParameters: Entities.FlammableParameters;
531
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
532
+ flammableOutputConfigCount: number;
533
+
534
+ /**
535
+ * DistancesAndEllipsesToRadiationLevelsForPoolFires calculation request class.
536
+ *
537
+ * @param {Entities.PoolFireFlameResult} poolFireFlameResult - Scalar pool fire flame results.
538
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
539
+ * @param {number} flameRecordCount - Number of Flame Records.
540
+ * @param {Entities.Weather} weather - A Weather entity.
541
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
542
+ * @param {Entities.FlammableOutputConfig[]} flammableOutputConfigs - An Array of Flammable Output Configs.
543
+ * @param {number} flammableOutputConfigCount - Number of radiation levels.
544
+ */
545
+ constructor(
546
+ poolFireFlameResult: Entities.PoolFireFlameResult,
547
+ flameRecords: Entities.FlameRecord[],
548
+ flameRecordCount: number,
549
+ weather: Entities.Weather,
550
+ flammableParameters: Entities.FlammableParameters,
551
+ flammableOutputConfigs: Entities.FlammableOutputConfig[],
552
+ flammableOutputConfigCount: number
553
+ ) {
554
+ super();
555
+ this.poolFireFlameResult = poolFireFlameResult;
556
+ this.flameRecords = flameRecords;
557
+ this.flameRecordCount = flameRecordCount;
558
+ this.weather = weather;
559
+ this.flammableParameters = flammableParameters;
560
+ this.flammableOutputConfigs = flammableOutputConfigs;
561
+ this.flammableOutputConfigCount = flammableOutputConfigCount;
562
+ }
563
+ }
564
+
565
+ export class DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationRequestSchema {
566
+ schema: Joi.ObjectSchema;
567
+ propertyTypes: Record<string, string>;
568
+
569
+ /**
570
+ * Schema for the DistancesAndEllipsesToRadiationLevelsForPoolFires calculation request.
571
+ */
572
+ constructor() {
573
+ this.schema = Joi.object({
574
+ poolFireFlameResult: new EntitySchemas.PoolFireFlameResultSchema().schema,
575
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
576
+ flameRecordCount: Joi.number().integer(),
577
+ weather: new EntitySchemas.WeatherSchema().schema,
578
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
579
+ flammableOutputConfigs: Joi.array().items(new EntitySchemas.FlammableOutputConfigSchema().schema).allow(null),
580
+ flammableOutputConfigCount: Joi.number().integer(),
581
+ }).unknown(true);
582
+
583
+ this.propertyTypes = {
584
+ poolFireFlameResult: "Entities.PoolFireFlameResult",
585
+ flameRecords: "Entities.FlameRecord[]",
586
+ flameRecordCount: "number",
587
+ weather: "Entities.Weather",
588
+ flammableParameters: "Entities.FlammableParameters",
589
+ flammableOutputConfigs: "Entities.FlammableOutputConfig[]",
590
+ flammableOutputConfigCount: "number",
591
+ };
592
+ }
593
+
594
+ validate(data: DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationRequestSchemaData): DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationRequest {
595
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
596
+ if (error) {
597
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
598
+ }
599
+ return this.makeCalculationRequest(value);
600
+ }
601
+
602
+ makeCalculationRequest(data: DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationRequestSchemaData): DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationRequest {
603
+ return new DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationRequest(
604
+ data.poolFireFlameResult,
605
+ data.flameRecords,
606
+ data.flameRecordCount,
607
+ data.weather,
608
+ data.flammableParameters,
609
+ data.flammableOutputConfigs,
610
+ data.flammableOutputConfigCount
611
+ );
612
+ }
613
+ }
614
+
615
+ export class DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculation extends CalculationBase {
616
+ poolFireFlameResult: Entities.PoolFireFlameResult;
617
+ flameRecords: Entities.FlameRecord[];
618
+ flameRecordCount: number;
619
+ weather: Entities.Weather;
620
+ flammableParameters: Entities.FlammableParameters;
621
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
622
+ flammableOutputConfigCount: number;
623
+ distances?: number[];
624
+ contourPoints?: Entities.LocalPosition[];
625
+ nContourPoints?: number[];
626
+ areas?: number[];
627
+
628
+ /**
629
+ * Calculates the distances and ellipses to specified radiation intensity levels from a flame model. This calculation can be called after pool fire calculation.
630
+ *
631
+ * @param {Entities.PoolFireFlameResult} poolFireFlameResult - Scalar pool fire flame results.
632
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
633
+ * @param {number} flameRecordCount - Number of Flame Records.
634
+ * @param {Entities.Weather} weather - A Weather entity.
635
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
636
+ * @param {Entities.FlammableOutputConfig[]} flammableOutputConfigs - An Array of Flammable Output Configs.
637
+ * @param {number} flammableOutputConfigCount - Number of radiation levels.
638
+ */
639
+ constructor(
640
+ poolFireFlameResult: Entities.PoolFireFlameResult,
641
+ flameRecords: Entities.FlameRecord[],
642
+ flameRecordCount: number,
643
+ weather: Entities.Weather,
644
+ flammableParameters: Entities.FlammableParameters,
645
+ flammableOutputConfigs: Entities.FlammableOutputConfig[],
646
+ flammableOutputConfigCount: number
647
+ ) {
648
+ super();
649
+ this.poolFireFlameResult = poolFireFlameResult;
650
+ this.flameRecords = flameRecords;
651
+ this.flameRecordCount = flameRecordCount;
652
+ this.weather = weather;
653
+ this.flammableParameters = flammableParameters;
654
+ this.flammableOutputConfigs = flammableOutputConfigs;
655
+ this.flammableOutputConfigCount = flammableOutputConfigCount;
656
+ }
657
+
658
+ async run() {
659
+ try {
660
+ const request = new DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationRequest(
661
+ this.poolFireFlameResult,
662
+ this.flameRecords,
663
+ this.flameRecordCount,
664
+ this.weather,
665
+ this.flammableParameters,
666
+ this.flammableOutputConfigs,
667
+ this.flammableOutputConfigCount
668
+ );
669
+
670
+ const schema = new DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationRequestSchema();
671
+ const validatedRequest = schema.validate(request);
672
+
673
+ const requestJson = JSON.stringify(validatedRequest);
674
+ const url = `${getAnalyticsApiTarget()}calculatedistancesandellipsestoradiationlevelsforpoolfires?clientId=${getClientAliasId()}`;
675
+
676
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
677
+
678
+ const response = await this.postRequest(url, requestJson);
679
+
680
+ if (response.status >= 200 && response.status < 300) {
681
+ const schema = new DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationResponseSchema();
682
+ const validatedResponse = schema.validate(response.data);
683
+
684
+ this.resultCode = validatedResponse.resultCode;
685
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
686
+ this.distances = validatedResponse.distances;
687
+ this.contourPoints = validatedResponse.contourPoints;
688
+ this.nContourPoints = validatedResponse.nContourPoints;
689
+ this.areas = validatedResponse.areas;
690
+ this.resultCode = validatedResponse.resultCode;
691
+ this.messages = validatedResponse.messages ?? [];
692
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
693
+ this.operationId = validatedResponse.operationId;
694
+ } else {
695
+ this.messages.push(...(validatedResponse.messages ?? []));
696
+ }
697
+ } else {
698
+ this.handleFailedResponse(response);
699
+ }
700
+ } catch (error) {
701
+ if (error instanceof Error) {
702
+ this.messages.push(`Error: ${error.message}`);
703
+ } else {
704
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
705
+ }
706
+ console.error(error);
707
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
708
+ }
709
+
710
+ return this.resultCode;
711
+ }
712
+
713
+ toString() {
714
+ const parts = ["* DistancesAndEllipsesToRadiationLevelsForPoolFires"];
715
+
716
+ parts.push("*** distances:");
717
+ parts.push(
718
+ this.distances && this.distances.length > 0
719
+ ? this.distances.map((point) => `distancesElement: ${point}`).join("\n")
720
+ : "distances does not contain any elements"
721
+ );
722
+ parts.push("*** contourPoints:");
723
+ parts.push(
724
+ this.contourPoints && this.contourPoints.length > 0
725
+ ? this.contourPoints.map((point) => `contourPointsElement: ${point}`).join("\n")
726
+ : "contourPoints does not contain any elements"
727
+ );
728
+ parts.push("*** nContourPoints:");
729
+ parts.push(
730
+ this.nContourPoints && this.nContourPoints.length > 0
731
+ ? this.nContourPoints.map((point) => `nContourPointsElement: ${point}`).join("\n")
732
+ : "nContourPoints does not contain any elements"
733
+ );
734
+ parts.push("*** areas:");
735
+ parts.push(
736
+ this.areas && this.areas.length > 0
737
+ ? this.areas.map((point) => `areasElement: ${point}`).join("\n")
738
+ : "areas does not contain any elements"
739
+ );
740
+ parts.push(`resultCode: ${String(this.resultCode)}`);
741
+ parts.push("*** messages:");
742
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
743
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
744
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
745
+
746
+ return parts.join("\n");
747
+ }
748
+ }
749
+
750
+ export class DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationResponse extends CalculationResponseBase {
751
+ distances: number[];
752
+ contourPoints: Entities.LocalPosition[];
753
+ nContourPoints: number[];
754
+ areas: number[];
755
+
756
+ /**
757
+ * DistancesAndEllipsesToRadiationLevelsForPoolFires calculation response class.
758
+ *
759
+ * @param {number[]} distances - An array of distances to radiation levels, corresponding to the Flammable Output Configs.
760
+ * @param {Entities.LocalPosition[]} contourPoints - Contour points of radiation ellipses to radiation levels.
761
+ * @param {number[]} nContourPoints - An array of the number of contour points, corresponding to the Flammable Output Configs.
762
+ * @param {number[]} areas - An array of areas of the ellipses to radiation levels, responding to the Flammable Output Configs.
763
+ */
764
+ constructor(
765
+ distances: number[],
766
+ contourPoints: Entities.LocalPosition[],
767
+ nContourPoints: number[],
768
+ areas: number[],
769
+ resultCode: Enums.ResultCode,
770
+ messages: string[],
771
+ calculationElapsedTime: number,
772
+ operationId: string
773
+ ) {
774
+ super();
775
+ this.distances = distances;
776
+ this.contourPoints = contourPoints;
777
+ this.nContourPoints = nContourPoints;
778
+ this.areas = areas;
779
+ this.resultCode = resultCode;
780
+ this.messages = messages;
781
+ this.calculationElapsedTime = calculationElapsedTime;
782
+ this.operationId = operationId;
783
+ }
784
+
785
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
786
+ if (data.distances && Array.isArray(data.distances)) {
787
+ this.distances = data.distances.map((item) => parseFloat(item));
788
+ }
789
+ if (data.contourPoints && Array.isArray(data.contourPoints)) {
790
+ this.contourPoints = data.contourPoints.map(
791
+ (item) => {
792
+ const record = new Entities.LocalPosition();
793
+ record.initialiseFromDictionary(item);
794
+ return record;
795
+ }
796
+ );
797
+ }
798
+ if (data.nContourPoints && Array.isArray(data.nContourPoints)) {
799
+ this.nContourPoints = data.nContourPoints.map((item) => parseInt(item));
800
+ }
801
+ if (data.areas && Array.isArray(data.areas)) {
802
+ this.areas = data.areas.map((item) => parseFloat(item));
803
+ }
804
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
805
+ this.resultCode = data.resultCode as Enums.ResultCode;
806
+ }
807
+ this.messages = this.messages ?? [];
808
+ if (data.messages && Array.isArray(data.messages)) {
809
+ this.messages.push(...data.messages);
810
+ }
811
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
812
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
813
+ }
814
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
815
+ this.operationId = data.operationId as string;
816
+ }
817
+ }
818
+ }
819
+
820
+ export interface DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationResponseSchemaData {
821
+ distances: number[];
822
+ contourPoints: Entities.LocalPosition[];
823
+ nContourPoints: number[];
824
+ areas: number[];
825
+ resultCode: Enums.ResultCode;
826
+ messages: string[];
827
+ calculationElapsedTime: number;
828
+ operationId: string;
829
+ }
830
+
831
+ export class DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationResponseSchema {
832
+ schema: Joi.ObjectSchema;
833
+ propertyTypes: Record<string, string>;
834
+
835
+ /**
836
+ * Schema for the DistancesAndEllipsesToRadiationLevelsForPoolFires calculation response.
837
+ */
838
+ constructor() {
839
+ this.schema = Joi.object({
840
+ distances: Joi.array().items(Joi.number().unsafe()).allow(null),
841
+ contourPoints: Joi.array().items(new EntitySchemas.LocalPositionSchema().schema).allow(null),
842
+ nContourPoints: Joi.array().items(Joi.number().integer()).allow(null),
843
+ areas: Joi.array().items(Joi.number().unsafe()).allow(null),
844
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
845
+ messages: Joi.array().items(Joi.string()),
846
+ calculationElapsedTime: Joi.number().unsafe(),
847
+ operationId: Joi.string().uuid().allow(null),
848
+ }).unknown(true);
849
+
850
+ this.propertyTypes = {
851
+ distances: "number[]",
852
+ contourPoints: "Entities.LocalPosition[]",
853
+ nContourPoints: "number[]",
854
+ areas: "number[]",
855
+ };
856
+ }
857
+
858
+ validate(data: DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationResponseSchemaData): DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationResponse {
859
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
860
+ if (error) {
861
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
862
+ }
863
+ return this.makeCalculationResponse(value);
864
+ }
865
+
866
+ makeCalculationResponse(data: DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationResponseSchemaData): DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationResponse {
867
+ return new DistancesAndEllipsesToRadiationLevelsForPoolFiresCalculationResponse(
868
+ data.distances,
869
+ data.contourPoints,
870
+ data.nContourPoints,
871
+ data.areas,
872
+ data.resultCode,
873
+ data.messages,
874
+ data.calculationElapsedTime,
875
+ data.operationId
876
+ );
877
+ }
878
+ }
879
+
880
+ export interface DistancesToRadiationLevelsCalculationRequestSchemaData {
881
+ flameResult: Entities.FlameResult;
882
+ flameRecords: Entities.FlameRecord[];
883
+ flameRecordCount: number;
884
+ weather: Entities.Weather;
885
+ flammableParameters: Entities.FlammableParameters;
886
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
887
+ flammableOutputConfigCount: number;
888
+ }
889
+
890
+ class DistancesToRadiationLevelsCalculationRequest extends CalculationRequestBase {
891
+ flameResult: Entities.FlameResult;
892
+ flameRecords: Entities.FlameRecord[];
893
+ flameRecordCount: number;
894
+ weather: Entities.Weather;
895
+ flammableParameters: Entities.FlammableParameters;
896
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
897
+ flammableOutputConfigCount: number;
898
+
899
+ /**
900
+ * DistancesToRadiationLevels calculation request class.
901
+ *
902
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
903
+ * @param {Entities.FlameRecord[]} flameRecords - An Array of Flame Records.
904
+ * @param {number} flameRecordCount - Number of Flame Records.
905
+ * @param {Entities.Weather} weather - A Weather entity.
906
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
907
+ * @param {Entities.FlammableOutputConfig[]} flammableOutputConfigs - An array of Flammable Output Configs.
908
+ * @param {number} flammableOutputConfigCount - Number of Flammable Output Configs.
909
+ */
910
+ constructor(
911
+ flameResult: Entities.FlameResult,
912
+ flameRecords: Entities.FlameRecord[],
913
+ flameRecordCount: number,
914
+ weather: Entities.Weather,
915
+ flammableParameters: Entities.FlammableParameters,
916
+ flammableOutputConfigs: Entities.FlammableOutputConfig[],
917
+ flammableOutputConfigCount: number
918
+ ) {
919
+ super();
920
+ this.flameResult = flameResult;
921
+ this.flameRecords = flameRecords;
922
+ this.flameRecordCount = flameRecordCount;
923
+ this.weather = weather;
924
+ this.flammableParameters = flammableParameters;
925
+ this.flammableOutputConfigs = flammableOutputConfigs;
926
+ this.flammableOutputConfigCount = flammableOutputConfigCount;
927
+ }
928
+ }
929
+
930
+ export class DistancesToRadiationLevelsCalculationRequestSchema {
931
+ schema: Joi.ObjectSchema;
932
+ propertyTypes: Record<string, string>;
933
+
934
+ /**
935
+ * Schema for the DistancesToRadiationLevels calculation request.
936
+ */
937
+ constructor() {
938
+ this.schema = Joi.object({
939
+ flameResult: new EntitySchemas.FlameResultSchema().schema,
940
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
941
+ flameRecordCount: Joi.number().integer(),
942
+ weather: new EntitySchemas.WeatherSchema().schema,
943
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
944
+ flammableOutputConfigs: Joi.array().items(new EntitySchemas.FlammableOutputConfigSchema().schema).allow(null),
945
+ flammableOutputConfigCount: Joi.number().integer(),
946
+ }).unknown(true);
947
+
948
+ this.propertyTypes = {
949
+ flameResult: "Entities.FlameResult",
950
+ flameRecords: "Entities.FlameRecord[]",
951
+ flameRecordCount: "number",
952
+ weather: "Entities.Weather",
953
+ flammableParameters: "Entities.FlammableParameters",
954
+ flammableOutputConfigs: "Entities.FlammableOutputConfig[]",
955
+ flammableOutputConfigCount: "number",
956
+ };
957
+ }
958
+
959
+ validate(data: DistancesToRadiationLevelsCalculationRequestSchemaData): DistancesToRadiationLevelsCalculationRequest {
960
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
961
+ if (error) {
962
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
963
+ }
964
+ return this.makeCalculationRequest(value);
965
+ }
966
+
967
+ makeCalculationRequest(data: DistancesToRadiationLevelsCalculationRequestSchemaData): DistancesToRadiationLevelsCalculationRequest {
968
+ return new DistancesToRadiationLevelsCalculationRequest(
969
+ data.flameResult,
970
+ data.flameRecords,
971
+ data.flameRecordCount,
972
+ data.weather,
973
+ data.flammableParameters,
974
+ data.flammableOutputConfigs,
975
+ data.flammableOutputConfigCount
976
+ );
977
+ }
978
+ }
979
+
980
+ export class DistancesToRadiationLevelsCalculation extends CalculationBase {
981
+ flameResult: Entities.FlameResult;
982
+ flameRecords: Entities.FlameRecord[];
983
+ flameRecordCount: number;
984
+ weather: Entities.Weather;
985
+ flammableParameters: Entities.FlammableParameters;
986
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
987
+ flammableOutputConfigCount: number;
988
+ distances?: number[];
989
+
990
+ /**
991
+ * Calculates the distances to specified radiation intensity levels from a flame model. This calculation can be called after any type of fire calculation (fireball, jet fire, pool fire).
992
+ *
993
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
994
+ * @param {Entities.FlameRecord[]} flameRecords - An Array of Flame Records.
995
+ * @param {number} flameRecordCount - Number of Flame Records.
996
+ * @param {Entities.Weather} weather - A Weather entity.
997
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
998
+ * @param {Entities.FlammableOutputConfig[]} flammableOutputConfigs - An array of Flammable Output Configs.
999
+ * @param {number} flammableOutputConfigCount - Number of Flammable Output Configs.
1000
+ */
1001
+ constructor(
1002
+ flameResult: Entities.FlameResult,
1003
+ flameRecords: Entities.FlameRecord[],
1004
+ flameRecordCount: number,
1005
+ weather: Entities.Weather,
1006
+ flammableParameters: Entities.FlammableParameters,
1007
+ flammableOutputConfigs: Entities.FlammableOutputConfig[],
1008
+ flammableOutputConfigCount: number
1009
+ ) {
1010
+ super();
1011
+ this.flameResult = flameResult;
1012
+ this.flameRecords = flameRecords;
1013
+ this.flameRecordCount = flameRecordCount;
1014
+ this.weather = weather;
1015
+ this.flammableParameters = flammableParameters;
1016
+ this.flammableOutputConfigs = flammableOutputConfigs;
1017
+ this.flammableOutputConfigCount = flammableOutputConfigCount;
1018
+ }
1019
+
1020
+ async run() {
1021
+ try {
1022
+ const request = new DistancesToRadiationLevelsCalculationRequest(
1023
+ this.flameResult,
1024
+ this.flameRecords,
1025
+ this.flameRecordCount,
1026
+ this.weather,
1027
+ this.flammableParameters,
1028
+ this.flammableOutputConfigs,
1029
+ this.flammableOutputConfigCount
1030
+ );
1031
+
1032
+ const schema = new DistancesToRadiationLevelsCalculationRequestSchema();
1033
+ const validatedRequest = schema.validate(request);
1034
+
1035
+ const requestJson = JSON.stringify(validatedRequest);
1036
+ const url = `${getAnalyticsApiTarget()}calculatedistancestoradiationlevels?clientId=${getClientAliasId()}`;
1037
+
1038
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
1039
+
1040
+ const response = await this.postRequest(url, requestJson);
1041
+
1042
+ if (response.status >= 200 && response.status < 300) {
1043
+ const schema = new DistancesToRadiationLevelsCalculationResponseSchema();
1044
+ const validatedResponse = schema.validate(response.data);
1045
+
1046
+ this.resultCode = validatedResponse.resultCode;
1047
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
1048
+ this.distances = validatedResponse.distances;
1049
+ this.resultCode = validatedResponse.resultCode;
1050
+ this.messages = validatedResponse.messages ?? [];
1051
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
1052
+ this.operationId = validatedResponse.operationId;
1053
+ } else {
1054
+ this.messages.push(...(validatedResponse.messages ?? []));
1055
+ }
1056
+ } else {
1057
+ this.handleFailedResponse(response);
1058
+ }
1059
+ } catch (error) {
1060
+ if (error instanceof Error) {
1061
+ this.messages.push(`Error: ${error.message}`);
1062
+ } else {
1063
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
1064
+ }
1065
+ console.error(error);
1066
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
1067
+ }
1068
+
1069
+ return this.resultCode;
1070
+ }
1071
+
1072
+ toString() {
1073
+ const parts = ["* DistancesToRadiationLevels"];
1074
+
1075
+ parts.push("*** distances:");
1076
+ parts.push(
1077
+ this.distances && this.distances.length > 0
1078
+ ? this.distances.map((point) => `distancesElement: ${point}`).join("\n")
1079
+ : "distances does not contain any elements"
1080
+ );
1081
+ parts.push(`resultCode: ${String(this.resultCode)}`);
1082
+ parts.push("*** messages:");
1083
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
1084
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
1085
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
1086
+
1087
+ return parts.join("\n");
1088
+ }
1089
+ }
1090
+
1091
+ export class DistancesToRadiationLevelsCalculationResponse extends CalculationResponseBase {
1092
+ distances: number[];
1093
+
1094
+ /**
1095
+ * DistancesToRadiationLevels calculation response class.
1096
+ *
1097
+ * @param {number[]} distances - An array of distances to radiation levels, corresponding to the Flammable Output Configs.
1098
+ */
1099
+ constructor(
1100
+ distances: number[],
1101
+ resultCode: Enums.ResultCode,
1102
+ messages: string[],
1103
+ calculationElapsedTime: number,
1104
+ operationId: string
1105
+ ) {
1106
+ super();
1107
+ this.distances = distances;
1108
+ this.resultCode = resultCode;
1109
+ this.messages = messages;
1110
+ this.calculationElapsedTime = calculationElapsedTime;
1111
+ this.operationId = operationId;
1112
+ }
1113
+
1114
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
1115
+ if (data.distances && Array.isArray(data.distances)) {
1116
+ this.distances = data.distances.map((item) => parseFloat(item));
1117
+ }
1118
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
1119
+ this.resultCode = data.resultCode as Enums.ResultCode;
1120
+ }
1121
+ this.messages = this.messages ?? [];
1122
+ if (data.messages && Array.isArray(data.messages)) {
1123
+ this.messages.push(...data.messages);
1124
+ }
1125
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
1126
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
1127
+ }
1128
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
1129
+ this.operationId = data.operationId as string;
1130
+ }
1131
+ }
1132
+ }
1133
+
1134
+ export interface DistancesToRadiationLevelsCalculationResponseSchemaData {
1135
+ distances: number[];
1136
+ resultCode: Enums.ResultCode;
1137
+ messages: string[];
1138
+ calculationElapsedTime: number;
1139
+ operationId: string;
1140
+ }
1141
+
1142
+ export class DistancesToRadiationLevelsCalculationResponseSchema {
1143
+ schema: Joi.ObjectSchema;
1144
+ propertyTypes: Record<string, string>;
1145
+
1146
+ /**
1147
+ * Schema for the DistancesToRadiationLevels calculation response.
1148
+ */
1149
+ constructor() {
1150
+ this.schema = Joi.object({
1151
+ distances: Joi.array().items(Joi.number().unsafe()).allow(null),
1152
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
1153
+ messages: Joi.array().items(Joi.string()),
1154
+ calculationElapsedTime: Joi.number().unsafe(),
1155
+ operationId: Joi.string().uuid().allow(null),
1156
+ }).unknown(true);
1157
+
1158
+ this.propertyTypes = {
1159
+ distances: "number[]",
1160
+ };
1161
+ }
1162
+
1163
+ validate(data: DistancesToRadiationLevelsCalculationResponseSchemaData): DistancesToRadiationLevelsCalculationResponse {
1164
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
1165
+ if (error) {
1166
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
1167
+ }
1168
+ return this.makeCalculationResponse(value);
1169
+ }
1170
+
1171
+ makeCalculationResponse(data: DistancesToRadiationLevelsCalculationResponseSchemaData): DistancesToRadiationLevelsCalculationResponse {
1172
+ return new DistancesToRadiationLevelsCalculationResponse(
1173
+ data.distances,
1174
+ data.resultCode,
1175
+ data.messages,
1176
+ data.calculationElapsedTime,
1177
+ data.operationId
1178
+ );
1179
+ }
1180
+ }
1181
+
1182
+ export interface DistanceToRadiationCalculationRequestSchemaData {
1183
+ flameResult: Entities.FlameResult;
1184
+ flameRecords: Entities.FlameRecord[];
1185
+ flameRecordCount: number;
1186
+ weather: Entities.Weather;
1187
+ flammableParameters: Entities.FlammableParameters;
1188
+ flammableOutputConfig: Entities.FlammableOutputConfig;
1189
+ }
1190
+
1191
+ class DistanceToRadiationCalculationRequest extends CalculationRequestBase {
1192
+ flameResult: Entities.FlameResult;
1193
+ flameRecords: Entities.FlameRecord[];
1194
+ flameRecordCount: number;
1195
+ weather: Entities.Weather;
1196
+ flammableParameters: Entities.FlammableParameters;
1197
+ flammableOutputConfig: Entities.FlammableOutputConfig;
1198
+
1199
+ /**
1200
+ * DistanceToRadiation calculation request class.
1201
+ *
1202
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
1203
+ * @param {Entities.FlameRecord[]} flameRecords - An Array of Flame Records.
1204
+ * @param {number} flameRecordCount - Number of Flame Records.
1205
+ * @param {Entities.Weather} weather - A Weather entity.
1206
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
1207
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity.
1208
+ */
1209
+ constructor(
1210
+ flameResult: Entities.FlameResult,
1211
+ flameRecords: Entities.FlameRecord[],
1212
+ flameRecordCount: number,
1213
+ weather: Entities.Weather,
1214
+ flammableParameters: Entities.FlammableParameters,
1215
+ flammableOutputConfig: Entities.FlammableOutputConfig
1216
+ ) {
1217
+ super();
1218
+ this.flameResult = flameResult;
1219
+ this.flameRecords = flameRecords;
1220
+ this.flameRecordCount = flameRecordCount;
1221
+ this.weather = weather;
1222
+ this.flammableParameters = flammableParameters;
1223
+ this.flammableOutputConfig = flammableOutputConfig;
1224
+ }
1225
+ }
1226
+
1227
+ export class DistanceToRadiationCalculationRequestSchema {
1228
+ schema: Joi.ObjectSchema;
1229
+ propertyTypes: Record<string, string>;
1230
+
1231
+ /**
1232
+ * Schema for the DistanceToRadiation calculation request.
1233
+ */
1234
+ constructor() {
1235
+ this.schema = Joi.object({
1236
+ flameResult: new EntitySchemas.FlameResultSchema().schema,
1237
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
1238
+ flameRecordCount: Joi.number().integer(),
1239
+ weather: new EntitySchemas.WeatherSchema().schema,
1240
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
1241
+ flammableOutputConfig: new EntitySchemas.FlammableOutputConfigSchema().schema,
1242
+ }).unknown(true);
1243
+
1244
+ this.propertyTypes = {
1245
+ flameResult: "Entities.FlameResult",
1246
+ flameRecords: "Entities.FlameRecord[]",
1247
+ flameRecordCount: "number",
1248
+ weather: "Entities.Weather",
1249
+ flammableParameters: "Entities.FlammableParameters",
1250
+ flammableOutputConfig: "Entities.FlammableOutputConfig",
1251
+ };
1252
+ }
1253
+
1254
+ validate(data: DistanceToRadiationCalculationRequestSchemaData): DistanceToRadiationCalculationRequest {
1255
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
1256
+ if (error) {
1257
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
1258
+ }
1259
+ return this.makeCalculationRequest(value);
1260
+ }
1261
+
1262
+ makeCalculationRequest(data: DistanceToRadiationCalculationRequestSchemaData): DistanceToRadiationCalculationRequest {
1263
+ return new DistanceToRadiationCalculationRequest(
1264
+ data.flameResult,
1265
+ data.flameRecords,
1266
+ data.flameRecordCount,
1267
+ data.weather,
1268
+ data.flammableParameters,
1269
+ data.flammableOutputConfig
1270
+ );
1271
+ }
1272
+ }
1273
+
1274
+ export class DistanceToRadiationCalculation extends CalculationBase {
1275
+ flameResult: Entities.FlameResult;
1276
+ flameRecords: Entities.FlameRecord[];
1277
+ flameRecordCount: number;
1278
+ weather: Entities.Weather;
1279
+ flammableParameters: Entities.FlammableParameters;
1280
+ flammableOutputConfig: Entities.FlammableOutputConfig;
1281
+ distance?: number;
1282
+
1283
+ /**
1284
+ * Calculates the distance to a specified radiation intensity or lethality level from a flame model. This calculation an be called after any type of fire calculation (fireball, jet fire, pool fire).
1285
+ *
1286
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
1287
+ * @param {Entities.FlameRecord[]} flameRecords - An Array of Flame Records.
1288
+ * @param {number} flameRecordCount - Number of Flame Records.
1289
+ * @param {Entities.Weather} weather - A Weather entity.
1290
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
1291
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity.
1292
+ */
1293
+ constructor(
1294
+ flameResult: Entities.FlameResult,
1295
+ flameRecords: Entities.FlameRecord[],
1296
+ flameRecordCount: number,
1297
+ weather: Entities.Weather,
1298
+ flammableParameters: Entities.FlammableParameters,
1299
+ flammableOutputConfig: Entities.FlammableOutputConfig
1300
+ ) {
1301
+ super();
1302
+ this.flameResult = flameResult;
1303
+ this.flameRecords = flameRecords;
1304
+ this.flameRecordCount = flameRecordCount;
1305
+ this.weather = weather;
1306
+ this.flammableParameters = flammableParameters;
1307
+ this.flammableOutputConfig = flammableOutputConfig;
1308
+ }
1309
+
1310
+ async run() {
1311
+ try {
1312
+ const request = new DistanceToRadiationCalculationRequest(
1313
+ this.flameResult,
1314
+ this.flameRecords,
1315
+ this.flameRecordCount,
1316
+ this.weather,
1317
+ this.flammableParameters,
1318
+ this.flammableOutputConfig
1319
+ );
1320
+
1321
+ const schema = new DistanceToRadiationCalculationRequestSchema();
1322
+ const validatedRequest = schema.validate(request);
1323
+
1324
+ const requestJson = JSON.stringify(validatedRequest);
1325
+ const url = `${getAnalyticsApiTarget()}calculatedistancetoradiation?clientId=${getClientAliasId()}`;
1326
+
1327
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
1328
+
1329
+ const response = await this.postRequest(url, requestJson);
1330
+
1331
+ if (response.status >= 200 && response.status < 300) {
1332
+ const schema = new DistanceToRadiationCalculationResponseSchema();
1333
+ const validatedResponse = schema.validate(response.data);
1334
+
1335
+ this.resultCode = validatedResponse.resultCode;
1336
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
1337
+ this.distance = validatedResponse.distance;
1338
+ this.resultCode = validatedResponse.resultCode;
1339
+ this.messages = validatedResponse.messages ?? [];
1340
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
1341
+ this.operationId = validatedResponse.operationId;
1342
+ } else {
1343
+ this.messages.push(...(validatedResponse.messages ?? []));
1344
+ }
1345
+ } else {
1346
+ this.handleFailedResponse(response);
1347
+ }
1348
+ } catch (error) {
1349
+ if (error instanceof Error) {
1350
+ this.messages.push(`Error: ${error.message}`);
1351
+ } else {
1352
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
1353
+ }
1354
+ console.error(error);
1355
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
1356
+ }
1357
+
1358
+ return this.resultCode;
1359
+ }
1360
+
1361
+ toString() {
1362
+ const parts = ["* DistanceToRadiation"];
1363
+
1364
+ parts.push(`distance: ${String(this.distance)}`);
1365
+ parts.push(`resultCode: ${String(this.resultCode)}`);
1366
+ parts.push("*** messages:");
1367
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
1368
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
1369
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
1370
+
1371
+ return parts.join("\n");
1372
+ }
1373
+ }
1374
+
1375
+ export class DistanceToRadiationCalculationResponse extends CalculationResponseBase {
1376
+ distance: number;
1377
+
1378
+ /**
1379
+ * DistanceToRadiation calculation response class.
1380
+ *
1381
+ * @param {number} distance - Distance to radiation level.
1382
+ */
1383
+ constructor(
1384
+ distance: number,
1385
+ resultCode: Enums.ResultCode,
1386
+ messages: string[],
1387
+ calculationElapsedTime: number,
1388
+ operationId: string
1389
+ ) {
1390
+ super();
1391
+ this.distance = distance;
1392
+ this.resultCode = resultCode;
1393
+ this.messages = messages;
1394
+ this.calculationElapsedTime = calculationElapsedTime;
1395
+ this.operationId = operationId;
1396
+ }
1397
+
1398
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
1399
+ if (data.distance !== undefined && typeof data.distance === "number") {
1400
+ this.distance = data.distance as number;
1401
+ }
1402
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
1403
+ this.resultCode = data.resultCode as Enums.ResultCode;
1404
+ }
1405
+ this.messages = this.messages ?? [];
1406
+ if (data.messages && Array.isArray(data.messages)) {
1407
+ this.messages.push(...data.messages);
1408
+ }
1409
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
1410
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
1411
+ }
1412
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
1413
+ this.operationId = data.operationId as string;
1414
+ }
1415
+ }
1416
+ }
1417
+
1418
+ export interface DistanceToRadiationCalculationResponseSchemaData {
1419
+ distance: number;
1420
+ resultCode: Enums.ResultCode;
1421
+ messages: string[];
1422
+ calculationElapsedTime: number;
1423
+ operationId: string;
1424
+ }
1425
+
1426
+ export class DistanceToRadiationCalculationResponseSchema {
1427
+ schema: Joi.ObjectSchema;
1428
+ propertyTypes: Record<string, string>;
1429
+
1430
+ /**
1431
+ * Schema for the DistanceToRadiation calculation response.
1432
+ */
1433
+ constructor() {
1434
+ this.schema = Joi.object({
1435
+ distance: Joi.number().unsafe(),
1436
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
1437
+ messages: Joi.array().items(Joi.string()),
1438
+ calculationElapsedTime: Joi.number().unsafe(),
1439
+ operationId: Joi.string().uuid().allow(null),
1440
+ }).unknown(true);
1441
+
1442
+ this.propertyTypes = {
1443
+ distance: "number",
1444
+ };
1445
+ }
1446
+
1447
+ validate(data: DistanceToRadiationCalculationResponseSchemaData): DistanceToRadiationCalculationResponse {
1448
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
1449
+ if (error) {
1450
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
1451
+ }
1452
+ return this.makeCalculationResponse(value);
1453
+ }
1454
+
1455
+ makeCalculationResponse(data: DistanceToRadiationCalculationResponseSchemaData): DistanceToRadiationCalculationResponse {
1456
+ return new DistanceToRadiationCalculationResponse(
1457
+ data.distance,
1458
+ data.resultCode,
1459
+ data.messages,
1460
+ data.calculationElapsedTime,
1461
+ data.operationId
1462
+ );
1463
+ }
1464
+ }
1465
+
1466
+ export interface RadiationAtAPointCalculationRequestSchemaData {
1467
+ flameResult: Entities.FlameResult;
1468
+ flameRecords: Entities.FlameRecord[];
1469
+ flameRecordCount: number;
1470
+ weather: Entities.Weather;
1471
+ flammableParameters: Entities.FlammableParameters;
1472
+ flammableOutputConfig: Entities.FlammableOutputConfig;
1473
+ }
1474
+
1475
+ class RadiationAtAPointCalculationRequest extends CalculationRequestBase {
1476
+ flameResult: Entities.FlameResult;
1477
+ flameRecords: Entities.FlameRecord[];
1478
+ flameRecordCount: number;
1479
+ weather: Entities.Weather;
1480
+ flammableParameters: Entities.FlammableParameters;
1481
+ flammableOutputConfig: Entities.FlammableOutputConfig;
1482
+
1483
+ /**
1484
+ * RadiationAtAPoint calculation request class.
1485
+ *
1486
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
1487
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
1488
+ * @param {number} flameRecordCount - Number of Flame Records.
1489
+ * @param {Entities.Weather} weather - A Weather entity.
1490
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
1491
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity, for setting the point coordinates.
1492
+ */
1493
+ constructor(
1494
+ flameResult: Entities.FlameResult,
1495
+ flameRecords: Entities.FlameRecord[],
1496
+ flameRecordCount: number,
1497
+ weather: Entities.Weather,
1498
+ flammableParameters: Entities.FlammableParameters,
1499
+ flammableOutputConfig: Entities.FlammableOutputConfig
1500
+ ) {
1501
+ super();
1502
+ this.flameResult = flameResult;
1503
+ this.flameRecords = flameRecords;
1504
+ this.flameRecordCount = flameRecordCount;
1505
+ this.weather = weather;
1506
+ this.flammableParameters = flammableParameters;
1507
+ this.flammableOutputConfig = flammableOutputConfig;
1508
+ }
1509
+ }
1510
+
1511
+ export class RadiationAtAPointCalculationRequestSchema {
1512
+ schema: Joi.ObjectSchema;
1513
+ propertyTypes: Record<string, string>;
1514
+
1515
+ /**
1516
+ * Schema for the RadiationAtAPoint calculation request.
1517
+ */
1518
+ constructor() {
1519
+ this.schema = Joi.object({
1520
+ flameResult: new EntitySchemas.FlameResultSchema().schema,
1521
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
1522
+ flameRecordCount: Joi.number().integer(),
1523
+ weather: new EntitySchemas.WeatherSchema().schema,
1524
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
1525
+ flammableOutputConfig: new EntitySchemas.FlammableOutputConfigSchema().schema,
1526
+ }).unknown(true);
1527
+
1528
+ this.propertyTypes = {
1529
+ flameResult: "Entities.FlameResult",
1530
+ flameRecords: "Entities.FlameRecord[]",
1531
+ flameRecordCount: "number",
1532
+ weather: "Entities.Weather",
1533
+ flammableParameters: "Entities.FlammableParameters",
1534
+ flammableOutputConfig: "Entities.FlammableOutputConfig",
1535
+ };
1536
+ }
1537
+
1538
+ validate(data: RadiationAtAPointCalculationRequestSchemaData): RadiationAtAPointCalculationRequest {
1539
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
1540
+ if (error) {
1541
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
1542
+ }
1543
+ return this.makeCalculationRequest(value);
1544
+ }
1545
+
1546
+ makeCalculationRequest(data: RadiationAtAPointCalculationRequestSchemaData): RadiationAtAPointCalculationRequest {
1547
+ return new RadiationAtAPointCalculationRequest(
1548
+ data.flameResult,
1549
+ data.flameRecords,
1550
+ data.flameRecordCount,
1551
+ data.weather,
1552
+ data.flammableParameters,
1553
+ data.flammableOutputConfig
1554
+ );
1555
+ }
1556
+ }
1557
+
1558
+ export class RadiationAtAPointCalculation extends CalculationBase {
1559
+ flameResult: Entities.FlameResult;
1560
+ flameRecords: Entities.FlameRecord[];
1561
+ flameRecordCount: number;
1562
+ weather: Entities.Weather;
1563
+ flammableParameters: Entities.FlammableParameters;
1564
+ flammableOutputConfig: Entities.FlammableOutputConfig;
1565
+ radiation?: number;
1566
+
1567
+ /**
1568
+ * Calculates the radiation at coordinates x, y, z from a flammable model.
1569
+ *
1570
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
1571
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
1572
+ * @param {number} flameRecordCount - Number of Flame Records.
1573
+ * @param {Entities.Weather} weather - A Weather entity.
1574
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
1575
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity, for setting the point coordinates.
1576
+ */
1577
+ constructor(
1578
+ flameResult: Entities.FlameResult,
1579
+ flameRecords: Entities.FlameRecord[],
1580
+ flameRecordCount: number,
1581
+ weather: Entities.Weather,
1582
+ flammableParameters: Entities.FlammableParameters,
1583
+ flammableOutputConfig: Entities.FlammableOutputConfig
1584
+ ) {
1585
+ super();
1586
+ this.flameResult = flameResult;
1587
+ this.flameRecords = flameRecords;
1588
+ this.flameRecordCount = flameRecordCount;
1589
+ this.weather = weather;
1590
+ this.flammableParameters = flammableParameters;
1591
+ this.flammableOutputConfig = flammableOutputConfig;
1592
+ }
1593
+
1594
+ async run() {
1595
+ try {
1596
+ const request = new RadiationAtAPointCalculationRequest(
1597
+ this.flameResult,
1598
+ this.flameRecords,
1599
+ this.flameRecordCount,
1600
+ this.weather,
1601
+ this.flammableParameters,
1602
+ this.flammableOutputConfig
1603
+ );
1604
+
1605
+ const schema = new RadiationAtAPointCalculationRequestSchema();
1606
+ const validatedRequest = schema.validate(request);
1607
+
1608
+ const requestJson = JSON.stringify(validatedRequest);
1609
+ const url = `${getAnalyticsApiTarget()}calculateradiationatapoint?clientId=${getClientAliasId()}`;
1610
+
1611
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
1612
+
1613
+ const response = await this.postRequest(url, requestJson);
1614
+
1615
+ if (response.status >= 200 && response.status < 300) {
1616
+ const schema = new RadiationAtAPointCalculationResponseSchema();
1617
+ const validatedResponse = schema.validate(response.data);
1618
+
1619
+ this.resultCode = validatedResponse.resultCode;
1620
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
1621
+ this.radiation = validatedResponse.radiation;
1622
+ this.resultCode = validatedResponse.resultCode;
1623
+ this.messages = validatedResponse.messages ?? [];
1624
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
1625
+ this.operationId = validatedResponse.operationId;
1626
+ } else {
1627
+ this.messages.push(...(validatedResponse.messages ?? []));
1628
+ }
1629
+ } else {
1630
+ this.handleFailedResponse(response);
1631
+ }
1632
+ } catch (error) {
1633
+ if (error instanceof Error) {
1634
+ this.messages.push(`Error: ${error.message}`);
1635
+ } else {
1636
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
1637
+ }
1638
+ console.error(error);
1639
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
1640
+ }
1641
+
1642
+ return this.resultCode;
1643
+ }
1644
+
1645
+ toString() {
1646
+ const parts = ["* RadiationAtAPoint"];
1647
+
1648
+ parts.push(`radiation: ${String(this.radiation)}`);
1649
+ parts.push(`resultCode: ${String(this.resultCode)}`);
1650
+ parts.push("*** messages:");
1651
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
1652
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
1653
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
1654
+
1655
+ return parts.join("\n");
1656
+ }
1657
+ }
1658
+
1659
+ export class RadiationAtAPointCalculationResponse extends CalculationResponseBase {
1660
+ radiation: number;
1661
+
1662
+ /**
1663
+ * RadiationAtAPoint calculation response class.
1664
+ *
1665
+ * @param {number} radiation - Radiation at a point.
1666
+ */
1667
+ constructor(
1668
+ radiation: number,
1669
+ resultCode: Enums.ResultCode,
1670
+ messages: string[],
1671
+ calculationElapsedTime: number,
1672
+ operationId: string
1673
+ ) {
1674
+ super();
1675
+ this.radiation = radiation;
1676
+ this.resultCode = resultCode;
1677
+ this.messages = messages;
1678
+ this.calculationElapsedTime = calculationElapsedTime;
1679
+ this.operationId = operationId;
1680
+ }
1681
+
1682
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
1683
+ if (data.radiation !== undefined && typeof data.radiation === "number") {
1684
+ this.radiation = data.radiation as number;
1685
+ }
1686
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
1687
+ this.resultCode = data.resultCode as Enums.ResultCode;
1688
+ }
1689
+ this.messages = this.messages ?? [];
1690
+ if (data.messages && Array.isArray(data.messages)) {
1691
+ this.messages.push(...data.messages);
1692
+ }
1693
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
1694
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
1695
+ }
1696
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
1697
+ this.operationId = data.operationId as string;
1698
+ }
1699
+ }
1700
+ }
1701
+
1702
+ export interface RadiationAtAPointCalculationResponseSchemaData {
1703
+ radiation: number;
1704
+ resultCode: Enums.ResultCode;
1705
+ messages: string[];
1706
+ calculationElapsedTime: number;
1707
+ operationId: string;
1708
+ }
1709
+
1710
+ export class RadiationAtAPointCalculationResponseSchema {
1711
+ schema: Joi.ObjectSchema;
1712
+ propertyTypes: Record<string, string>;
1713
+
1714
+ /**
1715
+ * Schema for the RadiationAtAPoint calculation response.
1716
+ */
1717
+ constructor() {
1718
+ this.schema = Joi.object({
1719
+ radiation: Joi.number().unsafe(),
1720
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
1721
+ messages: Joi.array().items(Joi.string()),
1722
+ calculationElapsedTime: Joi.number().unsafe(),
1723
+ operationId: Joi.string().uuid().allow(null),
1724
+ }).unknown(true);
1725
+
1726
+ this.propertyTypes = {
1727
+ radiation: "number",
1728
+ };
1729
+ }
1730
+
1731
+ validate(data: RadiationAtAPointCalculationResponseSchemaData): RadiationAtAPointCalculationResponse {
1732
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
1733
+ if (error) {
1734
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
1735
+ }
1736
+ return this.makeCalculationResponse(value);
1737
+ }
1738
+
1739
+ makeCalculationResponse(data: RadiationAtAPointCalculationResponseSchemaData): RadiationAtAPointCalculationResponse {
1740
+ return new RadiationAtAPointCalculationResponse(
1741
+ data.radiation,
1742
+ data.resultCode,
1743
+ data.messages,
1744
+ data.calculationElapsedTime,
1745
+ data.operationId
1746
+ );
1747
+ }
1748
+ }
1749
+
1750
+ export interface RadiationAtAPointForPoolFiresCalculationRequestSchemaData {
1751
+ poolFireFlameResult: Entities.PoolFireFlameResult;
1752
+ flameRecords: Entities.FlameRecord[];
1753
+ flameRecordCount: number;
1754
+ weather: Entities.Weather;
1755
+ flammableParameters: Entities.FlammableParameters;
1756
+ flammableOutputConfig: Entities.FlammableOutputConfig;
1757
+ }
1758
+
1759
+ class RadiationAtAPointForPoolFiresCalculationRequest extends CalculationRequestBase {
1760
+ poolFireFlameResult: Entities.PoolFireFlameResult;
1761
+ flameRecords: Entities.FlameRecord[];
1762
+ flameRecordCount: number;
1763
+ weather: Entities.Weather;
1764
+ flammableParameters: Entities.FlammableParameters;
1765
+ flammableOutputConfig: Entities.FlammableOutputConfig;
1766
+
1767
+ /**
1768
+ * RadiationAtAPointForPoolFires calculation request class.
1769
+ *
1770
+ * @param {Entities.PoolFireFlameResult} poolFireFlameResult - Scalar flame results.
1771
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
1772
+ * @param {number} flameRecordCount - Number of Flame Records.
1773
+ * @param {Entities.Weather} weather - A Weather entity.
1774
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
1775
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity, for setting the point coordinates.
1776
+ */
1777
+ constructor(
1778
+ poolFireFlameResult: Entities.PoolFireFlameResult,
1779
+ flameRecords: Entities.FlameRecord[],
1780
+ flameRecordCount: number,
1781
+ weather: Entities.Weather,
1782
+ flammableParameters: Entities.FlammableParameters,
1783
+ flammableOutputConfig: Entities.FlammableOutputConfig
1784
+ ) {
1785
+ super();
1786
+ this.poolFireFlameResult = poolFireFlameResult;
1787
+ this.flameRecords = flameRecords;
1788
+ this.flameRecordCount = flameRecordCount;
1789
+ this.weather = weather;
1790
+ this.flammableParameters = flammableParameters;
1791
+ this.flammableOutputConfig = flammableOutputConfig;
1792
+ }
1793
+ }
1794
+
1795
+ export class RadiationAtAPointForPoolFiresCalculationRequestSchema {
1796
+ schema: Joi.ObjectSchema;
1797
+ propertyTypes: Record<string, string>;
1798
+
1799
+ /**
1800
+ * Schema for the RadiationAtAPointForPoolFires calculation request.
1801
+ */
1802
+ constructor() {
1803
+ this.schema = Joi.object({
1804
+ poolFireFlameResult: new EntitySchemas.PoolFireFlameResultSchema().schema,
1805
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
1806
+ flameRecordCount: Joi.number().integer(),
1807
+ weather: new EntitySchemas.WeatherSchema().schema,
1808
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
1809
+ flammableOutputConfig: new EntitySchemas.FlammableOutputConfigSchema().schema,
1810
+ }).unknown(true);
1811
+
1812
+ this.propertyTypes = {
1813
+ poolFireFlameResult: "Entities.PoolFireFlameResult",
1814
+ flameRecords: "Entities.FlameRecord[]",
1815
+ flameRecordCount: "number",
1816
+ weather: "Entities.Weather",
1817
+ flammableParameters: "Entities.FlammableParameters",
1818
+ flammableOutputConfig: "Entities.FlammableOutputConfig",
1819
+ };
1820
+ }
1821
+
1822
+ validate(data: RadiationAtAPointForPoolFiresCalculationRequestSchemaData): RadiationAtAPointForPoolFiresCalculationRequest {
1823
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
1824
+ if (error) {
1825
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
1826
+ }
1827
+ return this.makeCalculationRequest(value);
1828
+ }
1829
+
1830
+ makeCalculationRequest(data: RadiationAtAPointForPoolFiresCalculationRequestSchemaData): RadiationAtAPointForPoolFiresCalculationRequest {
1831
+ return new RadiationAtAPointForPoolFiresCalculationRequest(
1832
+ data.poolFireFlameResult,
1833
+ data.flameRecords,
1834
+ data.flameRecordCount,
1835
+ data.weather,
1836
+ data.flammableParameters,
1837
+ data.flammableOutputConfig
1838
+ );
1839
+ }
1840
+ }
1841
+
1842
+ export class RadiationAtAPointForPoolFiresCalculation extends CalculationBase {
1843
+ poolFireFlameResult: Entities.PoolFireFlameResult;
1844
+ flameRecords: Entities.FlameRecord[];
1845
+ flameRecordCount: number;
1846
+ weather: Entities.Weather;
1847
+ flammableParameters: Entities.FlammableParameters;
1848
+ flammableOutputConfig: Entities.FlammableOutputConfig;
1849
+ radiation?: number;
1850
+
1851
+ /**
1852
+ * Calculates the radiation at coordinates x, y, z from a pool fire model.
1853
+ *
1854
+ * @param {Entities.PoolFireFlameResult} poolFireFlameResult - Scalar flame results.
1855
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
1856
+ * @param {number} flameRecordCount - Number of Flame Records.
1857
+ * @param {Entities.Weather} weather - A Weather entity.
1858
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
1859
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity, for setting the point coordinates.
1860
+ */
1861
+ constructor(
1862
+ poolFireFlameResult: Entities.PoolFireFlameResult,
1863
+ flameRecords: Entities.FlameRecord[],
1864
+ flameRecordCount: number,
1865
+ weather: Entities.Weather,
1866
+ flammableParameters: Entities.FlammableParameters,
1867
+ flammableOutputConfig: Entities.FlammableOutputConfig
1868
+ ) {
1869
+ super();
1870
+ this.poolFireFlameResult = poolFireFlameResult;
1871
+ this.flameRecords = flameRecords;
1872
+ this.flameRecordCount = flameRecordCount;
1873
+ this.weather = weather;
1874
+ this.flammableParameters = flammableParameters;
1875
+ this.flammableOutputConfig = flammableOutputConfig;
1876
+ }
1877
+
1878
+ async run() {
1879
+ try {
1880
+ const request = new RadiationAtAPointForPoolFiresCalculationRequest(
1881
+ this.poolFireFlameResult,
1882
+ this.flameRecords,
1883
+ this.flameRecordCount,
1884
+ this.weather,
1885
+ this.flammableParameters,
1886
+ this.flammableOutputConfig
1887
+ );
1888
+
1889
+ const schema = new RadiationAtAPointForPoolFiresCalculationRequestSchema();
1890
+ const validatedRequest = schema.validate(request);
1891
+
1892
+ const requestJson = JSON.stringify(validatedRequest);
1893
+ const url = `${getAnalyticsApiTarget()}calculateradiationatapointforpoolfires?clientId=${getClientAliasId()}`;
1894
+
1895
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
1896
+
1897
+ const response = await this.postRequest(url, requestJson);
1898
+
1899
+ if (response.status >= 200 && response.status < 300) {
1900
+ const schema = new RadiationAtAPointForPoolFiresCalculationResponseSchema();
1901
+ const validatedResponse = schema.validate(response.data);
1902
+
1903
+ this.resultCode = validatedResponse.resultCode;
1904
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
1905
+ this.radiation = validatedResponse.radiation;
1906
+ this.resultCode = validatedResponse.resultCode;
1907
+ this.messages = validatedResponse.messages ?? [];
1908
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
1909
+ this.operationId = validatedResponse.operationId;
1910
+ } else {
1911
+ this.messages.push(...(validatedResponse.messages ?? []));
1912
+ }
1913
+ } else {
1914
+ this.handleFailedResponse(response);
1915
+ }
1916
+ } catch (error) {
1917
+ if (error instanceof Error) {
1918
+ this.messages.push(`Error: ${error.message}`);
1919
+ } else {
1920
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
1921
+ }
1922
+ console.error(error);
1923
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
1924
+ }
1925
+
1926
+ return this.resultCode;
1927
+ }
1928
+
1929
+ toString() {
1930
+ const parts = ["* RadiationAtAPointForPoolFires"];
1931
+
1932
+ parts.push(`radiation: ${String(this.radiation)}`);
1933
+ parts.push(`resultCode: ${String(this.resultCode)}`);
1934
+ parts.push("*** messages:");
1935
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
1936
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
1937
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
1938
+
1939
+ return parts.join("\n");
1940
+ }
1941
+ }
1942
+
1943
+ export class RadiationAtAPointForPoolFiresCalculationResponse extends CalculationResponseBase {
1944
+ radiation: number;
1945
+
1946
+ /**
1947
+ * RadiationAtAPointForPoolFires calculation response class.
1948
+ *
1949
+ * @param {number} radiation - Radiation at a point.
1950
+ */
1951
+ constructor(
1952
+ radiation: number,
1953
+ resultCode: Enums.ResultCode,
1954
+ messages: string[],
1955
+ calculationElapsedTime: number,
1956
+ operationId: string
1957
+ ) {
1958
+ super();
1959
+ this.radiation = radiation;
1960
+ this.resultCode = resultCode;
1961
+ this.messages = messages;
1962
+ this.calculationElapsedTime = calculationElapsedTime;
1963
+ this.operationId = operationId;
1964
+ }
1965
+
1966
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
1967
+ if (data.radiation !== undefined && typeof data.radiation === "number") {
1968
+ this.radiation = data.radiation as number;
1969
+ }
1970
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
1971
+ this.resultCode = data.resultCode as Enums.ResultCode;
1972
+ }
1973
+ this.messages = this.messages ?? [];
1974
+ if (data.messages && Array.isArray(data.messages)) {
1975
+ this.messages.push(...data.messages);
1976
+ }
1977
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
1978
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
1979
+ }
1980
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
1981
+ this.operationId = data.operationId as string;
1982
+ }
1983
+ }
1984
+ }
1985
+
1986
+ export interface RadiationAtAPointForPoolFiresCalculationResponseSchemaData {
1987
+ radiation: number;
1988
+ resultCode: Enums.ResultCode;
1989
+ messages: string[];
1990
+ calculationElapsedTime: number;
1991
+ operationId: string;
1992
+ }
1993
+
1994
+ export class RadiationAtAPointForPoolFiresCalculationResponseSchema {
1995
+ schema: Joi.ObjectSchema;
1996
+ propertyTypes: Record<string, string>;
1997
+
1998
+ /**
1999
+ * Schema for the RadiationAtAPointForPoolFires calculation response.
2000
+ */
2001
+ constructor() {
2002
+ this.schema = Joi.object({
2003
+ radiation: Joi.number().unsafe(),
2004
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
2005
+ messages: Joi.array().items(Joi.string()),
2006
+ calculationElapsedTime: Joi.number().unsafe(),
2007
+ operationId: Joi.string().uuid().allow(null),
2008
+ }).unknown(true);
2009
+
2010
+ this.propertyTypes = {
2011
+ radiation: "number",
2012
+ };
2013
+ }
2014
+
2015
+ validate(data: RadiationAtAPointForPoolFiresCalculationResponseSchemaData): RadiationAtAPointForPoolFiresCalculationResponse {
2016
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
2017
+ if (error) {
2018
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
2019
+ }
2020
+ return this.makeCalculationResponse(value);
2021
+ }
2022
+
2023
+ makeCalculationResponse(data: RadiationAtAPointForPoolFiresCalculationResponseSchemaData): RadiationAtAPointForPoolFiresCalculationResponse {
2024
+ return new RadiationAtAPointForPoolFiresCalculationResponse(
2025
+ data.radiation,
2026
+ data.resultCode,
2027
+ data.messages,
2028
+ data.calculationElapsedTime,
2029
+ data.operationId
2030
+ );
2031
+ }
2032
+ }
2033
+
2034
+ export interface RadiationAtPointsCalculationRequestSchemaData {
2035
+ flameResult: Entities.FlameResult;
2036
+ flameRecords: Entities.FlameRecord[];
2037
+ flameRecordCount: number;
2038
+ weather: Entities.Weather;
2039
+ flammableParameters: Entities.FlammableParameters;
2040
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
2041
+ flammableOutputConfigCount: number;
2042
+ }
2043
+
2044
+ class RadiationAtPointsCalculationRequest extends CalculationRequestBase {
2045
+ flameResult: Entities.FlameResult;
2046
+ flameRecords: Entities.FlameRecord[];
2047
+ flameRecordCount: number;
2048
+ weather: Entities.Weather;
2049
+ flammableParameters: Entities.FlammableParameters;
2050
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
2051
+ flammableOutputConfigCount: number;
2052
+
2053
+ /**
2054
+ * RadiationAtPoints calculation request class.
2055
+ *
2056
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
2057
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
2058
+ * @param {number} flameRecordCount - Number of Flame Records.
2059
+ * @param {Entities.Weather} weather - A Weather entity.
2060
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
2061
+ * @param {Entities.FlammableOutputConfig[]} flammableOutputConfigs - A Flammable Output Config entity, for setting the point coordinates.
2062
+ * @param {number} flammableOutputConfigCount - Number of points.
2063
+ */
2064
+ constructor(
2065
+ flameResult: Entities.FlameResult,
2066
+ flameRecords: Entities.FlameRecord[],
2067
+ flameRecordCount: number,
2068
+ weather: Entities.Weather,
2069
+ flammableParameters: Entities.FlammableParameters,
2070
+ flammableOutputConfigs: Entities.FlammableOutputConfig[],
2071
+ flammableOutputConfigCount: number
2072
+ ) {
2073
+ super();
2074
+ this.flameResult = flameResult;
2075
+ this.flameRecords = flameRecords;
2076
+ this.flameRecordCount = flameRecordCount;
2077
+ this.weather = weather;
2078
+ this.flammableParameters = flammableParameters;
2079
+ this.flammableOutputConfigs = flammableOutputConfigs;
2080
+ this.flammableOutputConfigCount = flammableOutputConfigCount;
2081
+ }
2082
+ }
2083
+
2084
+ export class RadiationAtPointsCalculationRequestSchema {
2085
+ schema: Joi.ObjectSchema;
2086
+ propertyTypes: Record<string, string>;
2087
+
2088
+ /**
2089
+ * Schema for the RadiationAtPoints calculation request.
2090
+ */
2091
+ constructor() {
2092
+ this.schema = Joi.object({
2093
+ flameResult: new EntitySchemas.FlameResultSchema().schema,
2094
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
2095
+ flameRecordCount: Joi.number().integer(),
2096
+ weather: new EntitySchemas.WeatherSchema().schema,
2097
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
2098
+ flammableOutputConfigs: Joi.array().items(new EntitySchemas.FlammableOutputConfigSchema().schema).allow(null),
2099
+ flammableOutputConfigCount: Joi.number().integer(),
2100
+ }).unknown(true);
2101
+
2102
+ this.propertyTypes = {
2103
+ flameResult: "Entities.FlameResult",
2104
+ flameRecords: "Entities.FlameRecord[]",
2105
+ flameRecordCount: "number",
2106
+ weather: "Entities.Weather",
2107
+ flammableParameters: "Entities.FlammableParameters",
2108
+ flammableOutputConfigs: "Entities.FlammableOutputConfig[]",
2109
+ flammableOutputConfigCount: "number",
2110
+ };
2111
+ }
2112
+
2113
+ validate(data: RadiationAtPointsCalculationRequestSchemaData): RadiationAtPointsCalculationRequest {
2114
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
2115
+ if (error) {
2116
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
2117
+ }
2118
+ return this.makeCalculationRequest(value);
2119
+ }
2120
+
2121
+ makeCalculationRequest(data: RadiationAtPointsCalculationRequestSchemaData): RadiationAtPointsCalculationRequest {
2122
+ return new RadiationAtPointsCalculationRequest(
2123
+ data.flameResult,
2124
+ data.flameRecords,
2125
+ data.flameRecordCount,
2126
+ data.weather,
2127
+ data.flammableParameters,
2128
+ data.flammableOutputConfigs,
2129
+ data.flammableOutputConfigCount
2130
+ );
2131
+ }
2132
+ }
2133
+
2134
+ export class RadiationAtPointsCalculation extends CalculationBase {
2135
+ flameResult: Entities.FlameResult;
2136
+ flameRecords: Entities.FlameRecord[];
2137
+ flameRecordCount: number;
2138
+ weather: Entities.Weather;
2139
+ flammableParameters: Entities.FlammableParameters;
2140
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
2141
+ flammableOutputConfigCount: number;
2142
+ radiation?: number[];
2143
+
2144
+ /**
2145
+ * Calculates the radiation at an array of coordinates x, y, z from a flammable model.
2146
+ *
2147
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
2148
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
2149
+ * @param {number} flameRecordCount - Number of Flame Records.
2150
+ * @param {Entities.Weather} weather - A Weather entity.
2151
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
2152
+ * @param {Entities.FlammableOutputConfig[]} flammableOutputConfigs - A Flammable Output Config entity, for setting the point coordinates.
2153
+ * @param {number} flammableOutputConfigCount - Number of points.
2154
+ */
2155
+ constructor(
2156
+ flameResult: Entities.FlameResult,
2157
+ flameRecords: Entities.FlameRecord[],
2158
+ flameRecordCount: number,
2159
+ weather: Entities.Weather,
2160
+ flammableParameters: Entities.FlammableParameters,
2161
+ flammableOutputConfigs: Entities.FlammableOutputConfig[],
2162
+ flammableOutputConfigCount: number
2163
+ ) {
2164
+ super();
2165
+ this.flameResult = flameResult;
2166
+ this.flameRecords = flameRecords;
2167
+ this.flameRecordCount = flameRecordCount;
2168
+ this.weather = weather;
2169
+ this.flammableParameters = flammableParameters;
2170
+ this.flammableOutputConfigs = flammableOutputConfigs;
2171
+ this.flammableOutputConfigCount = flammableOutputConfigCount;
2172
+ }
2173
+
2174
+ async run() {
2175
+ try {
2176
+ const request = new RadiationAtPointsCalculationRequest(
2177
+ this.flameResult,
2178
+ this.flameRecords,
2179
+ this.flameRecordCount,
2180
+ this.weather,
2181
+ this.flammableParameters,
2182
+ this.flammableOutputConfigs,
2183
+ this.flammableOutputConfigCount
2184
+ );
2185
+
2186
+ const schema = new RadiationAtPointsCalculationRequestSchema();
2187
+ const validatedRequest = schema.validate(request);
2188
+
2189
+ const requestJson = JSON.stringify(validatedRequest);
2190
+ const url = `${getAnalyticsApiTarget()}calculateradiationatpoints?clientId=${getClientAliasId()}`;
2191
+
2192
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
2193
+
2194
+ const response = await this.postRequest(url, requestJson);
2195
+
2196
+ if (response.status >= 200 && response.status < 300) {
2197
+ const schema = new RadiationAtPointsCalculationResponseSchema();
2198
+ const validatedResponse = schema.validate(response.data);
2199
+
2200
+ this.resultCode = validatedResponse.resultCode;
2201
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
2202
+ this.radiation = validatedResponse.radiation;
2203
+ this.resultCode = validatedResponse.resultCode;
2204
+ this.messages = validatedResponse.messages ?? [];
2205
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
2206
+ this.operationId = validatedResponse.operationId;
2207
+ } else {
2208
+ this.messages.push(...(validatedResponse.messages ?? []));
2209
+ }
2210
+ } else {
2211
+ this.handleFailedResponse(response);
2212
+ }
2213
+ } catch (error) {
2214
+ if (error instanceof Error) {
2215
+ this.messages.push(`Error: ${error.message}`);
2216
+ } else {
2217
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
2218
+ }
2219
+ console.error(error);
2220
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
2221
+ }
2222
+
2223
+ return this.resultCode;
2224
+ }
2225
+
2226
+ toString() {
2227
+ const parts = ["* RadiationAtPoints"];
2228
+
2229
+ parts.push("*** radiation:");
2230
+ parts.push(
2231
+ this.radiation && this.radiation.length > 0
2232
+ ? this.radiation.map((point) => `radiationElement: ${point}`).join("\n")
2233
+ : "radiation does not contain any elements"
2234
+ );
2235
+ parts.push(`resultCode: ${String(this.resultCode)}`);
2236
+ parts.push("*** messages:");
2237
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
2238
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
2239
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
2240
+
2241
+ return parts.join("\n");
2242
+ }
2243
+ }
2244
+
2245
+ export class RadiationAtPointsCalculationResponse extends CalculationResponseBase {
2246
+ radiation: number[];
2247
+
2248
+ /**
2249
+ * RadiationAtPoints calculation response class.
2250
+ *
2251
+ * @param {number[]} radiation - An array of radiation at a point.
2252
+ */
2253
+ constructor(
2254
+ radiation: number[],
2255
+ resultCode: Enums.ResultCode,
2256
+ messages: string[],
2257
+ calculationElapsedTime: number,
2258
+ operationId: string
2259
+ ) {
2260
+ super();
2261
+ this.radiation = radiation;
2262
+ this.resultCode = resultCode;
2263
+ this.messages = messages;
2264
+ this.calculationElapsedTime = calculationElapsedTime;
2265
+ this.operationId = operationId;
2266
+ }
2267
+
2268
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
2269
+ if (data.radiation && Array.isArray(data.radiation)) {
2270
+ this.radiation = data.radiation.map((item) => parseFloat(item));
2271
+ }
2272
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
2273
+ this.resultCode = data.resultCode as Enums.ResultCode;
2274
+ }
2275
+ this.messages = this.messages ?? [];
2276
+ if (data.messages && Array.isArray(data.messages)) {
2277
+ this.messages.push(...data.messages);
2278
+ }
2279
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
2280
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
2281
+ }
2282
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
2283
+ this.operationId = data.operationId as string;
2284
+ }
2285
+ }
2286
+ }
2287
+
2288
+ export interface RadiationAtPointsCalculationResponseSchemaData {
2289
+ radiation: number[];
2290
+ resultCode: Enums.ResultCode;
2291
+ messages: string[];
2292
+ calculationElapsedTime: number;
2293
+ operationId: string;
2294
+ }
2295
+
2296
+ export class RadiationAtPointsCalculationResponseSchema {
2297
+ schema: Joi.ObjectSchema;
2298
+ propertyTypes: Record<string, string>;
2299
+
2300
+ /**
2301
+ * Schema for the RadiationAtPoints calculation response.
2302
+ */
2303
+ constructor() {
2304
+ this.schema = Joi.object({
2305
+ radiation: Joi.array().items(Joi.number().unsafe()).allow(null),
2306
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
2307
+ messages: Joi.array().items(Joi.string()),
2308
+ calculationElapsedTime: Joi.number().unsafe(),
2309
+ operationId: Joi.string().uuid().allow(null),
2310
+ }).unknown(true);
2311
+
2312
+ this.propertyTypes = {
2313
+ radiation: "number[]",
2314
+ };
2315
+ }
2316
+
2317
+ validate(data: RadiationAtPointsCalculationResponseSchemaData): RadiationAtPointsCalculationResponse {
2318
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
2319
+ if (error) {
2320
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
2321
+ }
2322
+ return this.makeCalculationResponse(value);
2323
+ }
2324
+
2325
+ makeCalculationResponse(data: RadiationAtPointsCalculationResponseSchemaData): RadiationAtPointsCalculationResponse {
2326
+ return new RadiationAtPointsCalculationResponse(
2327
+ data.radiation,
2328
+ data.resultCode,
2329
+ data.messages,
2330
+ data.calculationElapsedTime,
2331
+ data.operationId
2332
+ );
2333
+ }
2334
+ }
2335
+
2336
+ export interface RadiationAtPointsForPoolFiresCalculationRequestSchemaData {
2337
+ poolFireFlameResult: Entities.PoolFireFlameResult;
2338
+ flameRecords: Entities.FlameRecord[];
2339
+ flameRecordCount: number;
2340
+ weather: Entities.Weather;
2341
+ flammableParameters: Entities.FlammableParameters;
2342
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
2343
+ flammableOutputConfigCount: number;
2344
+ }
2345
+
2346
+ class RadiationAtPointsForPoolFiresCalculationRequest extends CalculationRequestBase {
2347
+ poolFireFlameResult: Entities.PoolFireFlameResult;
2348
+ flameRecords: Entities.FlameRecord[];
2349
+ flameRecordCount: number;
2350
+ weather: Entities.Weather;
2351
+ flammableParameters: Entities.FlammableParameters;
2352
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
2353
+ flammableOutputConfigCount: number;
2354
+
2355
+ /**
2356
+ * RadiationAtPointsForPoolFires calculation request class.
2357
+ *
2358
+ * @param {Entities.PoolFireFlameResult} poolFireFlameResult - Scalar flame results.
2359
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
2360
+ * @param {number} flameRecordCount - Number of Flame Records.
2361
+ * @param {Entities.Weather} weather - A Weather entity.
2362
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
2363
+ * @param {Entities.FlammableOutputConfig[]} flammableOutputConfigs - A Flammable Output Config entity, for setting the point coordinates.
2364
+ * @param {number} flammableOutputConfigCount - Number of points.
2365
+ */
2366
+ constructor(
2367
+ poolFireFlameResult: Entities.PoolFireFlameResult,
2368
+ flameRecords: Entities.FlameRecord[],
2369
+ flameRecordCount: number,
2370
+ weather: Entities.Weather,
2371
+ flammableParameters: Entities.FlammableParameters,
2372
+ flammableOutputConfigs: Entities.FlammableOutputConfig[],
2373
+ flammableOutputConfigCount: number
2374
+ ) {
2375
+ super();
2376
+ this.poolFireFlameResult = poolFireFlameResult;
2377
+ this.flameRecords = flameRecords;
2378
+ this.flameRecordCount = flameRecordCount;
2379
+ this.weather = weather;
2380
+ this.flammableParameters = flammableParameters;
2381
+ this.flammableOutputConfigs = flammableOutputConfigs;
2382
+ this.flammableOutputConfigCount = flammableOutputConfigCount;
2383
+ }
2384
+ }
2385
+
2386
+ export class RadiationAtPointsForPoolFiresCalculationRequestSchema {
2387
+ schema: Joi.ObjectSchema;
2388
+ propertyTypes: Record<string, string>;
2389
+
2390
+ /**
2391
+ * Schema for the RadiationAtPointsForPoolFires calculation request.
2392
+ */
2393
+ constructor() {
2394
+ this.schema = Joi.object({
2395
+ poolFireFlameResult: new EntitySchemas.PoolFireFlameResultSchema().schema,
2396
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
2397
+ flameRecordCount: Joi.number().integer(),
2398
+ weather: new EntitySchemas.WeatherSchema().schema,
2399
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
2400
+ flammableOutputConfigs: Joi.array().items(new EntitySchemas.FlammableOutputConfigSchema().schema).allow(null),
2401
+ flammableOutputConfigCount: Joi.number().integer(),
2402
+ }).unknown(true);
2403
+
2404
+ this.propertyTypes = {
2405
+ poolFireFlameResult: "Entities.PoolFireFlameResult",
2406
+ flameRecords: "Entities.FlameRecord[]",
2407
+ flameRecordCount: "number",
2408
+ weather: "Entities.Weather",
2409
+ flammableParameters: "Entities.FlammableParameters",
2410
+ flammableOutputConfigs: "Entities.FlammableOutputConfig[]",
2411
+ flammableOutputConfigCount: "number",
2412
+ };
2413
+ }
2414
+
2415
+ validate(data: RadiationAtPointsForPoolFiresCalculationRequestSchemaData): RadiationAtPointsForPoolFiresCalculationRequest {
2416
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
2417
+ if (error) {
2418
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
2419
+ }
2420
+ return this.makeCalculationRequest(value);
2421
+ }
2422
+
2423
+ makeCalculationRequest(data: RadiationAtPointsForPoolFiresCalculationRequestSchemaData): RadiationAtPointsForPoolFiresCalculationRequest {
2424
+ return new RadiationAtPointsForPoolFiresCalculationRequest(
2425
+ data.poolFireFlameResult,
2426
+ data.flameRecords,
2427
+ data.flameRecordCount,
2428
+ data.weather,
2429
+ data.flammableParameters,
2430
+ data.flammableOutputConfigs,
2431
+ data.flammableOutputConfigCount
2432
+ );
2433
+ }
2434
+ }
2435
+
2436
+ export class RadiationAtPointsForPoolFiresCalculation extends CalculationBase {
2437
+ poolFireFlameResult: Entities.PoolFireFlameResult;
2438
+ flameRecords: Entities.FlameRecord[];
2439
+ flameRecordCount: number;
2440
+ weather: Entities.Weather;
2441
+ flammableParameters: Entities.FlammableParameters;
2442
+ flammableOutputConfigs: Entities.FlammableOutputConfig[];
2443
+ flammableOutputConfigCount: number;
2444
+ radiation?: number[];
2445
+
2446
+ /**
2447
+ * Calculates the radiation at an array of coordinates x, y, z from a pool fire model.
2448
+ *
2449
+ * @param {Entities.PoolFireFlameResult} poolFireFlameResult - Scalar flame results.
2450
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
2451
+ * @param {number} flameRecordCount - Number of Flame Records.
2452
+ * @param {Entities.Weather} weather - A Weather entity.
2453
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
2454
+ * @param {Entities.FlammableOutputConfig[]} flammableOutputConfigs - A Flammable Output Config entity, for setting the point coordinates.
2455
+ * @param {number} flammableOutputConfigCount - Number of points.
2456
+ */
2457
+ constructor(
2458
+ poolFireFlameResult: Entities.PoolFireFlameResult,
2459
+ flameRecords: Entities.FlameRecord[],
2460
+ flameRecordCount: number,
2461
+ weather: Entities.Weather,
2462
+ flammableParameters: Entities.FlammableParameters,
2463
+ flammableOutputConfigs: Entities.FlammableOutputConfig[],
2464
+ flammableOutputConfigCount: number
2465
+ ) {
2466
+ super();
2467
+ this.poolFireFlameResult = poolFireFlameResult;
2468
+ this.flameRecords = flameRecords;
2469
+ this.flameRecordCount = flameRecordCount;
2470
+ this.weather = weather;
2471
+ this.flammableParameters = flammableParameters;
2472
+ this.flammableOutputConfigs = flammableOutputConfigs;
2473
+ this.flammableOutputConfigCount = flammableOutputConfigCount;
2474
+ }
2475
+
2476
+ async run() {
2477
+ try {
2478
+ const request = new RadiationAtPointsForPoolFiresCalculationRequest(
2479
+ this.poolFireFlameResult,
2480
+ this.flameRecords,
2481
+ this.flameRecordCount,
2482
+ this.weather,
2483
+ this.flammableParameters,
2484
+ this.flammableOutputConfigs,
2485
+ this.flammableOutputConfigCount
2486
+ );
2487
+
2488
+ const schema = new RadiationAtPointsForPoolFiresCalculationRequestSchema();
2489
+ const validatedRequest = schema.validate(request);
2490
+
2491
+ const requestJson = JSON.stringify(validatedRequest);
2492
+ const url = `${getAnalyticsApiTarget()}calculateradiationatpointsforpoolfires?clientId=${getClientAliasId()}`;
2493
+
2494
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
2495
+
2496
+ const response = await this.postRequest(url, requestJson);
2497
+
2498
+ if (response.status >= 200 && response.status < 300) {
2499
+ const schema = new RadiationAtPointsForPoolFiresCalculationResponseSchema();
2500
+ const validatedResponse = schema.validate(response.data);
2501
+
2502
+ this.resultCode = validatedResponse.resultCode;
2503
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
2504
+ this.radiation = validatedResponse.radiation;
2505
+ this.resultCode = validatedResponse.resultCode;
2506
+ this.messages = validatedResponse.messages ?? [];
2507
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
2508
+ this.operationId = validatedResponse.operationId;
2509
+ } else {
2510
+ this.messages.push(...(validatedResponse.messages ?? []));
2511
+ }
2512
+ } else {
2513
+ this.handleFailedResponse(response);
2514
+ }
2515
+ } catch (error) {
2516
+ if (error instanceof Error) {
2517
+ this.messages.push(`Error: ${error.message}`);
2518
+ } else {
2519
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
2520
+ }
2521
+ console.error(error);
2522
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
2523
+ }
2524
+
2525
+ return this.resultCode;
2526
+ }
2527
+
2528
+ toString() {
2529
+ const parts = ["* RadiationAtPointsForPoolFires"];
2530
+
2531
+ parts.push("*** radiation:");
2532
+ parts.push(
2533
+ this.radiation && this.radiation.length > 0
2534
+ ? this.radiation.map((point) => `radiationElement: ${point}`).join("\n")
2535
+ : "radiation does not contain any elements"
2536
+ );
2537
+ parts.push(`resultCode: ${String(this.resultCode)}`);
2538
+ parts.push("*** messages:");
2539
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
2540
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
2541
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
2542
+
2543
+ return parts.join("\n");
2544
+ }
2545
+ }
2546
+
2547
+ export class RadiationAtPointsForPoolFiresCalculationResponse extends CalculationResponseBase {
2548
+ radiation: number[];
2549
+
2550
+ /**
2551
+ * RadiationAtPointsForPoolFires calculation response class.
2552
+ *
2553
+ * @param {number[]} radiation - An array of radiation at a point.
2554
+ */
2555
+ constructor(
2556
+ radiation: number[],
2557
+ resultCode: Enums.ResultCode,
2558
+ messages: string[],
2559
+ calculationElapsedTime: number,
2560
+ operationId: string
2561
+ ) {
2562
+ super();
2563
+ this.radiation = radiation;
2564
+ this.resultCode = resultCode;
2565
+ this.messages = messages;
2566
+ this.calculationElapsedTime = calculationElapsedTime;
2567
+ this.operationId = operationId;
2568
+ }
2569
+
2570
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
2571
+ if (data.radiation && Array.isArray(data.radiation)) {
2572
+ this.radiation = data.radiation.map((item) => parseFloat(item));
2573
+ }
2574
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
2575
+ this.resultCode = data.resultCode as Enums.ResultCode;
2576
+ }
2577
+ this.messages = this.messages ?? [];
2578
+ if (data.messages && Array.isArray(data.messages)) {
2579
+ this.messages.push(...data.messages);
2580
+ }
2581
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
2582
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
2583
+ }
2584
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
2585
+ this.operationId = data.operationId as string;
2586
+ }
2587
+ }
2588
+ }
2589
+
2590
+ export interface RadiationAtPointsForPoolFiresCalculationResponseSchemaData {
2591
+ radiation: number[];
2592
+ resultCode: Enums.ResultCode;
2593
+ messages: string[];
2594
+ calculationElapsedTime: number;
2595
+ operationId: string;
2596
+ }
2597
+
2598
+ export class RadiationAtPointsForPoolFiresCalculationResponseSchema {
2599
+ schema: Joi.ObjectSchema;
2600
+ propertyTypes: Record<string, string>;
2601
+
2602
+ /**
2603
+ * Schema for the RadiationAtPointsForPoolFires calculation response.
2604
+ */
2605
+ constructor() {
2606
+ this.schema = Joi.object({
2607
+ radiation: Joi.array().items(Joi.number().unsafe()).allow(null),
2608
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
2609
+ messages: Joi.array().items(Joi.string()),
2610
+ calculationElapsedTime: Joi.number().unsafe(),
2611
+ operationId: Joi.string().uuid().allow(null),
2612
+ }).unknown(true);
2613
+
2614
+ this.propertyTypes = {
2615
+ radiation: "number[]",
2616
+ };
2617
+ }
2618
+
2619
+ validate(data: RadiationAtPointsForPoolFiresCalculationResponseSchemaData): RadiationAtPointsForPoolFiresCalculationResponse {
2620
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
2621
+ if (error) {
2622
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
2623
+ }
2624
+ return this.makeCalculationResponse(value);
2625
+ }
2626
+
2627
+ makeCalculationResponse(data: RadiationAtPointsForPoolFiresCalculationResponseSchemaData): RadiationAtPointsForPoolFiresCalculationResponse {
2628
+ return new RadiationAtPointsForPoolFiresCalculationResponse(
2629
+ data.radiation,
2630
+ data.resultCode,
2631
+ data.messages,
2632
+ data.calculationElapsedTime,
2633
+ data.operationId
2634
+ );
2635
+ }
2636
+ }
2637
+
2638
+ export interface RadiationContourCalculationRequestSchemaData {
2639
+ flameResult: Entities.FlameResult;
2640
+ flameRecords: Entities.FlameRecord[];
2641
+ flameRecordCount: number;
2642
+ weather: Entities.Weather;
2643
+ flammableParameters: Entities.FlammableParameters;
2644
+ flammableOutputConfig: Entities.FlammableOutputConfig;
2645
+ }
2646
+
2647
+ class RadiationContourCalculationRequest extends CalculationRequestBase {
2648
+ flameResult: Entities.FlameResult;
2649
+ flameRecords: Entities.FlameRecord[];
2650
+ flameRecordCount: number;
2651
+ weather: Entities.Weather;
2652
+ flammableParameters: Entities.FlammableParameters;
2653
+ flammableOutputConfig: Entities.FlammableOutputConfig;
2654
+
2655
+ /**
2656
+ * RadiationContour calculation request class.
2657
+ *
2658
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
2659
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
2660
+ * @param {number} flameRecordCount - Number of flame records.
2661
+ * @param {Entities.Weather} weather - A Weather entity.
2662
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
2663
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity.
2664
+ */
2665
+ constructor(
2666
+ flameResult: Entities.FlameResult,
2667
+ flameRecords: Entities.FlameRecord[],
2668
+ flameRecordCount: number,
2669
+ weather: Entities.Weather,
2670
+ flammableParameters: Entities.FlammableParameters,
2671
+ flammableOutputConfig: Entities.FlammableOutputConfig
2672
+ ) {
2673
+ super();
2674
+ this.flameResult = flameResult;
2675
+ this.flameRecords = flameRecords;
2676
+ this.flameRecordCount = flameRecordCount;
2677
+ this.weather = weather;
2678
+ this.flammableParameters = flammableParameters;
2679
+ this.flammableOutputConfig = flammableOutputConfig;
2680
+ }
2681
+ }
2682
+
2683
+ export class RadiationContourCalculationRequestSchema {
2684
+ schema: Joi.ObjectSchema;
2685
+ propertyTypes: Record<string, string>;
2686
+
2687
+ /**
2688
+ * Schema for the RadiationContour calculation request.
2689
+ */
2690
+ constructor() {
2691
+ this.schema = Joi.object({
2692
+ flameResult: new EntitySchemas.FlameResultSchema().schema,
2693
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
2694
+ flameRecordCount: Joi.number().integer(),
2695
+ weather: new EntitySchemas.WeatherSchema().schema,
2696
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
2697
+ flammableOutputConfig: new EntitySchemas.FlammableOutputConfigSchema().schema,
2698
+ }).unknown(true);
2699
+
2700
+ this.propertyTypes = {
2701
+ flameResult: "Entities.FlameResult",
2702
+ flameRecords: "Entities.FlameRecord[]",
2703
+ flameRecordCount: "number",
2704
+ weather: "Entities.Weather",
2705
+ flammableParameters: "Entities.FlammableParameters",
2706
+ flammableOutputConfig: "Entities.FlammableOutputConfig",
2707
+ };
2708
+ }
2709
+
2710
+ validate(data: RadiationContourCalculationRequestSchemaData): RadiationContourCalculationRequest {
2711
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
2712
+ if (error) {
2713
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
2714
+ }
2715
+ return this.makeCalculationRequest(value);
2716
+ }
2717
+
2718
+ makeCalculationRequest(data: RadiationContourCalculationRequestSchemaData): RadiationContourCalculationRequest {
2719
+ return new RadiationContourCalculationRequest(
2720
+ data.flameResult,
2721
+ data.flameRecords,
2722
+ data.flameRecordCount,
2723
+ data.weather,
2724
+ data.flammableParameters,
2725
+ data.flammableOutputConfig
2726
+ );
2727
+ }
2728
+ }
2729
+
2730
+ export class RadiationContourCalculation extends CalculationBase {
2731
+ flameResult: Entities.FlameResult;
2732
+ flameRecords: Entities.FlameRecord[];
2733
+ flameRecordCount: number;
2734
+ weather: Entities.Weather;
2735
+ flammableParameters: Entities.FlammableParameters;
2736
+ flammableOutputConfig: Entities.FlammableOutputConfig;
2737
+ contourPoints?: Entities.LocalPosition[];
2738
+
2739
+ /**
2740
+ * Calculates the radiation contours from a flame model out to a specified intensity or lethality level. This calculation an be called after any type of fire calculation (fireball, jet fire, pool fire). Sideviews and footprints can be requested.
2741
+ *
2742
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
2743
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
2744
+ * @param {number} flameRecordCount - Number of flame records.
2745
+ * @param {Entities.Weather} weather - A Weather entity.
2746
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
2747
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity.
2748
+ */
2749
+ constructor(
2750
+ flameResult: Entities.FlameResult,
2751
+ flameRecords: Entities.FlameRecord[],
2752
+ flameRecordCount: number,
2753
+ weather: Entities.Weather,
2754
+ flammableParameters: Entities.FlammableParameters,
2755
+ flammableOutputConfig: Entities.FlammableOutputConfig
2756
+ ) {
2757
+ super();
2758
+ this.flameResult = flameResult;
2759
+ this.flameRecords = flameRecords;
2760
+ this.flameRecordCount = flameRecordCount;
2761
+ this.weather = weather;
2762
+ this.flammableParameters = flammableParameters;
2763
+ this.flammableOutputConfig = flammableOutputConfig;
2764
+ }
2765
+
2766
+ async run() {
2767
+ try {
2768
+ const request = new RadiationContourCalculationRequest(
2769
+ this.flameResult,
2770
+ this.flameRecords,
2771
+ this.flameRecordCount,
2772
+ this.weather,
2773
+ this.flammableParameters,
2774
+ this.flammableOutputConfig
2775
+ );
2776
+
2777
+ const schema = new RadiationContourCalculationRequestSchema();
2778
+ const validatedRequest = schema.validate(request);
2779
+
2780
+ const requestJson = JSON.stringify(validatedRequest);
2781
+ const url = `${getAnalyticsApiTarget()}calculateradiationcontour?clientId=${getClientAliasId()}`;
2782
+
2783
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
2784
+
2785
+ const response = await this.postRequest(url, requestJson);
2786
+
2787
+ if (response.status >= 200 && response.status < 300) {
2788
+ const schema = new RadiationContourCalculationResponseSchema();
2789
+ const validatedResponse = schema.validate(response.data);
2790
+
2791
+ this.resultCode = validatedResponse.resultCode;
2792
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
2793
+ this.contourPoints = validatedResponse.contourPoints;
2794
+ this.resultCode = validatedResponse.resultCode;
2795
+ this.messages = validatedResponse.messages ?? [];
2796
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
2797
+ this.operationId = validatedResponse.operationId;
2798
+ } else {
2799
+ this.messages.push(...(validatedResponse.messages ?? []));
2800
+ }
2801
+ } else {
2802
+ this.handleFailedResponse(response);
2803
+ }
2804
+ } catch (error) {
2805
+ if (error instanceof Error) {
2806
+ this.messages.push(`Error: ${error.message}`);
2807
+ } else {
2808
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
2809
+ }
2810
+ console.error(error);
2811
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
2812
+ }
2813
+
2814
+ return this.resultCode;
2815
+ }
2816
+
2817
+ toString() {
2818
+ const parts = ["* RadiationContour"];
2819
+
2820
+ parts.push("*** contourPoints:");
2821
+ parts.push(
2822
+ this.contourPoints && this.contourPoints.length > 0
2823
+ ? this.contourPoints.map((point) => `contourPointsElement: ${point}`).join("\n")
2824
+ : "contourPoints does not contain any elements"
2825
+ );
2826
+ parts.push(`resultCode: ${String(this.resultCode)}`);
2827
+ parts.push("*** messages:");
2828
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
2829
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
2830
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
2831
+
2832
+ return parts.join("\n");
2833
+ }
2834
+ }
2835
+
2836
+ export class RadiationContourCalculationResponse extends CalculationResponseBase {
2837
+ contourPoints: Entities.LocalPosition[];
2838
+
2839
+ /**
2840
+ * RadiationContour calculation response class.
2841
+ *
2842
+ * @param {Entities.LocalPosition[]} contourPoints - An array of contour points.
2843
+ */
2844
+ constructor(
2845
+ contourPoints: Entities.LocalPosition[],
2846
+ resultCode: Enums.ResultCode,
2847
+ messages: string[],
2848
+ calculationElapsedTime: number,
2849
+ operationId: string
2850
+ ) {
2851
+ super();
2852
+ this.contourPoints = contourPoints;
2853
+ this.resultCode = resultCode;
2854
+ this.messages = messages;
2855
+ this.calculationElapsedTime = calculationElapsedTime;
2856
+ this.operationId = operationId;
2857
+ }
2858
+
2859
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
2860
+ if (data.contourPoints && Array.isArray(data.contourPoints)) {
2861
+ this.contourPoints = data.contourPoints.map(
2862
+ (item) => {
2863
+ const record = new Entities.LocalPosition();
2864
+ record.initialiseFromDictionary(item);
2865
+ return record;
2866
+ }
2867
+ );
2868
+ }
2869
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
2870
+ this.resultCode = data.resultCode as Enums.ResultCode;
2871
+ }
2872
+ this.messages = this.messages ?? [];
2873
+ if (data.messages && Array.isArray(data.messages)) {
2874
+ this.messages.push(...data.messages);
2875
+ }
2876
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
2877
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
2878
+ }
2879
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
2880
+ this.operationId = data.operationId as string;
2881
+ }
2882
+ }
2883
+ }
2884
+
2885
+ export interface RadiationContourCalculationResponseSchemaData {
2886
+ contourPoints: Entities.LocalPosition[];
2887
+ resultCode: Enums.ResultCode;
2888
+ messages: string[];
2889
+ calculationElapsedTime: number;
2890
+ operationId: string;
2891
+ }
2892
+
2893
+ export class RadiationContourCalculationResponseSchema {
2894
+ schema: Joi.ObjectSchema;
2895
+ propertyTypes: Record<string, string>;
2896
+
2897
+ /**
2898
+ * Schema for the RadiationContour calculation response.
2899
+ */
2900
+ constructor() {
2901
+ this.schema = Joi.object({
2902
+ contourPoints: Joi.array().items(new EntitySchemas.LocalPositionSchema().schema).allow(null),
2903
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
2904
+ messages: Joi.array().items(Joi.string()),
2905
+ calculationElapsedTime: Joi.number().unsafe(),
2906
+ operationId: Joi.string().uuid().allow(null),
2907
+ }).unknown(true);
2908
+
2909
+ this.propertyTypes = {
2910
+ contourPoints: "Entities.LocalPosition[]",
2911
+ };
2912
+ }
2913
+
2914
+ validate(data: RadiationContourCalculationResponseSchemaData): RadiationContourCalculationResponse {
2915
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
2916
+ if (error) {
2917
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
2918
+ }
2919
+ return this.makeCalculationResponse(value);
2920
+ }
2921
+
2922
+ makeCalculationResponse(data: RadiationContourCalculationResponseSchemaData): RadiationContourCalculationResponse {
2923
+ return new RadiationContourCalculationResponse(
2924
+ data.contourPoints,
2925
+ data.resultCode,
2926
+ data.messages,
2927
+ data.calculationElapsedTime,
2928
+ data.operationId
2929
+ );
2930
+ }
2931
+ }
2932
+
2933
+ export interface RadiationTransectCalculationRequestSchemaData {
2934
+ flameResult: Entities.FlameResult;
2935
+ flameRecords: Entities.FlameRecord[];
2936
+ flameRecordCount: number;
2937
+ weather: Entities.Weather;
2938
+ flammableParameters: Entities.FlammableParameters;
2939
+ flammableOutputConfig: Entities.FlammableOutputConfig;
2940
+ }
2941
+
2942
+ class RadiationTransectCalculationRequest extends CalculationRequestBase {
2943
+ flameResult: Entities.FlameResult;
2944
+ flameRecords: Entities.FlameRecord[];
2945
+ flameRecordCount: number;
2946
+ weather: Entities.Weather;
2947
+ flammableParameters: Entities.FlammableParameters;
2948
+ flammableOutputConfig: Entities.FlammableOutputConfig;
2949
+
2950
+ /**
2951
+ * RadiationTransect calculation request class.
2952
+ *
2953
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
2954
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
2955
+ * @param {number} flameRecordCount - Number of Flame Records.
2956
+ * @param {Entities.Weather} weather - A Weather entity.
2957
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
2958
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity.
2959
+ */
2960
+ constructor(
2961
+ flameResult: Entities.FlameResult,
2962
+ flameRecords: Entities.FlameRecord[],
2963
+ flameRecordCount: number,
2964
+ weather: Entities.Weather,
2965
+ flammableParameters: Entities.FlammableParameters,
2966
+ flammableOutputConfig: Entities.FlammableOutputConfig
2967
+ ) {
2968
+ super();
2969
+ this.flameResult = flameResult;
2970
+ this.flameRecords = flameRecords;
2971
+ this.flameRecordCount = flameRecordCount;
2972
+ this.weather = weather;
2973
+ this.flammableParameters = flammableParameters;
2974
+ this.flammableOutputConfig = flammableOutputConfig;
2975
+ }
2976
+ }
2977
+
2978
+ export class RadiationTransectCalculationRequestSchema {
2979
+ schema: Joi.ObjectSchema;
2980
+ propertyTypes: Record<string, string>;
2981
+
2982
+ /**
2983
+ * Schema for the RadiationTransect calculation request.
2984
+ */
2985
+ constructor() {
2986
+ this.schema = Joi.object({
2987
+ flameResult: new EntitySchemas.FlameResultSchema().schema,
2988
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
2989
+ flameRecordCount: Joi.number().integer(),
2990
+ weather: new EntitySchemas.WeatherSchema().schema,
2991
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
2992
+ flammableOutputConfig: new EntitySchemas.FlammableOutputConfigSchema().schema,
2993
+ }).unknown(true);
2994
+
2995
+ this.propertyTypes = {
2996
+ flameResult: "Entities.FlameResult",
2997
+ flameRecords: "Entities.FlameRecord[]",
2998
+ flameRecordCount: "number",
2999
+ weather: "Entities.Weather",
3000
+ flammableParameters: "Entities.FlammableParameters",
3001
+ flammableOutputConfig: "Entities.FlammableOutputConfig",
3002
+ };
3003
+ }
3004
+
3005
+ validate(data: RadiationTransectCalculationRequestSchemaData): RadiationTransectCalculationRequest {
3006
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
3007
+ if (error) {
3008
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
3009
+ }
3010
+ return this.makeCalculationRequest(value);
3011
+ }
3012
+
3013
+ makeCalculationRequest(data: RadiationTransectCalculationRequestSchemaData): RadiationTransectCalculationRequest {
3014
+ return new RadiationTransectCalculationRequest(
3015
+ data.flameResult,
3016
+ data.flameRecords,
3017
+ data.flameRecordCount,
3018
+ data.weather,
3019
+ data.flammableParameters,
3020
+ data.flammableOutputConfig
3021
+ );
3022
+ }
3023
+ }
3024
+
3025
+ export class RadiationTransectCalculation extends CalculationBase {
3026
+ flameResult: Entities.FlameResult;
3027
+ flameRecords: Entities.FlameRecord[];
3028
+ flameRecordCount: number;
3029
+ weather: Entities.Weather;
3030
+ flammableParameters: Entities.FlammableParameters;
3031
+ flammableOutputConfig: Entities.FlammableOutputConfig;
3032
+ radiationRecords?: Entities.RadiationRecord[];
3033
+
3034
+ /**
3035
+ * Calculates the radiation along a specified transect from a flame model down to a specified intensity or lethality level. This calculation an be called after any type of fire calculation (fireball, jet fire, pool fire).
3036
+ *
3037
+ * @param {Entities.FlameResult} flameResult - Scalar flame results.
3038
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
3039
+ * @param {number} flameRecordCount - Number of Flame Records.
3040
+ * @param {Entities.Weather} weather - A Weather entity.
3041
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
3042
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity.
3043
+ */
3044
+ constructor(
3045
+ flameResult: Entities.FlameResult,
3046
+ flameRecords: Entities.FlameRecord[],
3047
+ flameRecordCount: number,
3048
+ weather: Entities.Weather,
3049
+ flammableParameters: Entities.FlammableParameters,
3050
+ flammableOutputConfig: Entities.FlammableOutputConfig
3051
+ ) {
3052
+ super();
3053
+ this.flameResult = flameResult;
3054
+ this.flameRecords = flameRecords;
3055
+ this.flameRecordCount = flameRecordCount;
3056
+ this.weather = weather;
3057
+ this.flammableParameters = flammableParameters;
3058
+ this.flammableOutputConfig = flammableOutputConfig;
3059
+ }
3060
+
3061
+ async run() {
3062
+ try {
3063
+ const request = new RadiationTransectCalculationRequest(
3064
+ this.flameResult,
3065
+ this.flameRecords,
3066
+ this.flameRecordCount,
3067
+ this.weather,
3068
+ this.flammableParameters,
3069
+ this.flammableOutputConfig
3070
+ );
3071
+
3072
+ const schema = new RadiationTransectCalculationRequestSchema();
3073
+ const validatedRequest = schema.validate(request);
3074
+
3075
+ const requestJson = JSON.stringify(validatedRequest);
3076
+ const url = `${getAnalyticsApiTarget()}calculateradiationtransect?clientId=${getClientAliasId()}`;
3077
+
3078
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
3079
+
3080
+ const response = await this.postRequest(url, requestJson);
3081
+
3082
+ if (response.status >= 200 && response.status < 300) {
3083
+ const schema = new RadiationTransectCalculationResponseSchema();
3084
+ const validatedResponse = schema.validate(response.data);
3085
+
3086
+ this.resultCode = validatedResponse.resultCode;
3087
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
3088
+ this.radiationRecords = validatedResponse.radiationRecords;
3089
+ this.resultCode = validatedResponse.resultCode;
3090
+ this.messages = validatedResponse.messages ?? [];
3091
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
3092
+ this.operationId = validatedResponse.operationId;
3093
+ } else {
3094
+ this.messages.push(...(validatedResponse.messages ?? []));
3095
+ }
3096
+ } else {
3097
+ this.handleFailedResponse(response);
3098
+ }
3099
+ } catch (error) {
3100
+ if (error instanceof Error) {
3101
+ this.messages.push(`Error: ${error.message}`);
3102
+ } else {
3103
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
3104
+ }
3105
+ console.error(error);
3106
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
3107
+ }
3108
+
3109
+ return this.resultCode;
3110
+ }
3111
+
3112
+ toString() {
3113
+ const parts = ["* RadiationTransect"];
3114
+
3115
+ parts.push("*** radiationRecords:");
3116
+ parts.push(
3117
+ this.radiationRecords && this.radiationRecords.length > 0
3118
+ ? this.radiationRecords.map((point) => `radiationRecordsElement: ${point}`).join("\n")
3119
+ : "radiationRecords does not contain any elements"
3120
+ );
3121
+ parts.push(`resultCode: ${String(this.resultCode)}`);
3122
+ parts.push("*** messages:");
3123
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
3124
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
3125
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
3126
+
3127
+ return parts.join("\n");
3128
+ }
3129
+ }
3130
+
3131
+ export class RadiationTransectCalculationResponse extends CalculationResponseBase {
3132
+ radiationRecords: Entities.RadiationRecord[];
3133
+
3134
+ /**
3135
+ * RadiationTransect calculation response class.
3136
+ *
3137
+ * @param {Entities.RadiationRecord[]} radiationRecords - An array of Radiation Records along transect.
3138
+ */
3139
+ constructor(
3140
+ radiationRecords: Entities.RadiationRecord[],
3141
+ resultCode: Enums.ResultCode,
3142
+ messages: string[],
3143
+ calculationElapsedTime: number,
3144
+ operationId: string
3145
+ ) {
3146
+ super();
3147
+ this.radiationRecords = radiationRecords;
3148
+ this.resultCode = resultCode;
3149
+ this.messages = messages;
3150
+ this.calculationElapsedTime = calculationElapsedTime;
3151
+ this.operationId = operationId;
3152
+ }
3153
+
3154
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
3155
+ if (data.radiationRecords && Array.isArray(data.radiationRecords)) {
3156
+ this.radiationRecords = data.radiationRecords.map(
3157
+ (item) => {
3158
+ const record = new Entities.RadiationRecord();
3159
+ record.initialiseFromDictionary(item);
3160
+ return record;
3161
+ }
3162
+ );
3163
+ }
3164
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
3165
+ this.resultCode = data.resultCode as Enums.ResultCode;
3166
+ }
3167
+ this.messages = this.messages ?? [];
3168
+ if (data.messages && Array.isArray(data.messages)) {
3169
+ this.messages.push(...data.messages);
3170
+ }
3171
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
3172
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
3173
+ }
3174
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
3175
+ this.operationId = data.operationId as string;
3176
+ }
3177
+ }
3178
+ }
3179
+
3180
+ export interface RadiationTransectCalculationResponseSchemaData {
3181
+ radiationRecords: Entities.RadiationRecord[];
3182
+ resultCode: Enums.ResultCode;
3183
+ messages: string[];
3184
+ calculationElapsedTime: number;
3185
+ operationId: string;
3186
+ }
3187
+
3188
+ export class RadiationTransectCalculationResponseSchema {
3189
+ schema: Joi.ObjectSchema;
3190
+ propertyTypes: Record<string, string>;
3191
+
3192
+ /**
3193
+ * Schema for the RadiationTransect calculation response.
3194
+ */
3195
+ constructor() {
3196
+ this.schema = Joi.object({
3197
+ radiationRecords: Joi.array().items(new EntitySchemas.RadiationRecordSchema().schema).allow(null),
3198
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
3199
+ messages: Joi.array().items(Joi.string()),
3200
+ calculationElapsedTime: Joi.number().unsafe(),
3201
+ operationId: Joi.string().uuid().allow(null),
3202
+ }).unknown(true);
3203
+
3204
+ this.propertyTypes = {
3205
+ radiationRecords: "Entities.RadiationRecord[]",
3206
+ };
3207
+ }
3208
+
3209
+ validate(data: RadiationTransectCalculationResponseSchemaData): RadiationTransectCalculationResponse {
3210
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
3211
+ if (error) {
3212
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
3213
+ }
3214
+ return this.makeCalculationResponse(value);
3215
+ }
3216
+
3217
+ makeCalculationResponse(data: RadiationTransectCalculationResponseSchemaData): RadiationTransectCalculationResponse {
3218
+ return new RadiationTransectCalculationResponse(
3219
+ data.radiationRecords,
3220
+ data.resultCode,
3221
+ data.messages,
3222
+ data.calculationElapsedTime,
3223
+ data.operationId
3224
+ );
3225
+ }
3226
+ }
3227
+
3228
+ export interface RadiationTransectForPoolFiresCalculationRequestSchemaData {
3229
+ poolFireFlameResult: Entities.PoolFireFlameResult;
3230
+ flameRecords: Entities.FlameRecord[];
3231
+ flameRecordCount: number;
3232
+ weather: Entities.Weather;
3233
+ flammableParameters: Entities.FlammableParameters;
3234
+ flammableOutputConfig: Entities.FlammableOutputConfig;
3235
+ }
3236
+
3237
+ class RadiationTransectForPoolFiresCalculationRequest extends CalculationRequestBase {
3238
+ poolFireFlameResult: Entities.PoolFireFlameResult;
3239
+ flameRecords: Entities.FlameRecord[];
3240
+ flameRecordCount: number;
3241
+ weather: Entities.Weather;
3242
+ flammableParameters: Entities.FlammableParameters;
3243
+ flammableOutputConfig: Entities.FlammableOutputConfig;
3244
+
3245
+ /**
3246
+ * RadiationTransectForPoolFires calculation request class.
3247
+ *
3248
+ * @param {Entities.PoolFireFlameResult} poolFireFlameResult - Pool fire flame results.
3249
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
3250
+ * @param {number} flameRecordCount - Number of Flame Records.
3251
+ * @param {Entities.Weather} weather - A Weather entity.
3252
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
3253
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity.
3254
+ */
3255
+ constructor(
3256
+ poolFireFlameResult: Entities.PoolFireFlameResult,
3257
+ flameRecords: Entities.FlameRecord[],
3258
+ flameRecordCount: number,
3259
+ weather: Entities.Weather,
3260
+ flammableParameters: Entities.FlammableParameters,
3261
+ flammableOutputConfig: Entities.FlammableOutputConfig
3262
+ ) {
3263
+ super();
3264
+ this.poolFireFlameResult = poolFireFlameResult;
3265
+ this.flameRecords = flameRecords;
3266
+ this.flameRecordCount = flameRecordCount;
3267
+ this.weather = weather;
3268
+ this.flammableParameters = flammableParameters;
3269
+ this.flammableOutputConfig = flammableOutputConfig;
3270
+ }
3271
+ }
3272
+
3273
+ export class RadiationTransectForPoolFiresCalculationRequestSchema {
3274
+ schema: Joi.ObjectSchema;
3275
+ propertyTypes: Record<string, string>;
3276
+
3277
+ /**
3278
+ * Schema for the RadiationTransectForPoolFires calculation request.
3279
+ */
3280
+ constructor() {
3281
+ this.schema = Joi.object({
3282
+ poolFireFlameResult: new EntitySchemas.PoolFireFlameResultSchema().schema,
3283
+ flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
3284
+ flameRecordCount: Joi.number().integer(),
3285
+ weather: new EntitySchemas.WeatherSchema().schema,
3286
+ flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
3287
+ flammableOutputConfig: new EntitySchemas.FlammableOutputConfigSchema().schema,
3288
+ }).unknown(true);
3289
+
3290
+ this.propertyTypes = {
3291
+ poolFireFlameResult: "Entities.PoolFireFlameResult",
3292
+ flameRecords: "Entities.FlameRecord[]",
3293
+ flameRecordCount: "number",
3294
+ weather: "Entities.Weather",
3295
+ flammableParameters: "Entities.FlammableParameters",
3296
+ flammableOutputConfig: "Entities.FlammableOutputConfig",
3297
+ };
3298
+ }
3299
+
3300
+ validate(data: RadiationTransectForPoolFiresCalculationRequestSchemaData): RadiationTransectForPoolFiresCalculationRequest {
3301
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
3302
+ if (error) {
3303
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
3304
+ }
3305
+ return this.makeCalculationRequest(value);
3306
+ }
3307
+
3308
+ makeCalculationRequest(data: RadiationTransectForPoolFiresCalculationRequestSchemaData): RadiationTransectForPoolFiresCalculationRequest {
3309
+ return new RadiationTransectForPoolFiresCalculationRequest(
3310
+ data.poolFireFlameResult,
3311
+ data.flameRecords,
3312
+ data.flameRecordCount,
3313
+ data.weather,
3314
+ data.flammableParameters,
3315
+ data.flammableOutputConfig
3316
+ );
3317
+ }
3318
+ }
3319
+
3320
+ export class RadiationTransectForPoolFiresCalculation extends CalculationBase {
3321
+ poolFireFlameResult: Entities.PoolFireFlameResult;
3322
+ flameRecords: Entities.FlameRecord[];
3323
+ flameRecordCount: number;
3324
+ weather: Entities.Weather;
3325
+ flammableParameters: Entities.FlammableParameters;
3326
+ flammableOutputConfig: Entities.FlammableOutputConfig;
3327
+ radiationRecords?: Entities.RadiationRecord[];
3328
+
3329
+ /**
3330
+ * Calculates the radiation along a specified transect from a flame model down to a specified intensity or lethality level. This calculation can be called after pool fire calculation.
3331
+ *
3332
+ * @param {Entities.PoolFireFlameResult} poolFireFlameResult - Pool fire flame results.
3333
+ * @param {Entities.FlameRecord[]} flameRecords - An array of Flame Records.
3334
+ * @param {number} flameRecordCount - Number of Flame Records.
3335
+ * @param {Entities.Weather} weather - A Weather entity.
3336
+ * @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
3337
+ * @param {Entities.FlammableOutputConfig} flammableOutputConfig - A Flammable Output Config entity.
3338
+ */
3339
+ constructor(
3340
+ poolFireFlameResult: Entities.PoolFireFlameResult,
3341
+ flameRecords: Entities.FlameRecord[],
3342
+ flameRecordCount: number,
3343
+ weather: Entities.Weather,
3344
+ flammableParameters: Entities.FlammableParameters,
3345
+ flammableOutputConfig: Entities.FlammableOutputConfig
3346
+ ) {
3347
+ super();
3348
+ this.poolFireFlameResult = poolFireFlameResult;
3349
+ this.flameRecords = flameRecords;
3350
+ this.flameRecordCount = flameRecordCount;
3351
+ this.weather = weather;
3352
+ this.flammableParameters = flammableParameters;
3353
+ this.flammableOutputConfig = flammableOutputConfig;
3354
+ }
3355
+
3356
+ async run() {
3357
+ try {
3358
+ const request = new RadiationTransectForPoolFiresCalculationRequest(
3359
+ this.poolFireFlameResult,
3360
+ this.flameRecords,
3361
+ this.flameRecordCount,
3362
+ this.weather,
3363
+ this.flammableParameters,
3364
+ this.flammableOutputConfig
3365
+ );
3366
+
3367
+ const schema = new RadiationTransectForPoolFiresCalculationRequestSchema();
3368
+ const validatedRequest = schema.validate(request);
3369
+
3370
+ const requestJson = JSON.stringify(validatedRequest);
3371
+ const url = `${getAnalyticsApiTarget()}calculateradiationtransectforpoolfires?clientId=${getClientAliasId()}`;
3372
+
3373
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
3374
+
3375
+ const response = await this.postRequest(url, requestJson);
3376
+
3377
+ if (response.status >= 200 && response.status < 300) {
3378
+ const schema = new RadiationTransectForPoolFiresCalculationResponseSchema();
3379
+ const validatedResponse = schema.validate(response.data);
3380
+
3381
+ this.resultCode = validatedResponse.resultCode;
3382
+ if (this.resultCode === Enums.ResultCode.SUCCESS) {
3383
+ this.radiationRecords = validatedResponse.radiationRecords;
3384
+ this.resultCode = validatedResponse.resultCode;
3385
+ this.messages = validatedResponse.messages ?? [];
3386
+ this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
3387
+ this.operationId = validatedResponse.operationId;
3388
+ } else {
3389
+ this.messages.push(...(validatedResponse.messages ?? []));
3390
+ }
3391
+ } else {
3392
+ this.handleFailedResponse(response);
3393
+ }
3394
+ } catch (error) {
3395
+ if (error instanceof Error) {
3396
+ this.messages.push(`Error: ${error.message}`);
3397
+ } else {
3398
+ this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
3399
+ }
3400
+ console.error(error);
3401
+ this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
3402
+ }
3403
+
3404
+ return this.resultCode;
3405
+ }
3406
+
3407
+ toString() {
3408
+ const parts = ["* RadiationTransectForPoolFires"];
3409
+
3410
+ parts.push("*** radiationRecords:");
3411
+ parts.push(
3412
+ this.radiationRecords && this.radiationRecords.length > 0
3413
+ ? this.radiationRecords.map((point) => `radiationRecordsElement: ${point}`).join("\n")
3414
+ : "radiationRecords does not contain any elements"
3415
+ );
3416
+ parts.push(`resultCode: ${String(this.resultCode)}`);
3417
+ parts.push("*** messages:");
3418
+ parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
3419
+ parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
3420
+ parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
3421
+
3422
+ return parts.join("\n");
3423
+ }
3424
+ }
3425
+
3426
+ export class RadiationTransectForPoolFiresCalculationResponse extends CalculationResponseBase {
3427
+ radiationRecords: Entities.RadiationRecord[];
3428
+
3429
+ /**
3430
+ * RadiationTransectForPoolFires calculation response class.
3431
+ *
3432
+ * @param {Entities.RadiationRecord[]} radiationRecords - An array of Radiation Records along transect.
3433
+ */
3434
+ constructor(
3435
+ radiationRecords: Entities.RadiationRecord[],
3436
+ resultCode: Enums.ResultCode,
3437
+ messages: string[],
3438
+ calculationElapsedTime: number,
3439
+ operationId: string
3440
+ ) {
3441
+ super();
3442
+ this.radiationRecords = radiationRecords;
3443
+ this.resultCode = resultCode;
3444
+ this.messages = messages;
3445
+ this.calculationElapsedTime = calculationElapsedTime;
3446
+ this.operationId = operationId;
3447
+ }
3448
+
3449
+ initialiseFromDictionary(data: { [key: string]: unknown }) {
3450
+ if (data.radiationRecords && Array.isArray(data.radiationRecords)) {
3451
+ this.radiationRecords = data.radiationRecords.map(
3452
+ (item) => {
3453
+ const record = new Entities.RadiationRecord();
3454
+ record.initialiseFromDictionary(item);
3455
+ return record;
3456
+ }
3457
+ );
3458
+ }
3459
+ if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
3460
+ this.resultCode = data.resultCode as Enums.ResultCode;
3461
+ }
3462
+ this.messages = this.messages ?? [];
3463
+ if (data.messages && Array.isArray(data.messages)) {
3464
+ this.messages.push(...data.messages);
3465
+ }
3466
+ if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
3467
+ this.calculationElapsedTime = data.calculationElapsedTime as number;
3468
+ }
3469
+ if (data.operationId !== undefined && typeof data.operationId === "string") {
3470
+ this.operationId = data.operationId as string;
3471
+ }
3472
+ }
3473
+ }
3474
+
3475
+ export interface RadiationTransectForPoolFiresCalculationResponseSchemaData {
3476
+ radiationRecords: Entities.RadiationRecord[];
3477
+ resultCode: Enums.ResultCode;
3478
+ messages: string[];
3479
+ calculationElapsedTime: number;
3480
+ operationId: string;
3481
+ }
3482
+
3483
+ export class RadiationTransectForPoolFiresCalculationResponseSchema {
3484
+ schema: Joi.ObjectSchema;
3485
+ propertyTypes: Record<string, string>;
3486
+
3487
+ /**
3488
+ * Schema for the RadiationTransectForPoolFires calculation response.
3489
+ */
3490
+ constructor() {
3491
+ this.schema = Joi.object({
3492
+ radiationRecords: Joi.array().items(new EntitySchemas.RadiationRecordSchema().schema).allow(null),
3493
+ resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
3494
+ messages: Joi.array().items(Joi.string()),
3495
+ calculationElapsedTime: Joi.number().unsafe(),
3496
+ operationId: Joi.string().uuid().allow(null),
3497
+ }).unknown(true);
3498
+
3499
+ this.propertyTypes = {
3500
+ radiationRecords: "Entities.RadiationRecord[]",
3501
+ };
3502
+ }
3503
+
3504
+ validate(data: RadiationTransectForPoolFiresCalculationResponseSchemaData): RadiationTransectForPoolFiresCalculationResponse {
3505
+ const { error, value } = this.schema.validate(data, { abortEarly: false });
3506
+ if (error) {
3507
+ throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
3508
+ }
3509
+ return this.makeCalculationResponse(value);
3510
+ }
3511
+
3512
+ makeCalculationResponse(data: RadiationTransectForPoolFiresCalculationResponseSchemaData): RadiationTransectForPoolFiresCalculationResponse {
3513
+ return new RadiationTransectForPoolFiresCalculationResponse(
3514
+ data.radiationRecords,
3515
+ data.resultCode,
3516
+ data.messages,
3517
+ data.calculationElapsedTime,
3518
+ data.operationId
3519
+ );
3520
+ }
3521
+ }