@sdeverywhere/check-core 0.1.0 → 0.1.2

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.
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- declare type SourceName = string;
2
- declare type VarId = string;
3
- declare type ScenarioKey = string;
4
- declare type ScenarioGroupKey = string;
5
- declare type DatasetKey = string;
6
- declare type Dataset = Map<number, number>;
7
- declare type DatasetMap = Map<DatasetKey, Dataset>;
8
-
9
- declare type InputPosition = 'at-default' | 'at-minimum' | 'at-maximum';
1
+ type SourceName = string;
2
+ type VarId = string;
3
+ type DatasetKey = string;
4
+ type Dataset = Map<number, number>;
5
+ type DatasetMap = Map<DatasetKey, Dataset>;
6
+
7
+ /** A unique identifier for the scenario, derived from its input settings. */
8
+ type ScenarioSpecUid = string;
9
+ type InputPosition = 'at-default' | 'at-minimum' | 'at-maximum';
10
10
  interface PositionSetting {
11
11
  kind: 'position';
12
12
  inputVarId: VarId;
@@ -17,39 +17,18 @@ interface ValueSetting {
17
17
  inputVarId: VarId;
18
18
  value: number;
19
19
  }
20
- declare type InputSetting = PositionSetting | ValueSetting;
21
- interface SettingsScenario {
22
- kind: 'settings';
23
- key: ScenarioKey;
24
- groupKey: ScenarioGroupKey;
20
+ type InputSetting = PositionSetting | ValueSetting;
21
+ interface InputSettingsSpec {
22
+ kind: 'input-settings';
23
+ uid: ScenarioSpecUid;
25
24
  settings: InputSetting[];
26
25
  }
27
- interface AllInputsScenario {
26
+ interface AllInputsSpec {
28
27
  kind: 'all-inputs';
29
- key: ScenarioKey;
30
- groupKey: ScenarioGroupKey;
28
+ uid: ScenarioSpecUid;
31
29
  position: InputPosition;
32
30
  }
33
- declare type Scenario = SettingsScenario | AllInputsScenario;
34
- declare function positionSetting(inputVarId: VarId, position: InputPosition): InputSetting;
35
- declare function valueSetting(inputVarId: VarId, value: number): InputSetting;
36
- declare function settingsScenario(key: ScenarioKey, groupKey: ScenarioGroupKey, settings: InputSetting[]): Scenario;
37
- declare function inputAtPositionScenario(inputVarId: VarId, groupKey: ScenarioGroupKey, position: InputPosition): Scenario;
38
- declare function inputAtValueScenario(inputVarId: VarId, groupKey: ScenarioGroupKey, value: number): Scenario;
39
- declare function allInputsAtPositionScenario(position: InputPosition): Scenario;
40
- /**
41
- * Return an array of scenarios that can be used to run the model
42
- * with a matrix of output/input scenarios.
43
- *
44
- * For each output variable, run the model:
45
- * - once with all inputs at their default
46
- * - once with all inputs at their minimum
47
- * - once with all inputs at their maximum
48
- * - twice for each input
49
- * - once with single input at its minimum
50
- * - once with single input at its maximum
51
- */
52
- declare function matrixScenarios(inputVarIds: VarId[]): Scenario[];
31
+ type ScenarioSpec = InputSettingsSpec | AllInputsSpec;
53
32
 
54
33
  interface DatasetsResult {
55
34
  /**
@@ -64,7 +43,7 @@ interface DatasetsResult {
64
43
  }
65
44
  interface DataSource {
66
45
  /** Return the datasets that result from running the given scenario. */
67
- getDatasetsForScenario(scenario: Scenario, datasetKeys: DatasetKey[]): Promise<DatasetsResult>;
46
+ getDatasetsForScenario(scenarioSpec: ScenarioSpec, datasetKeys: DatasetKey[]): Promise<DatasetsResult>;
68
47
  }
69
48
 
70
49
  /**
@@ -76,24 +55,58 @@ interface RelatedItem {
76
55
  id: string;
77
56
  locationPath: string[];
78
57
  }
58
+ /** A unique, stable input identifier. */
59
+ type InputId = string;
79
60
  /**
80
61
  * Holds information about an input variable used in the model.
81
62
  */
82
63
  interface InputVar {
64
+ /**
65
+ * Whether this input is controlled by a continuous range/slider or a discrete on/off switch.
66
+ * If undefined, 'slider' will be assumed.
67
+ */
68
+ kind?: 'slider' | 'switch';
69
+ /**
70
+ * A unique, stable identifier string for this input.
71
+ *
72
+ * This can be used to identify an input variable in a way that is resilient
73
+ * to the variable's name being changed between two versions of the model.
74
+ *
75
+ * For example, if both the "left" and "right" versions of the model have an
76
+ * input with an `inputId` of 2, but the variable is called "Variable 2" in
77
+ * the left and "Variable Two" in the right, the inputs can be correlated and
78
+ * compared despite the different variable names.
79
+ */
80
+ inputId: InputId;
81
+ /** The variable identifier (typically a simplified/canonical ID, like the form used in SDE). */
83
82
  varId: VarId;
83
+ /** The full variable name as used in the modeling tool. */
84
84
  varName: string;
85
+ /** The default value of the input. */
85
86
  defaultValue: number;
87
+ /** The minimum value of the input. */
86
88
  minValue: number;
89
+ /** The maximum value of the input. */
87
90
  maxValue: number;
91
+ /** The metadata for the related input control. */
88
92
  relatedItem?: RelatedItem;
89
93
  }
90
94
  /**
91
95
  * Holds information about an output variable used in the model.
92
96
  */
93
97
  interface OutputVar {
98
+ /** The unique dataset key for this variable (it should include `sourceName` and `varId`). */
99
+ datasetKey: DatasetKey;
100
+ /**
101
+ * The source for the variable (e.g., undefined for a normal model output, "Data" for a variable
102
+ * that is defined in an external data file).
103
+ */
94
104
  sourceName?: SourceName;
105
+ /** The variable identifier (typically a simplified/canonical ID, like the form used in SDE). */
95
106
  varId: VarId;
107
+ /** The full variable name as used in the modeling tool. */
96
108
  varName: string;
109
+ /** The metadata for the related visuals/graphs in which this variable is used. */
97
110
  relatedItems?: RelatedItem[];
98
111
  }
99
112
  /**
@@ -122,7 +135,7 @@ interface Dimension {
122
135
  interface ImplVar {
123
136
  /** The variable identifier, as used in SDE. */
124
137
  varId: VarId;
125
- /** The variable name, as used in Vensim. */
138
+ /** The variable name, as used in the modeling tool. */
126
139
  varName: string;
127
140
  /** The variable index, used by SDE to reference the value in the generated model. */
128
141
  varIndex: number;
@@ -132,6 +145,12 @@ interface ImplVar {
132
145
  varType: string;
133
146
  }
134
147
 
148
+ /** The human-readable name for a group of inputs. */
149
+ type InputGroupName = string;
150
+ /** The alias name for an input. */
151
+ type InputAliasName = string;
152
+ /** The human-readable name for a group of dataset. */
153
+ type DatasetGroupName = string;
135
154
  /**
136
155
  * Includes the properties needed to display a legend item in the UI.
137
156
  */
@@ -152,7 +171,8 @@ interface LinkItem {
152
171
  /** The link content (a URL or text). */
153
172
  content: string;
154
173
  }
155
- declare type BundleGraphId = string;
174
+ /** The identifier for a bundle-specific graph. */
175
+ type BundleGraphId = string;
156
176
  /**
157
177
  * Describes a dataset in a bundle-specific graph.
158
178
  */
@@ -211,10 +231,12 @@ interface ModelSpec {
211
231
  outputVars: Map<DatasetKey, OutputVar>;
212
232
  /** The map of all variables (both internal and exported) in this version of the model. */
213
233
  implVars: Map<DatasetKey, ImplVar>;
234
+ /** The custom input variable aliases defined for this model. */
235
+ inputAliases?: Map<InputAliasName, VarId>;
214
236
  /** The custom input variable groups defined for this model. */
215
- inputGroups: Map<string, InputVar[]>;
237
+ inputGroups?: Map<InputGroupName, InputVar[]>;
216
238
  /** The custom dataset (output variable) groups defined for this model. */
217
- datasetGroups: Map<string, DatasetKey[]>;
239
+ datasetGroups?: Map<DatasetGroupName, DatasetKey[]>;
218
240
  /** The start time (year) for the model. */
219
241
  startTime?: number;
220
242
  /** The end time (year) for the model. */
@@ -229,18 +251,13 @@ interface ModelSpec {
229
251
  interface BundleModel extends DataSource {
230
252
  /** The spec for the bundled model. */
231
253
  modelSpec: ModelSpec;
232
- /**
233
- * Return the set of context graphs to be displayed for the given dataset. If left
234
- * undefined, the set of graphs will be determined using the advertised graph specs.
235
- */
236
- getGraphsForDataset?(datasetKey: DatasetKey): BundleGraphId[];
237
254
  /**
238
255
  * Load the data used to display the graph by running the model with inputs
239
256
  * configured for the given scenario.
240
257
  */
241
- getGraphDataForScenario(scenario: Scenario, graphId: BundleGraphId): Promise<BundleGraphData>;
258
+ getGraphDataForScenario(scenarioSpec: ScenarioSpec, graphId: BundleGraphId): Promise<BundleGraphData>;
242
259
  /** Return the links to be displayed for the graph in the given scenario. */
243
- getGraphLinksForScenario(scenario: Scenario, graphId: BundleGraphId): LinkItem[];
260
+ getGraphLinksForScenario(scenarioSpec: ScenarioSpec, graphId: BundleGraphId): LinkItem[];
244
261
  }
245
262
  /**
246
263
  * Provides access to the model that is contained in this bundle for use in
@@ -279,7 +296,7 @@ interface LoadedBundle {
279
296
  model: BundleModel;
280
297
  }
281
298
 
282
- declare type CheckDataRequestKey = string;
299
+ type CheckDataRequestKey = string;
283
300
  /**
284
301
  * Coordinates on-demand loading of data used to display a graph representation
285
302
  * of a check/predicate.
@@ -288,21 +305,21 @@ declare class CheckDataCoordinator {
288
305
  readonly bundleModel: BundleModel;
289
306
  private readonly taskQueue;
290
307
  constructor(bundleModel: BundleModel);
291
- requestDataset(requestKey: CheckDataRequestKey, scenario: Scenario, datasetKey: DatasetKey, onResponse: (dataset: Dataset) => void): void;
308
+ requestDataset(requestKey: CheckDataRequestKey, scenarioSpec: ScenarioSpec, datasetKey: DatasetKey, onResponse: (dataset: Dataset) => void): void;
292
309
  cancelRequest(key: CheckDataRequestKey): void;
293
310
  }
294
311
 
295
- declare type CheckPredicateOp = 'gt' | 'gte' | 'lt' | 'lte' | 'eq' | 'approx';
312
+ type CheckPredicateOp = 'gt' | 'gte' | 'lt' | 'lte' | 'eq' | 'approx';
296
313
 
297
- declare type CheckPredicateTimeSingle = number;
298
- declare type CheckPredicateTimeRange = [number, number];
314
+ type CheckPredicateTimeSingle = number;
315
+ type CheckPredicateTimeRange = [number, number];
299
316
  interface CheckPredicateTimeOptions {
300
317
  after_excl?: number;
301
318
  after_incl?: number;
302
319
  before_excl?: number;
303
320
  before_incl?: number;
304
321
  }
305
- declare type CheckPredicateTimeSpec = CheckPredicateTimeSingle | CheckPredicateTimeRange | CheckPredicateTimeOptions;
322
+ type CheckPredicateTimeSpec = CheckPredicateTimeSingle | CheckPredicateTimeRange | CheckPredicateTimeOptions;
306
323
 
307
324
  interface CheckResultErrorInfo {
308
325
  kind: 'unknown-dataset' | 'unknown-input' | 'unknown-input-group' | 'empty-input-group';
@@ -318,7 +335,7 @@ interface CheckResult {
318
335
  errorInfo?: CheckResultErrorInfo;
319
336
  }
320
337
 
321
- declare type CheckDatasetError = 'no-matches-for-dataset' | 'no-matches-for-group' | 'no-matches-for-type';
338
+ type CheckDatasetError = 'no-matches-for-dataset' | 'no-matches-for-group' | 'no-matches-for-type';
322
339
  interface CheckDataset {
323
340
  /** The key for the matched dataset; can be undefined if no dataset matched. */
324
341
  datasetKey?: DatasetKey;
@@ -344,8 +361,8 @@ interface CheckScenarioInputDesc {
344
361
  value?: number;
345
362
  }
346
363
  interface CheckScenario {
347
- /** The scenario for the matched input(s); can be undefined if input(s) failed to match. */
348
- scenario?: Scenario;
364
+ /** The spec used to configure the model with the matched input(s); can be undefined if input(s) failed to match. */
365
+ spec?: ScenarioSpec;
349
366
  /** The name of the associated input group, if any. */
350
367
  inputGroupName?: string;
351
368
  /** The descriptions of the inputs; if empty, it is an "all inputs" scenario. */
@@ -355,9 +372,9 @@ interface CheckScenario {
355
372
  }
356
373
 
357
374
  /**
358
- * The key type for data references (in the form `<ScenarioKey::DatasetKey>`).
375
+ * The key type for data references (in the form `<ScenarioUid::DatasetKey>`).
359
376
  */
360
- declare type CheckDataRefKey = string;
377
+ type CheckDataRefKey = string;
361
378
  /**
362
379
  * The scenario and dataset referenced by a particular predicate (for cases
363
380
  * where the check is against another dataset rather than a constant value).
@@ -371,9 +388,9 @@ interface CheckDataRef {
371
388
  dataset: CheckDataset;
372
389
  }
373
390
 
374
- declare type CheckKey = number;
391
+ type CheckKey = number;
375
392
 
376
- declare type CheckStatus = 'passed' | 'failed' | 'error';
393
+ type CheckStatus = 'passed' | 'failed' | 'error';
377
394
  interface CheckPredicateOpConstantRef {
378
395
  kind: 'constant';
379
396
  value: number;
@@ -382,7 +399,7 @@ interface CheckPredicateOpDataRef {
382
399
  kind: 'data';
383
400
  dataRef: CheckDataRef;
384
401
  }
385
- declare type CheckPredicateOpRef = CheckPredicateOpConstantRef | CheckPredicateOpDataRef;
402
+ type CheckPredicateOpRef = CheckPredicateOpConstantRef | CheckPredicateOpDataRef;
386
403
  interface CheckPredicateReport {
387
404
  checkKey: CheckKey;
388
405
  result: CheckResult;
@@ -413,7 +430,7 @@ interface CheckGroupReport {
413
430
  interface CheckReport {
414
431
  groups: CheckGroupReport[];
415
432
  }
416
- declare type StyleFunc = (s: string) => string;
433
+ type StyleFunc = (s: string) => string;
417
434
  /**
418
435
  * Return a string representation of the given scenario.
419
436
  *
@@ -478,176 +495,456 @@ declare function checkSummaryFromReport(checkReport: CheckReport): CheckSummary;
478
495
  *
479
496
  * @param checkConfig The config used to reconstruct the check test structure.
480
497
  * @param checkSummary The simplified check summary.
481
- * @param simplifyScenarios If true, reduce the number of scenarios generated for a `matrix`.
482
498
  * @return The converted check report.
483
499
  */
484
- declare function checkReportFromSummary(checkConfig: CheckConfig, checkSummary: CheckSummary, simplifyScenarios: boolean): CheckReport | undefined;
500
+ declare function checkReportFromSummary(checkConfig: CheckConfig, checkSummary: CheckSummary): CheckReport | undefined;
485
501
 
502
+ type ComparisonScenarioId = string;
503
+ type ComparisonScenarioTitle = string;
504
+ type ComparisonScenarioSubtitle = string;
505
+ type ComparisonScenarioInputName = string;
506
+ type ComparisonScenarioInputPosition = 'default' | 'min' | 'max';
486
507
  /**
487
- * Describes a scenario/dataset comparison.
508
+ * Specifies an input that is set to a specific position (default / min / max).
488
509
  */
489
- interface CompareItem {
490
- /** The item title. */
491
- title: string;
492
- /** The item subtitle. */
493
- subtitle?: string;
494
- /** The scenario used for comparison. */
495
- scenario: Scenario;
496
- /** The key for the datasets being compared. */
497
- datasetKey: DatasetKey;
510
+ interface ComparisonScenarioInputAtPositionSpec {
511
+ kind: 'input-at-position';
512
+ /** The requested input name or alias. */
513
+ inputName: ComparisonScenarioInputName;
514
+ /** The requested position of the input. */
515
+ position: ComparisonScenarioInputPosition;
498
516
  }
499
517
  /**
500
- * The title and subtitle info for a group of comparisons.
518
+ * Specifies an input that is set to a specific number value.
501
519
  */
502
- interface CompareGroupInfo {
503
- /** The group title. */
504
- title: string;
505
- /** The group subtitle. */
506
- subtitle?: string;
507
- /** The related items (e.g. graphs or sliders) for the group. */
508
- relatedItems: RelatedItem[];
520
+ interface ComparisonScenarioInputAtValueSpec {
521
+ kind: 'input-at-value';
522
+ /** The requested input name or alias. */
523
+ inputName: ComparisonScenarioInputName;
524
+ /** The number value of the input. */
525
+ value: number;
509
526
  }
510
527
  /**
511
- * Describes a group of comparisons. The results can be grouped either
512
- * by dataset or by scenario.
528
+ * A single input setting for a scenario. An input can be set to a specific number value,
529
+ * or it can be set to a "position" (default / min / max).
513
530
  */
514
- interface CompareGroup {
515
- /** The group title/subtitle info. */
516
- info: CompareGroupInfo;
517
- /** The items in the group. */
518
- items: CompareItem[];
531
+ type ComparisonScenarioInputSpec = ComparisonScenarioInputAtPositionSpec | ComparisonScenarioInputAtValueSpec;
532
+ /**
533
+ * Specifies a single scenario that sets one or more inputs to a value/position.
534
+ */
535
+ interface ComparisonScenarioWithInputsSpec {
536
+ kind: 'scenario-with-inputs';
537
+ /** The unique identifier for the scenario. */
538
+ id?: ComparisonScenarioId;
539
+ /** The title of the scenario. */
540
+ title?: ComparisonScenarioTitle;
541
+ /** The subtitle of the scenario. */
542
+ subtitle?: ComparisonScenarioSubtitle;
543
+ /** The input settings for this scenario. */
544
+ inputs: ComparisonScenarioInputSpec[];
519
545
  }
520
-
521
546
  /**
522
- * The variable/source name info associated with a dataset.
547
+ * Specifies a single scenario that configures inputs differently for the two
548
+ * model instances.
523
549
  */
524
- interface DatasetInfo {
525
- /** The variable name. */
526
- varName: string;
527
- /** The new variable name, if it was renamed. */
528
- newVarName?: string;
529
- /** The source name. */
530
- sourceName?: string;
531
- /** The new source name, if it was renamed. */
532
- newSourceName?: string;
533
- /** The related items (e.g. graphs) for the dataset. */
534
- relatedItems: RelatedItem[];
550
+ interface ComparisonScenarioWithDistinctInputsSpec {
551
+ kind: 'scenario-with-distinct-inputs';
552
+ /** The unique identifier for the scenario. */
553
+ id?: ComparisonScenarioId;
554
+ /** The title of the scenario. */
555
+ title?: ComparisonScenarioTitle;
556
+ /** The subtitle of the scenario. */
557
+ subtitle?: ComparisonScenarioSubtitle;
558
+ /** The input settings for this scenario when run with the "left" model. */
559
+ inputsL: ComparisonScenarioInputSpec[];
560
+ /** The input settings for this scenario when run with the "right" model. */
561
+ inputsR: ComparisonScenarioInputSpec[];
562
+ }
563
+ /**
564
+ * Specifies a single scenario that sets all available inputs to position.
565
+ */
566
+ interface ComparisonScenarioWithAllInputsSpec {
567
+ kind: 'scenario-with-all-inputs';
568
+ /** The unique identifier for the scenario. */
569
+ id?: ComparisonScenarioId;
570
+ /** The title of the scenario. */
571
+ title?: ComparisonScenarioTitle;
572
+ /** The subtitle of the scenario. */
573
+ subtitle?: ComparisonScenarioSubtitle;
574
+ /** The position that will be used for all available inputs. */
575
+ position: ComparisonScenarioInputPosition;
576
+ }
577
+ /**
578
+ * Special preset that expands to many scenarios:
579
+ * - one scenario with all inputs at their default
580
+ * - two scenarios for each available input:
581
+ * - one scenario with the input at its minimum
582
+ * - one scenario with the input at its maximum
583
+ */
584
+ interface ComparisonScenarioPresetMatrixSpec {
585
+ kind: 'scenario-matrix';
586
+ }
587
+ /**
588
+ * A definition of input scenario(s). A scenario can set one input to a value/position, or it
589
+ * can set multiple inputs to particular values/positions.
590
+ */
591
+ type ComparisonScenarioSpec = ComparisonScenarioWithInputsSpec | ComparisonScenarioWithDistinctInputsSpec | ComparisonScenarioWithAllInputsSpec | ComparisonScenarioPresetMatrixSpec;
592
+ /** A reference to a scenario definition. */
593
+ interface ComparisonScenarioRefSpec {
594
+ kind: 'scenario-ref';
595
+ /** The ID of the scenario that is referenced. */
596
+ scenarioId: ComparisonScenarioId;
597
+ /** The optional title that is used instead of the referenced scenario's title. */
598
+ title?: ComparisonScenarioTitle;
599
+ /** The optional subtitle that is used instead of the referenced scenario's subtitle. */
600
+ subtitle?: ComparisonScenarioSubtitle;
601
+ }
602
+ type ComparisonScenarioGroupId = string;
603
+ type ComparisonScenarioGroupTitle = string;
604
+ /**
605
+ * A definition of a group of input scenarios. Multiple scenarios can be grouped together under a single name, and
606
+ * can later be referenced by group ID in a view definition.
607
+ */
608
+ interface ComparisonScenarioGroupSpec {
609
+ kind: 'scenario-group';
610
+ /** The unique identifier for the group. */
611
+ id?: ComparisonScenarioGroupId;
612
+ /** The title of the group. */
613
+ title: ComparisonScenarioGroupTitle;
614
+ /** The scenarios that are included in this group. */
615
+ scenarios: (ComparisonScenarioSpec | ComparisonScenarioRefSpec)[];
616
+ }
617
+ /** A reference to a scenario group definition. */
618
+ interface ComparisonScenarioGroupRefSpec {
619
+ kind: 'scenario-group-ref';
620
+ /** The ID of the scenario group that is referenced. */
621
+ groupId: ComparisonScenarioGroupId;
622
+ }
623
+ type ComparisonViewTitle = string;
624
+ type ComparisonViewSubtitle = string;
625
+ type ComparisonViewGraphId = string;
626
+ /**
627
+ * Specifies a list of graphs to be shown in a view.
628
+ */
629
+ interface ComparisonViewGraphsArraySpec {
630
+ kind: 'graphs-array';
631
+ /** The array of IDs for graphs to show. */
632
+ graphIds: ComparisonViewGraphId[];
633
+ }
634
+ /**
635
+ * Specifies a preset list of graphs to be shown in a view.
636
+ */
637
+ interface ComparisonViewGraphsPresetSpec {
638
+ kind: 'graphs-preset';
639
+ /** The preset (currently only "all" is supported, which shows all available graphs). */
640
+ preset: 'all';
641
+ }
642
+ /**
643
+ * Specifies a set of graphs to be shown in a view.
644
+ */
645
+ type ComparisonViewGraphsSpec = ComparisonViewGraphsArraySpec | ComparisonViewGraphsPresetSpec;
646
+ /**
647
+ * A definition of a view. A view presents a set of graphs for a single input scenario.
648
+ */
649
+ interface ComparisonViewSpec {
650
+ kind: 'view';
651
+ /** The title of the view. If undefined, the title will be inferred from the scenario. */
652
+ title?: ComparisonViewTitle;
653
+ /** The subtitle of the view. If undefined, the subtitle will be inferred from the scenario. */
654
+ subtitle?: ComparisonViewGroupTitle;
655
+ /** The scenario to be shown in the view. */
656
+ scenarioId: ComparisonScenarioId;
657
+ /** The graphs to be shown for each scenario view. */
658
+ graphs: ComparisonViewGraphsSpec;
659
+ }
660
+ type ComparisonViewGroupTitle = string;
661
+ /**
662
+ * Specifies a view group with an explicit array of view definitions.
663
+ */
664
+ interface ComparisonViewGroupWithViewsSpec {
665
+ kind: 'view-group-with-views';
666
+ /** The title of the group of views. */
667
+ title: ComparisonViewGroupTitle;
668
+ /** The views that are included in this group. */
669
+ views: ComparisonViewSpec[];
670
+ }
671
+ /**
672
+ * Specifies a view group by declaring the scenarios included in the group (one view per scenario), along
673
+ * with a set of graphs that will shown in each view.
674
+ */
675
+ interface ComparisonViewGroupWithScenariosSpec {
676
+ kind: 'view-group-with-scenarios';
677
+ /** The title of the group of views. */
678
+ title: ComparisonViewGroupTitle;
679
+ /** The scenarios to be included (one view will be created for each scenario). */
680
+ scenarios: (ComparisonScenarioRefSpec | ComparisonScenarioGroupRefSpec)[];
681
+ /** The graphs to be shown for each scenario view. */
682
+ graphs: ComparisonViewGraphsSpec;
535
683
  }
536
684
  /**
537
- * The human-readable title and subtitle for a scenario.
685
+ * A definition of a group of views. Multiple related views can be grouped together under a single title
686
+ * to make them easy to distinguish in a report.
538
687
  */
539
- interface ScenarioInfo {
688
+ type ComparisonViewGroupSpec = ComparisonViewGroupWithViewsSpec | ComparisonViewGroupWithScenariosSpec;
689
+ /**
690
+ * Contains the scenario and view definitions from one or more sources (JSON/YAML files or manually
691
+ * defined specs).
692
+ */
693
+ interface ComparisonSpecs {
694
+ /** The requested scenarios. */
695
+ scenarios: ComparisonScenarioSpec[];
696
+ /** The requested scenario groups. */
697
+ scenarioGroups: ComparisonScenarioGroupSpec[];
698
+ /** The requested view groups. */
699
+ viewGroups: ComparisonViewGroupSpec[];
700
+ }
701
+ /** A source of comparison scenario and specifications. */
702
+ interface ComparisonSpecsSource {
703
+ kind: 'yaml' | 'json';
704
+ /** The source filename, if known. */
705
+ filename?: string;
706
+ /** A string containing YAML or JSON content. */
707
+ content: string;
708
+ }
709
+
710
+ /** A resolved dataset that is being compared. */
711
+ interface ComparisonDataset {
712
+ kind: 'dataset';
713
+ /** The unique key for the dataset (i.e., output variable or static data). */
714
+ key: DatasetKey;
715
+ /**
716
+ * The resolved output variable from the "left" model that corresponds to this dataset,
717
+ * or undefined if the variable is not defined in the left model.
718
+ */
719
+ outputVarL?: OutputVar;
720
+ /**
721
+ * The resolved output variable from the "right" model that corresponds to this dataset,
722
+ * or undefined if the variable is not defined in the right model.
723
+ */
724
+ outputVarR?: OutputVar;
725
+ }
726
+ /** A unique key for a `ComparisonScenario`, generated internally for use by the library. */
727
+ type ComparisonScenarioKey = string & {
728
+ _brand?: 'ComparisonScenarioKey';
729
+ };
730
+ interface ComparisonResolverUnknownInputError {
731
+ kind: 'unknown-input';
732
+ }
733
+ interface ComparisonResolverInvalidValueError {
734
+ kind: 'invalid-value';
735
+ }
736
+ type ComparisonResolverError = ComparisonResolverUnknownInputError | ComparisonResolverInvalidValueError;
737
+ /** Describes the resolution state for a scenario input relative to a specific model. */
738
+ interface ComparisonScenarioInputState {
739
+ /** The matched input variable; can be undefined if no input matched. */
740
+ inputVar?: InputVar;
741
+ /** The position of the input, if this is a position scenario. */
742
+ position?: InputPosition;
743
+ /** The value of the input, for the given position or explicit value. */
744
+ value?: number;
745
+ /** The error info if the input could not be resolved. */
746
+ error?: ComparisonResolverError;
747
+ }
748
+ /** A scenario input that has been checked against both "left" and "right" model. */
749
+ interface ComparisonScenarioInput {
750
+ /** The requested name of the input. */
751
+ requestedName: string;
752
+ /** The resolved state of the input for the "left" model. */
753
+ stateL: ComparisonScenarioInputState;
754
+ /** The resolved state of the input for the "right" model. */
755
+ stateR: ComparisonScenarioInputState;
756
+ }
757
+ /** A configuration that sets model inputs to specific values. */
758
+ interface ComparisonScenarioInputSettings {
759
+ kind: 'input-settings';
760
+ /** The resolutions for the specified inputs in the scenario. */
761
+ inputs: ComparisonScenarioInput[];
762
+ }
763
+ /** A configuration that sets all inputs in the model to a certain position. */
764
+ interface ComparisonScenarioAllInputsSettings {
765
+ kind: 'all-inputs-settings';
766
+ /** The input position that will be applied to all available inputs. */
767
+ position: InputPosition;
768
+ }
769
+ /**
770
+ * The configuration for an input scenario, either a set of individual input settings, or one
771
+ * that sets all inputs in the model to a certain position.
772
+ */
773
+ type ComparisonScenarioSettings = ComparisonScenarioInputSettings | ComparisonScenarioAllInputsSettings;
774
+ /** A single resolved input scenario. */
775
+ interface ComparisonScenario {
776
+ kind: 'scenario';
777
+ /** The unique key for the scenario, generated internally for use by the library. */
778
+ key: ComparisonScenarioKey;
779
+ /** The unique user-defined identifier for the scenario. */
780
+ id?: ComparisonScenarioId;
540
781
  /** The scenario title. */
541
782
  title: string;
542
783
  /** The scenario subtitle. */
543
784
  subtitle?: string;
785
+ /** The resolved settings for the model inputs in this scenario. */
786
+ settings: ComparisonScenarioSettings;
787
+ /** The input scenario used to configure the "left" model, or undefined if data not available. */
788
+ specL?: ScenarioSpec;
789
+ /** The input scenario used to configure the "right" model, or undefined if data not available. */
790
+ specR?: ScenarioSpec;
791
+ }
792
+ /** An unresolved input scenario reference. */
793
+ interface ComparisonUnresolvedScenarioRef {
794
+ kind: 'unresolved-scenario-ref';
795
+ /** The ID of the referenced scenario that could not be resolved. */
796
+ scenarioId: ComparisonScenarioId;
797
+ }
798
+ /** A resolved group of input scenarios. */
799
+ interface ComparisonScenarioGroup {
800
+ kind: 'scenario-group';
801
+ /** The unique identifier for the group. */
802
+ id?: ComparisonScenarioGroupId;
803
+ /** The title of the group. */
804
+ title: ComparisonScenarioGroupTitle;
544
805
  /**
545
- * The position of the scenario when displayed in a row. Typically, 0 means
546
- * "left", 1 means "middle", and so on.
806
+ * The scenarios that are included in this group. This includes scenario that were successfully
807
+ * resolved as well as scenario references that could not be resolved.
547
808
  */
548
- position: number;
809
+ scenarios: (ComparisonScenario | ComparisonUnresolvedScenarioRef)[];
810
+ }
811
+ /** An unresolved scenario group reference. */
812
+ interface ComparisonUnresolvedScenarioGroupRef {
813
+ kind: 'unresolved-scenario-group-ref';
814
+ /** The ID of the referenced scenario group that could not be resolved. */
815
+ scenarioGroupId: ComparisonScenarioGroupId;
816
+ }
817
+ /** A resolved view definition. A view presents a set of graphs for a single input scenario. */
818
+ interface ComparisonView {
819
+ kind: 'view';
820
+ /** The title of the view. */
821
+ title: ComparisonViewTitle;
822
+ /** The subtitle of the view. */
823
+ subtitle?: ComparisonViewSubtitle;
824
+ /** The resolved scenario to be shown in the view. */
825
+ scenario: ComparisonScenario;
826
+ /** The graphs to be shown for each scenario view. */
827
+ graphs: 'all' | ComparisonViewGraphId[];
828
+ }
829
+ /** An unresolved view. */
830
+ interface ComparisonUnresolvedView {
831
+ kind: 'unresolved-view';
832
+ /** The requested title of the view, if provided. */
833
+ title?: ComparisonViewTitle;
834
+ /** The requested subtitle of the view, if provided. */
835
+ subtitle?: ComparisonViewSubtitle;
836
+ /** The ID of the referenced scenario that could not be resolved. */
837
+ scenarioId?: ComparisonScenarioId;
838
+ /** The ID of the referenced scenario group that could not be resolved. */
839
+ scenarioGroupId?: ComparisonScenarioGroupId;
840
+ }
841
+ /** A resolved group of compared scenario/graph views. */
842
+ interface ComparisonViewGroup {
843
+ kind: 'view-group';
844
+ /** The title of the group of views. */
845
+ title: ComparisonViewGroupTitle;
846
+ /** The array of resolved (and unresolved) views that are included in this group. */
847
+ views: (ComparisonView | ComparisonUnresolvedView)[];
549
848
  }
550
849
 
551
850
  /**
552
- * Provides access to the set of scenarios that are used when comparing the two models.
851
+ * Provides access to the set of dataset definitions (`ComparisonDataset` instances) that are used
852
+ * when comparing the two models.
553
853
  */
554
- interface CompareScenarios {
854
+ interface ComparisonDatasets {
555
855
  /**
556
- * Return an array containing all configured scenarios.
856
+ * Return all `ComparisonDataset` instances that are available for comparisons.
557
857
  */
558
- getScenarios(): Scenario[];
858
+ getAllDatasets(): IterableIterator<ComparisonDataset>;
559
859
  /**
560
- * Return the scenario for the given key.
860
+ * Return the dataset metadata for the given key.
561
861
  *
562
- * @param scenarioKey The key for the scenario.
862
+ * @param datasetKey The key for the dataset.
563
863
  */
564
- getScenario(scenarioKey: ScenarioKey): Scenario | undefined;
864
+ getDataset(datasetKey: DatasetKey): ComparisonDataset | undefined;
565
865
  /**
566
- * Return the group info for the given group key.
866
+ * Return the keys for the datasets that should be compared for the given scenario.
567
867
  *
568
- * @param groupKey The scenario group key.
868
+ * @param scenario The scenario definition.
569
869
  */
570
- getScenarioGroupInfo(groupKey: ScenarioGroupKey): CompareGroupInfo | undefined;
870
+ getDatasetKeysForScenario(scenario: ComparisonScenario): DatasetKey[];
871
+ }
872
+
873
+ interface ComparisonScenarios {
571
874
  /**
572
- * Return the title/subtitle info for the given scenario.
573
- *
574
- * Note that the given `groupKey` could be different than `scenario.groupKey`. This
575
- * will be the case for the "all inputs at default" item that is included in each
576
- * row in the detail view for reference purposes. The provided `groupKey` will be
577
- * used to customize the title and subtitle for that item (for example, it will show
578
- * the default value of the input associated with the row).
875
+ * Return all `ComparisonScenario` instances that are available for comparisons.
876
+ */
877
+ getAllScenarios(): IterableIterator<ComparisonScenario>;
878
+ /**
879
+ * Return the scenario definition for the given key.
579
880
  *
580
- * @param scenario The scenario to be displayed.
581
- * @param groupKey The key for the group in which the scenario will be displayed.
881
+ * @param key The key for the scenario.
582
882
  */
583
- getScenarioInfo(scenario: Scenario, groupKey: ScenarioGroupKey): ScenarioInfo | undefined;
883
+ getScenario(key: ComparisonScenarioKey): ComparisonScenario | undefined;
584
884
  }
585
- /**
586
- * Provides access to the set of datasets that are configured for comparison.
587
- */
588
- interface CompareDatasets {
589
- /** The mapping of renamed dataset keys. */
590
- renamedDatasetKeys?: Map<DatasetKey, DatasetKey>;
885
+
886
+ interface ComparisonDatasetOptions {
591
887
  /**
592
- * Return the keys for the datasets that should be compared for the given scenario.
593
- *
594
- * @param scenario The scenario.
888
+ * The mapping of renamed dataset keys (old or "left" name as the map key,
889
+ * new or "right" name as the value).
595
890
  */
596
- getDatasetKeysForScenario(scenario: Scenario): DatasetKey[];
891
+ renamedDatasetKeys?: Map<DatasetKey, DatasetKey>;
597
892
  /**
598
- * Return the dataset info for the given key.
893
+ * An optional function that allows for limiting the datasets that are compared
894
+ * for a given scenario. By default, all datasets are compared for a given
895
+ * scenario, but if a custom function is provided, it can return a subset of
896
+ * datasets (for example, to omit datasets that are not relevant).
599
897
  */
600
- getDatasetInfo(datasetKey: DatasetKey): DatasetInfo | undefined;
898
+ datasetKeysForScenario?: (allDatasetKeys: DatasetKey[], scenario: ComparisonScenario) => DatasetKey[];
601
899
  }
602
- interface CompareOptions {
900
+ interface ComparisonOptions {
901
+ /** The left-side ("baseline") bundle being compared. */
603
902
  baseline: NamedBundle;
903
+ /**
904
+ * The array of thresholds used to color differences, e.g., [1, 5, 10] will use
905
+ * buckets of 0%, 0-1%, 1-5%, 5-10%, and >10%.
906
+ */
604
907
  thresholds: number[];
605
- scenarios: CompareScenarios;
606
- datasets: CompareDatasets;
908
+ /**
909
+ * The requested comparison scenario and view specifications. These can be
910
+ * specified in YAML or JSON files, or using `Spec` objects.
911
+ */
912
+ specs: (ComparisonSpecs | ComparisonSpecsSource)[];
913
+ /** Optional configuration for the datasets that are compared for different scenarios. */
914
+ datasets?: ComparisonDatasetOptions;
607
915
  }
608
- interface CompareConfig {
916
+ interface ComparisonConfig {
917
+ /** The loaded left-side ("baseline") bundle being compared. */
609
918
  bundleL: LoadedBundle;
919
+ /** The loaded right-side ("current") bundle being compared. */
610
920
  bundleR: LoadedBundle;
921
+ /**
922
+ * The array of thresholds used to color differences, e.g., [1, 5, 10] will use
923
+ * buckets of 0%, 0-1%, 1-5%, 5-10%, and >10%.
924
+ */
611
925
  thresholds: number[];
612
- scenarios: CompareScenarios;
613
- datasets: CompareDatasets;
926
+ /** The set of resolved scenarios that will be compared. */
927
+ scenarios: ComparisonScenarios;
928
+ /** The set of resolved datasets that will be compared. */
929
+ datasets: ComparisonDatasets;
930
+ /** The set of resolved view groups. */
931
+ viewGroups: ComparisonViewGroup[];
614
932
  }
615
933
 
616
- declare type CompareDataRequestKey = string;
934
+ type ComparisonDataRequestKey = string;
617
935
  /**
618
936
  * Coordinates loading of data in parallel from two models.
619
937
  */
620
- declare class CompareDataCoordinator {
938
+ declare class ComparisonDataCoordinator {
621
939
  readonly bundleModelL: BundleModel;
622
940
  readonly bundleModelR: BundleModel;
623
941
  private readonly taskQueue;
624
942
  constructor(bundleModelL: BundleModel, bundleModelR: BundleModel);
625
- requestDatasetMaps(requestKey: CompareDataRequestKey, scenario: Scenario, datasetKeys: DatasetKey[], onResponse: (datasetMapL: DatasetMap, datasetMapR: DatasetMap) => void): void;
626
- requestGraphData(requestKey: CompareDataRequestKey, bundle: 'left' | 'right', scenario: Scenario, graphId: BundleGraphId, onResponse: (graphData: BundleGraphData) => void): void;
627
- cancelRequest(key: CompareDataRequestKey): void;
628
- }
629
-
630
- interface PerfReport {
631
- readonly minTime: number;
632
- readonly maxTime: number;
633
- readonly avgTime: number;
634
- readonly allTimes: number[];
635
- }
636
- declare class PerfStats {
637
- private readonly times;
638
- addRun(timeInMillis: number): void;
639
- toReport(): PerfReport;
640
- }
641
-
642
- interface CompareDatasetReport {
643
- scenarioKey: ScenarioKey;
644
- datasetKey: DatasetKey;
645
- diffReport: DiffReport;
646
- }
647
- interface CompareReport {
648
- datasetReports: CompareDatasetReport[];
649
- perfReportL: PerfReport;
650
- perfReportR: PerfReport;
943
+ private processDatasetRequest;
944
+ private processGraphDataRequest;
945
+ requestDatasetMaps(requestKey: ComparisonDataRequestKey, scenarioSpecL: ScenarioSpec, scenarioSpecR: ScenarioSpec, datasetKeys: DatasetKey[], onResponse: (datasetMapL?: DatasetMap, datasetMapR?: DatasetMap) => void): void;
946
+ requestGraphData(requestKey: ComparisonDataRequestKey, scenarioSpecL: ScenarioSpec, scenarioSpecR: ScenarioSpec, graphId: BundleGraphId, onResponse: (graphDataL?: BundleGraphData, graphDataR?: BundleGraphData) => void): void;
947
+ cancelRequest(key: ComparisonDataRequestKey): void;
651
948
  }
652
949
 
653
950
  interface DiffPoint {
@@ -655,7 +952,7 @@ interface DiffPoint {
655
952
  valueL: number;
656
953
  valueR: number;
657
954
  }
658
- declare type DiffValidity = 'neither' | 'left-only' | 'right-only' | 'both';
955
+ type DiffValidity = 'neither' | 'left-only' | 'right-only' | 'both';
659
956
  interface DiffReport {
660
957
  validity: DiffValidity;
661
958
  minValue: number;
@@ -666,43 +963,71 @@ interface DiffReport {
666
963
  maxDiffPoint: DiffPoint;
667
964
  }
668
965
  declare function diffDatasets(datasetL: Dataset | undefined, datasetR: Dataset | undefined): DiffReport;
669
- declare function compareDatasets(scenarioKey: ScenarioKey, datasetKey: DatasetKey, datasetMapL: DatasetMap, datasetMapR: DatasetMap): CompareDatasetReport;
966
+
967
+ interface PerfReport {
968
+ readonly minTime: number;
969
+ readonly maxTime: number;
970
+ readonly avgTime: number;
971
+ readonly allTimes: number[];
972
+ }
973
+ declare class PerfStats {
974
+ private readonly times;
975
+ addRun(timeInMillis: number): void;
976
+ toReport(): PerfReport;
977
+ }
670
978
 
671
979
  /**
672
- * A simplified/terse version of `CompareDatasetReport` that matches the
673
- * format of the JSON objects emitted by the CLI in terse mode.
674
- * The object keys are terse and it only includes the minimum set of fields
980
+ * The report for a single comparison test (involving a dataset produced under
981
+ * a specific input scenario). This includes the full `DiffReport`, whereas
982
+ * a `ComparisonTestSummary` only includes the `maxDiff` value.
983
+ */
984
+ interface ComparisonTestReport {
985
+ scenarioKey: ComparisonScenarioKey;
986
+ datasetKey: DatasetKey;
987
+ diffReport: DiffReport;
988
+ }
989
+ /**
990
+ * A simplified/terse version of `ComparisonTestReport` that is used when writing
991
+ * results to a JSON file. The object keys are terse and it only includes the
992
+ * minimum set of fields (only the `maxDiff` value instead of the full `DiffReport`)
675
993
  * to keep the file smaller when there are many reported differences.
676
994
  */
677
- interface CompareDatasetSummary {
995
+ interface ComparisonTestSummary {
678
996
  /** Short for `scenarioKey`. */
679
- s: ScenarioKey;
997
+ s: ComparisonScenarioKey;
680
998
  /** Short for `datasetKey`. */
681
999
  d: DatasetKey;
682
1000
  /** Short for `maxDiff`. */
683
1001
  md: number;
684
1002
  }
685
1003
  /**
686
- * A simplified/terse version of `CompareReport` that matches the
687
- * format of the JSON objects emitted by the CLI in terse mode.
1004
+ * The roll-up report that contains the results of all individual comparison tests.
688
1005
  */
689
- interface CompareSummary {
690
- datasetSummaries: CompareDatasetSummary[];
1006
+ interface ComparisonReport {
1007
+ /** The set of all comparison test reports. */
1008
+ testReports: ComparisonTestReport[];
1009
+ /** The perf report for the "left" model. */
691
1010
  perfReportL: PerfReport;
1011
+ /** The perf report for the "right" model. */
692
1012
  perfReportR: PerfReport;
693
1013
  }
694
1014
  /**
695
- * Convert a full `CompareReport` to a simplified `CompareSummary` that includes
696
- * the minimum set of fields needed to keep the file smaller when there are many
697
- * reported differences.
698
- *
699
- * @param compareReport The full compare report.
700
- * @return The converted compare summary.
1015
+ * A simplified/terse version of `ComparisonReport` that only includes the minimum set
1016
+ * of fields needed by the reporting app (to keep the file smaller when there are many
1017
+ * reported differences). This only includes comparison results for which there is
1018
+ * a non-zero `maxDiff` value.
701
1019
  */
702
- declare function compareSummaryFromReport(compareReport: CompareReport): CompareSummary;
1020
+ interface ComparisonSummary {
1021
+ /** The simplified set of all terse comparison test summaries. */
1022
+ testSummaries: ComparisonTestSummary[];
1023
+ /** The perf report for the "left" model. */
1024
+ perfReportL: PerfReport;
1025
+ /** The perf report for the "right" model. */
1026
+ perfReportR: PerfReport;
1027
+ }
703
1028
 
704
- declare type GraphInclusion = 'neither' | 'left-only' | 'right-only' | 'both';
705
- interface GraphMetadataReport {
1029
+ type GraphInclusion = 'neither' | 'left-only' | 'right-only' | 'both';
1030
+ interface GraphComparisonMetadataReport {
706
1031
  /** The key for the metadata field. */
707
1032
  key: string;
708
1033
  /** The value of the metadata field in the left bundle. */
@@ -710,146 +1035,180 @@ interface GraphMetadataReport {
710
1035
  /** The value of the metadata field in the right bundle. */
711
1036
  valueR?: string;
712
1037
  }
713
- interface GraphDatasetReport {
1038
+ interface GraphComparisonDatasetReport {
714
1039
  /** The dataset key. */
715
1040
  datasetKey: DatasetKey;
716
1041
  /** The max diff for this dataset. */
717
1042
  maxDiff?: number;
718
1043
  }
719
- interface GraphReport {
1044
+ interface GraphComparisonReport {
720
1045
  /** Indicates which bundles the graph is defined in. */
721
1046
  inclusion: GraphInclusion;
722
1047
  /** The metadata fields with differences. */
723
- metadataReports: GraphMetadataReport[];
1048
+ metadataReports: GraphComparisonMetadataReport[];
724
1049
  /** The datasets with differences. */
725
- datasetReports: GraphDatasetReport[];
1050
+ datasetReports: GraphComparisonDatasetReport[];
726
1051
  }
727
1052
  /**
728
- * Compare the metadata and datasets for the given graphs.
1053
+ * Comparison the metadata and datasets for the given graphs.
729
1054
  *
730
1055
  * @param graphL The graph defined in the left bundle.
731
1056
  * @param graphR The graph defined in the right bundle.
732
- * @param scenarioKey The scenario used for comparing datasets.
733
- * @param datasetSummaries The set of summaries from a previous comparison run.
1057
+ * @param scenarioKey The key of the scenario used for comparing datasets.
1058
+ * @param testSummaries The set of test summaries from a previous comparison run.
734
1059
  */
735
- declare function diffGraphs(graphL: BundleGraphSpec | undefined, graphR: BundleGraphSpec | undefined, scenarioKey: ScenarioKey, datasetSummaries: CompareDatasetSummary[]): GraphReport;
1060
+ declare function diffGraphs(graphL: BundleGraphSpec | undefined, graphR: BundleGraphSpec | undefined, scenarioKey: ComparisonScenarioKey, testSummaries: ComparisonTestSummary[]): GraphComparisonReport;
736
1061
 
737
- interface ConfigOptions {
1062
+ /**
1063
+ * Convert a full `ComparisonReport` to a simplified `ComparisonSummary` that includes
1064
+ * the minimum set of fields needed to keep the file smaller when there are many
1065
+ * reported differences. This only includes comparison results for which there
1066
+ * is a non-zero `maxDiff` value.
1067
+ *
1068
+ * @param comparisonReport The full comparison report.
1069
+ * @return The terse summary.
1070
+ */
1071
+ declare function comparisonSummaryFromReport(comparisonReport: ComparisonReport): ComparisonSummary;
1072
+
1073
+ type ComparisonGroupKind = 'by-dataset' | 'by-scenario';
1074
+ type ComparisonGroupKey = string;
1075
+ /**
1076
+ * A group of comparison test summaries associated with a particular scenario or dataset.
1077
+ */
1078
+ interface ComparisonGroup {
1079
+ /** The kind of group, either 'by-dataset' or 'by-scenario'. */
1080
+ kind: ComparisonGroupKind;
738
1081
  /**
739
- * The bundle being checked. This bundle will also be compared against the
740
- * "baseline" bundle, if `compare` is defined.
1082
+ * The unique key for this group (a `DatasetKey` if grouped by dataset, or a
1083
+ * `ComparisonScenarioKey` if grouped by scenario).
741
1084
  */
742
- current: NamedBundle;
1085
+ key: ComparisonGroupKey;
1086
+ /** The comparison test summaries for this group. */
1087
+ testSummaries: ComparisonTestSummary[];
1088
+ }
1089
+ /** Describes the "root" or primary item for a group of comparisons. */
1090
+ type ComparisonGroupRoot = ComparisonDataset | ComparisonScenario;
1091
+ /** A summary of scores for a group of comparisons. */
1092
+ interface ComparisonGroupScores {
1093
+ /** The total number of comparisons (sample size) for this group. */
1094
+ totalDiffCount: number;
1095
+ /** The sum of the `maxDiff` values for each threshold bucket. */
1096
+ totalMaxDiffByBucket: number[];
1097
+ /** The number of comparisons that fall into each threshold bucket. */
1098
+ diffCountByBucket: number[];
1099
+ /** The percentage of comparisons that fall into each threshold bucket. */
1100
+ diffPercentByBucket: number[];
1101
+ }
1102
+ /**
1103
+ * A summary of a group of comparisons that includes the resolved scenario/dataset metadata
1104
+ * and score information for the group.
1105
+ */
1106
+ interface ComparisonGroupSummary {
1107
+ /** The metadata for the "root" or primary item for this group of comparisons. */
1108
+ root: ComparisonGroupRoot;
1109
+ /** The group containing the comparison summaries. */
1110
+ group: ComparisonGroup;
1111
+ /** The scores for this group, or undefined if comparisons were not performed for this group. */
1112
+ scores?: ComparisonGroupScores;
1113
+ }
1114
+ /**
1115
+ * Breaks down a set of by-scenario or by-dataset groupings into distinct categories.
1116
+ */
1117
+ interface ComparisonGroupSummariesByCategory {
743
1118
  /**
744
- * The model check options.
1119
+ * All groups in a map, keyed by "group key" (either a dataset key or scenario key).
745
1120
  */
746
- check: CheckOptions;
1121
+ allGroupSummaries: Map<ComparisonGroupKey, ComparisonGroupSummary>;
747
1122
  /**
748
- * The model comparison options.
1123
+ * Groups with items that have errors (are not valid) for both "left" and "right" models.
1124
+ */
1125
+ withErrors: ComparisonGroupSummary[];
1126
+ /**
1127
+ * Groups with items that are only valid for the "left" model (for example, datasets that
1128
+ * were removed and no longer available in the "right" model).
1129
+ */
1130
+ onlyInLeft: ComparisonGroupSummary[];
1131
+ /**
1132
+ * Groups with items that are only valid for the "right" model (for example, scenarios
1133
+ * for inputs that were added in the "right" model).
1134
+ */
1135
+ onlyInRight: ComparisonGroupSummary[];
1136
+ /**
1137
+ * Groups with one or more comparisons that have non-zero `maxDiff` scores; the groups
1138
+ * will be sorted by `maxDiff`, with higher scores at the front of the array.
1139
+ */
1140
+ withDiffs: ComparisonGroupSummary[];
1141
+ /**
1142
+ * Groups where all comparisons have `maxDiff` scores of zero (no differences between
1143
+ * "left" and "right").
749
1144
  */
750
- compare?: CompareOptions;
1145
+ withoutDiffs: ComparisonGroupSummary[];
751
1146
  }
752
- interface Config {
753
- check: CheckConfig;
754
- compare?: CompareConfig;
1147
+ /**
1148
+ * Rolls up all by-scenario and by-dataset groupings.
1149
+ */
1150
+ interface ComparisonCategorizedResults {
1151
+ /** The full set of by-scenario groupings. */
1152
+ byScenario: ComparisonGroupSummariesByCategory;
1153
+ /** The full set of by-dataset groupings. */
1154
+ byDataset: ComparisonGroupSummariesByCategory;
755
1155
  }
756
1156
 
757
- declare function createConfig(options: ConfigOptions): Promise<Config>;
758
-
759
1157
  /**
760
- * Manages a set of dataset keys (corresponding to the available model outputs
761
- * in the given bundles) that can be used to compare two versions of the model.
1158
+ * Given a set of terse test summaries (which only includes summaries for tests with non-zero `maxDiff`
1159
+ * scores), restore the full set of summaries and then categorize them.
762
1160
  *
763
- * This class computes the union of the available dataset keys and handles
764
- * renames so that if any variables were renamed in the "right" bundle, the
765
- * old key will be used so that the variable can still be compared.
766
- *
767
- * This is intended to be a simple, general purpose way to create a set of
768
- * dataset keys, but every model is different, so you can replace this with
769
- * a different set of dataset keys that is better suited for the model you
770
- * are testing.
771
- */
772
- declare class DatasetManager implements CompareDatasets {
773
- private readonly bundleL;
774
- private readonly bundleR;
775
- readonly renamedDatasetKeys?: Map<DatasetKey, DatasetKey>;
776
- readonly allOutputVarKeys: DatasetKey[];
777
- readonly modelOutputVarKeys: DatasetKey[];
778
- /**
779
- * @param bundleL The "left" bundle being compared.
780
- * @param bundleR The "right" bundle being compared.
781
- * @param renamedDatasetKeys The mapping of renamed dataset keys.
782
- */
783
- constructor(bundleL: Bundle, bundleR: Bundle, renamedDatasetKeys?: Map<DatasetKey, DatasetKey>);
784
- getDatasetKeysForScenario(scenario: Scenario): DatasetKey[];
785
- getDatasetInfo(datasetKey: DatasetKey): DatasetInfo | undefined;
786
- }
1161
+ * @param comparisonConfig The comparison configuration.
1162
+ * @param terseSummaries The set of terse test summaries.
1163
+ */
1164
+ declare function categorizeComparisonTestSummaries(comparisonConfig: ComparisonConfig, terseSummaries: ComparisonTestSummary[]): ComparisonCategorizedResults;
787
1165
 
788
1166
  /**
789
- * Manages a set of scenarios (corresponding to the available model inputs
790
- * in the given bundles) that can be used to compare two versions of the model.
1167
+ * Additional options that are passed to `getConfigOptions`. These can be used to customize
1168
+ * the `ConfigOptions`, for example, if the `simplifyScenarios` flag is true, a reduced set
1169
+ * of tests can be provided in the `ConfigOptions` so that the tests run faster in a local
1170
+ * development situation.
791
1171
  */
792
- declare class ScenarioManager implements CompareScenarios {
793
- private readonly bundleL;
794
- private readonly bundleR;
795
- private readonly scenarios;
796
- private readonly scenarioInfo;
797
- private readonly defaultInfoForGroup;
798
- private readonly groupInfo;
1172
+ interface ConfigInitOptions {
1173
+ /** If defined, overrides the displayed name of the baseline ("left") bundle. */
1174
+ bundleNameL?: string;
1175
+ /** If defined, overrides the displayed name of the current ("right") bundle. */
1176
+ bundleNameR?: string;
799
1177
  /**
800
- * @param bundleL The "left" bundle being compared.
801
- * @param bundleR The "right" bundle being compared.
1178
+ * A hint that the user wants tests to run faster. If true, you can return a
1179
+ * configuration that runs a smaller subset of tests than normal.
802
1180
  */
803
- constructor(bundleL: Bundle, bundleR: Bundle);
804
- getScenarios(): Scenario[];
805
- getScenario(scenarioKey: ScenarioKey): Scenario | undefined;
806
- getScenarioGroupInfo(groupKey: ScenarioGroupKey): CompareGroupInfo | undefined;
807
- getScenarioInfo(scenario: Scenario, groupKey: ScenarioGroupKey): ScenarioInfo | undefined;
1181
+ simplifyScenarios?: boolean;
1182
+ }
1183
+ /**
1184
+ * The user-specified options used by the library to resolve and initialize a `Config` instance.
1185
+ */
1186
+ interface ConfigOptions {
808
1187
  /**
809
- * Override the title and subtitle that are displayed when the "all inputs at default"
810
- * scenario is included for a particular group. This can be used to customize the
811
- * text instead of showing the default message ("...at default").
812
- *
813
- * @param groupKey The scenario group key.
814
- * @param scenarioInfo The custom info to be displayed.
1188
+ * The bundle being checked. This bundle will also be compared against the
1189
+ * "baseline" bundle, if `comparison` options are defined.
815
1190
  */
816
- setDefaultScenarioInfoForGroup(groupKey: ScenarioGroupKey, scenarioInfo: ScenarioInfo): void;
1191
+ current: NamedBundle;
817
1192
  /**
818
- * Add a scenario to the set.
819
- *
820
- * @param scenario The scenario to be added.
821
- * @param scenarioInfo The custom title/subtitle for the scenario. If left undefined, the
822
- * default (possibly generic) info will be used.
823
- * @param groupInfo The custom title/subtitle for the group. If left undefined, the
824
- * default (possibly generic) info will be used.
1193
+ * The model check options.
825
1194
  */
826
- addScenario(scenario: Scenario, scenarioInfo?: ScenarioInfo, groupInfo?: CompareGroupInfo): void;
1195
+ check: CheckOptions;
827
1196
  /**
828
- * Adds a set of scenarios that can be used to compare the two versions of
829
- * the given model.
830
- *
831
- * This function computes a matrix of input scenarios using the input variables
832
- * advertised by the given bundles. It will generate scenarios such that for
833
- * any output variable, the model will be run:
834
- * - once with all inputs at their default
835
- * - once with all inputs at their minimum
836
- * - once with all inputs at their maximum
837
- * - twice for each input
838
- * - once with single input at its minimum
839
- * - once with single input at its maximum
840
- *
841
- * This is intended to be a simple, general purpose way to create a set of
842
- * scenarios, but every model is different, so you can replace this with a
843
- * function to generate a different set of scenarios that is better suited
844
- * for the model you are testing.
1197
+ * The model comparison options.
845
1198
  */
846
- addScenarioMatrix(): void;
847
- private getGroupInfoForScenario;
848
- private getInfoForScenario;
849
- private getInfoForPositionSetting;
850
- private getRelatedItemsForSettings;
851
- private getInputVarForSetting;
1199
+ comparison?: ComparisonOptions;
852
1200
  }
1201
+ /**
1202
+ * The resolved configuration for check and comparison tests.
1203
+ */
1204
+ interface Config {
1205
+ /** The resolved check test configuration. */
1206
+ check: CheckConfig;
1207
+ /** The resolved comparison test configuration. */
1208
+ comparison?: ComparisonConfig;
1209
+ }
1210
+
1211
+ declare function createConfig(options: ConfigOptions): Promise<Config>;
853
1212
 
854
1213
  declare class PerfRunner {
855
1214
  readonly bundleModelL: BundleModel;
@@ -862,12 +1221,26 @@ declare class PerfRunner {
862
1221
  start(): void;
863
1222
  }
864
1223
 
1224
+ /**
1225
+ * The report for a single run of the full check+comparison test suite.
1226
+ */
865
1227
  interface SuiteReport {
866
1228
  checkReport: CheckReport;
867
- compareReport?: CompareReport;
1229
+ comparisonReport?: ComparisonReport;
1230
+ }
1231
+ /**
1232
+ * A simplified/terse version of `SuiteReport` that is used when writing
1233
+ * results to a JSON file. The object keys are terse and it only includes
1234
+ * the minimum set of fields (e.g., only the `maxDiff` value instead of the
1235
+ * full `DiffReport` for each comparison test) to keep the file smaller
1236
+ * when there are many reported differences.
1237
+ */
1238
+ interface SuiteSummary {
1239
+ checkSummary: CheckSummary;
1240
+ comparisonSummary?: ComparisonSummary;
868
1241
  }
869
1242
 
870
- declare type CancelRunSuite = () => void;
1243
+ type CancelRunSuite = () => void;
871
1244
  interface RunSuiteCallbacks {
872
1245
  onProgress?: (pct: number) => void;
873
1246
  onComplete?: (suiteReport: SuiteReport) => void;
@@ -887,14 +1260,6 @@ interface RunSuiteOptions {
887
1260
  */
888
1261
  declare function runSuite(config: Config, callbacks: RunSuiteCallbacks, options?: RunSuiteOptions): CancelRunSuite;
889
1262
 
890
- /**
891
- * A simplified/terse version of `SuiteReport` that matches the
892
- * format of the JSON objects emitted by the CLI in terse mode.
893
- */
894
- interface SuiteSummary {
895
- checkSummary: CheckSummary;
896
- compareSummary?: CompareSummary;
897
- }
898
1263
  /**
899
1264
  * Convert a full `SuiteReport` to a simplified `SuiteSummary` that only includes
900
1265
  * failed/errored checks or comparisons with differences.
@@ -904,4 +1269,4 @@ interface SuiteSummary {
904
1269
  */
905
1270
  declare function suiteSummaryFromReport(suiteReport: SuiteReport): SuiteSummary;
906
1271
 
907
- export { AllInputsScenario, Bundle, BundleGraphData, BundleGraphDatasetSpec, BundleGraphId, BundleGraphSpec, BundleGraphView, BundleModel, CheckDataCoordinator, CheckDataRequestKey, CheckDatasetReport, CheckGroupReport, CheckKey, CheckPredicateOp, CheckPredicateOpConstantRef, CheckPredicateOpDataRef, CheckPredicateOpRef, CheckPredicateReport, CheckPredicateSummary, CheckPredicateTimeOptions, CheckPredicateTimeRange, CheckPredicateTimeSingle, CheckPredicateTimeSpec, CheckReport, CheckResult, CheckResultErrorInfo, CheckScenarioReport, CheckStatus, CheckSummary, CheckTestReport, CompareConfig, CompareDataCoordinator, CompareDataRequestKey, CompareDatasetReport, CompareDatasetSummary, CompareDatasets, CompareGroup, CompareGroupInfo, CompareItem, CompareOptions, CompareReport, CompareScenarios, CompareSummary, Config, ConfigOptions, DataSource, Dataset, DatasetInfo, DatasetKey, DatasetManager, DatasetMap, DatasetsResult, DiffPoint, DiffReport, DiffValidity, Dimension, GraphDatasetReport, GraphInclusion, GraphMetadataReport, GraphReport, ImplVar, InputPosition, InputSetting, InputVar, LegendItem, LinkItem, LoadedBundle, ModelSpec, NamedBundle, OutputVar, PerfReport, PerfRunner, PerfStats, PositionSetting, RelatedItem, RunSuiteCallbacks, RunSuiteOptions, Scenario, ScenarioGroupKey, ScenarioInfo, ScenarioKey, ScenarioManager, SettingsScenario, SourceName, Subscript, SuiteReport, SuiteSummary, ValueSetting, VarId, allInputsAtPositionScenario, checkReportFromSummary, checkSummaryFromReport, compareDatasets, compareSummaryFromReport, createConfig, datasetMessage, diffDatasets, diffGraphs, inputAtPositionScenario, inputAtValueScenario, matrixScenarios, positionSetting, predicateMessage, runSuite, scenarioMessage, settingsScenario, suiteSummaryFromReport, valueSetting };
1272
+ export { AllInputsSpec, Bundle, BundleGraphData, BundleGraphDatasetSpec, BundleGraphId, BundleGraphSpec, BundleGraphView, BundleModel, CheckDataCoordinator, CheckDataRequestKey, CheckDatasetReport, CheckGroupReport, CheckKey, CheckPredicateOp, CheckPredicateOpConstantRef, CheckPredicateOpDataRef, CheckPredicateOpRef, CheckPredicateReport, CheckPredicateSummary, CheckPredicateTimeOptions, CheckPredicateTimeRange, CheckPredicateTimeSingle, CheckPredicateTimeSpec, CheckReport, CheckResult, CheckResultErrorInfo, CheckScenario, CheckScenarioError, CheckScenarioInputDesc, CheckScenarioReport, CheckStatus, CheckSummary, CheckTestReport, ComparisonCategorizedResults, ComparisonConfig, ComparisonDataCoordinator, ComparisonDataRequestKey, ComparisonDataset, ComparisonDatasetOptions, ComparisonDatasets, ComparisonGroup, ComparisonGroupKey, ComparisonGroupKind, ComparisonGroupRoot, ComparisonGroupScores, ComparisonGroupSummariesByCategory, ComparisonGroupSummary, ComparisonOptions, ComparisonReport, ComparisonResolverError, ComparisonResolverInvalidValueError, ComparisonResolverUnknownInputError, ComparisonScenario, ComparisonScenarioAllInputsSettings, ComparisonScenarioGroup, ComparisonScenarioGroupId, ComparisonScenarioGroupRefSpec, ComparisonScenarioGroupSpec, ComparisonScenarioGroupTitle, ComparisonScenarioId, ComparisonScenarioInput, ComparisonScenarioInputAtPositionSpec, ComparisonScenarioInputAtValueSpec, ComparisonScenarioInputName, ComparisonScenarioInputPosition, ComparisonScenarioInputSettings, ComparisonScenarioInputSpec, ComparisonScenarioInputState, ComparisonScenarioKey, ComparisonScenarioPresetMatrixSpec, ComparisonScenarioRefSpec, ComparisonScenarioSettings, ComparisonScenarioSpec, ComparisonScenarioSubtitle, ComparisonScenarioTitle, ComparisonScenarioWithAllInputsSpec, ComparisonScenarioWithDistinctInputsSpec, ComparisonScenarioWithInputsSpec, ComparisonScenarios, ComparisonSpecs, ComparisonSpecsSource, ComparisonSummary, ComparisonTestReport, ComparisonTestSummary, ComparisonUnresolvedScenarioGroupRef, ComparisonUnresolvedScenarioRef, ComparisonUnresolvedView, ComparisonView, ComparisonViewGraphId, ComparisonViewGraphsArraySpec, ComparisonViewGraphsPresetSpec, ComparisonViewGraphsSpec, ComparisonViewGroup, ComparisonViewGroupSpec, ComparisonViewGroupTitle, ComparisonViewGroupWithScenariosSpec, ComparisonViewGroupWithViewsSpec, ComparisonViewSpec, ComparisonViewSubtitle, ComparisonViewTitle, Config, ConfigInitOptions, ConfigOptions, DataSource, Dataset, DatasetGroupName, DatasetKey, DatasetMap, DatasetsResult, DiffPoint, DiffReport, DiffValidity, Dimension, GraphComparisonDatasetReport, GraphComparisonMetadataReport, GraphComparisonReport, GraphInclusion, ImplVar, InputAliasName, InputGroupName, InputId, InputPosition, InputSetting, InputSettingsSpec, InputVar, LegendItem, LinkItem, LoadedBundle, ModelSpec, NamedBundle, OutputVar, PerfReport, PerfRunner, PerfStats, PositionSetting, RelatedItem, RunSuiteCallbacks, RunSuiteOptions, ScenarioSpec, ScenarioSpecUid, SourceName, Subscript, SuiteReport, SuiteSummary, ValueSetting, VarId, categorizeComparisonTestSummaries, checkReportFromSummary, checkSummaryFromReport, comparisonSummaryFromReport, createConfig, datasetMessage, diffDatasets, diffGraphs, predicateMessage, runSuite, scenarioMessage, suiteSummaryFromReport };