@ssg-coop/luic-calculator-core 1.3.0 → 1.4.1

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.
Files changed (93) hide show
  1. package/README.md +12 -2
  2. package/dist/api/domain.d.ts +5 -0
  3. package/dist/api/domain.js +5 -0
  4. package/dist/config/i18n/en.d.ts +19 -0
  5. package/dist/config/i18n/en.js +19 -0
  6. package/dist/config/i18n/fr.d.ts +19 -0
  7. package/dist/config/i18n/fr.js +19 -0
  8. package/dist/config/types.d.ts +2 -0
  9. package/dist/config/types.js +5 -0
  10. package/dist/generator/WorkbookGenerator.d.ts +4 -0
  11. package/dist/generator/WorkbookGenerator.js +69 -9
  12. package/dist/generator/builders/ChartDataSheetBuilder.d.ts +10 -0
  13. package/dist/generator/builders/ChartDataSheetBuilder.js +160 -7
  14. package/dist/generator/builders/ChartsSheetBuilder.js +103 -2
  15. package/dist/generator/builders/InputDataSheetBuilder.js +4 -3
  16. package/dist/generator/builders/ScenarioDetailsBuilder.d.ts +2 -0
  17. package/dist/generator/builders/ScenarioDetailsBuilder.js +4 -4
  18. package/dist/generator/builders/ScenarioSheetBuilder.d.ts +2 -0
  19. package/dist/generator/builders/ScenarioSheetBuilder.js +205 -25
  20. package/dist/generator/builders/SummarySheetBuilder.d.ts +3 -2
  21. package/dist/generator/builders/SummarySheetBuilder.js +109 -9
  22. package/dist/types/config.types.d.ts +9 -0
  23. package/dist/types/workbook.types.d.ts +52 -1
  24. package/package.json +1 -1
  25. package/dist/package.json +0 -31
  26. package/dist/src/config/appConfig.d.ts +0 -11
  27. package/dist/src/config/appConfig.js +0 -38
  28. package/dist/src/config/core/calculatorUtils.d.ts +0 -17
  29. package/dist/src/config/core/calculatorUtils.js +0 -212
  30. package/dist/src/config/core/genericUtils.d.ts +0 -10
  31. package/dist/src/config/core/genericUtils.js +0 -79
  32. package/dist/src/config/domain/buildings.d.ts +0 -14
  33. package/dist/src/config/domain/buildings.js +0 -282
  34. package/dist/src/config/domain/emissionFactors.d.ts +0 -2
  35. package/dist/src/config/domain/emissionFactors.js +0 -42
  36. package/dist/src/config/domain/energySources.d.ts +0 -18
  37. package/dist/src/config/domain/energySources.js +0 -370
  38. package/dist/src/config/domain/infrastructure.d.ts +0 -8
  39. package/dist/src/config/domain/infrastructure.js +0 -56
  40. package/dist/src/config/domain/neighbourhoodTypes.d.ts +0 -10
  41. package/dist/src/config/domain/neighbourhoodTypes.js +0 -366
  42. package/dist/src/config/domain/regions.d.ts +0 -8
  43. package/dist/src/config/domain/regions.js +0 -423
  44. package/dist/src/config/domain/services.d.ts +0 -8
  45. package/dist/src/config/domain/services.js +0 -48
  46. package/dist/src/config/domain/transportation.d.ts +0 -12
  47. package/dist/src/config/domain/transportation.js +0 -81
  48. package/dist/src/config/i18n/en.d.ts +0 -445
  49. package/dist/src/config/i18n/en.js +0 -488
  50. package/dist/src/config/i18n/fr.d.ts +0 -445
  51. package/dist/src/config/i18n/fr.js +0 -491
  52. package/dist/src/config/types.d.ts +0 -80
  53. package/dist/src/config/types.js +0 -5
  54. package/dist/src/generator/FormulaBuilder.d.ts +0 -58
  55. package/dist/src/generator/FormulaBuilder.js +0 -101
  56. package/dist/src/generator/WorkbookGenerator.d.ts +0 -7
  57. package/dist/src/generator/WorkbookGenerator.js +0 -77
  58. package/dist/src/generator/builders/AssumptionsBuilder.d.ts +0 -20
  59. package/dist/src/generator/builders/AssumptionsBuilder.js +0 -311
  60. package/dist/src/generator/builders/CalculationSheetBuilder.d.ts +0 -20
  61. package/dist/src/generator/builders/CalculationSheetBuilder.js +0 -149
  62. package/dist/src/generator/builders/EmissionFactorsSheetBuilder.d.ts +0 -7
  63. package/dist/src/generator/builders/EmissionFactorsSheetBuilder.js +0 -86
  64. package/dist/src/generator/builders/InputDataSheetBuilder.d.ts +0 -13
  65. package/dist/src/generator/builders/InputDataSheetBuilder.js +0 -114
  66. package/dist/src/generator/builders/ScenarioSheetBuilder.d.ts +0 -19
  67. package/dist/src/generator/builders/ScenarioSheetBuilder.js +0 -1067
  68. package/dist/src/generator/builders/SummarySheetBuilder.d.ts +0 -8
  69. package/dist/src/generator/builders/SummarySheetBuilder.js +0 -304
  70. package/dist/src/index.d.ts +0 -57
  71. package/dist/src/index.js +0 -103
  72. package/dist/src/theme/defaultTheme.d.ts +0 -2
  73. package/dist/src/theme/defaultTheme.js +0 -254
  74. package/dist/src/theme/index.d.ts +0 -2
  75. package/dist/src/theme/index.js +0 -2
  76. package/dist/src/theme/sunsetTheme.d.ts +0 -2
  77. package/dist/src/theme/sunsetTheme.js +0 -310
  78. package/dist/src/types/config.types.d.ts +0 -69
  79. package/dist/src/types/config.types.js +0 -1
  80. package/dist/src/types/scenario.types.d.ts +0 -63
  81. package/dist/src/types/scenario.types.js +0 -1
  82. package/dist/src/types/workbook.types.d.ts +0 -181
  83. package/dist/src/types/workbook.types.js +0 -1
  84. package/dist/src/utils/ReactivityUtils.d.ts +0 -7
  85. package/dist/src/utils/ReactivityUtils.js +0 -26
  86. package/dist/src/utils/cellAddressing.d.ts +0 -16
  87. package/dist/src/utils/cellAddressing.js +0 -35
  88. package/dist/src/utils/formatting.d.ts +0 -9
  89. package/dist/src/utils/formatting.js +0 -32
  90. package/dist/src/writers/JsonExporter.d.ts +0 -11
  91. package/dist/src/writers/JsonExporter.js +0 -14
  92. package/dist/types/blinktagtypes.d.ts +0 -167
  93. package/dist/types/blinktagtypes.js +0 -21
package/README.md CHANGED
@@ -144,7 +144,8 @@ import { Generator, Themes } from '@ssg-coop/luic-calculator-core';
144
144
  // Generate the workbook blueprint
145
145
  const spec = Generator.generateWorkbook(scenarios, {
146
146
  locale: 'en', // 'en' | 'fr'
147
- theme: Themes.sunsetTheme // optional; defaults to Themes.defaultTheme
147
+ theme: Themes.sunsetTheme, // optional; defaults to Themes.defaultTheme
148
+ outputMode: 'multi-year' // optional; defaults to 'single-year'
148
149
  });
149
150
 
150
151
  // Serialize to JSON for storage or transport
@@ -155,6 +156,15 @@ const raw = Generator.JsonExporter.serialize(spec, false); // compact
155
156
  const restored = Generator.JsonExporter.deserialize(json);
156
157
  ```
157
158
 
159
+ ### Output modes
160
+
161
+ `outputMode` selects the workbook layout. The scenario input is the same in both modes.
162
+
163
+ | Mode | Workbook |
164
+ |---|---|
165
+ | `'single-year'` (default) | The 1.3.0 workbook: one typical year per scenario, with a "Calc" sheet per scenario for the emission calculations. |
166
+ | `'multi-year'` | A "Details" sheet per scenario with a year-by-year forecast from the build-out year (`scenario.year`) to 2050, maintenance and cumulative totals on the Scenario and Summary sheets, and line charts. |
167
+
158
168
  ### Available themes
159
169
 
160
170
  | Export | Description |
@@ -202,7 +212,7 @@ Key types exported from the root entry point:
202
212
  |---|---|
203
213
  | `Scenario` | Root scenario object passed to `generateWorkbook` |
204
214
  | `WorkbookSpec` | Output blueprint of `generateWorkbook` |
205
- | `GeneratorConfig` | Config object for `generateWorkbook` (`locale`, `theme`) |
215
+ | `GeneratorConfig` | Config object for `generateWorkbook` (`locale`, `theme`, `outputMode`) |
206
216
  | `WorkbookTheme` | Full theme definition |
207
217
  | `EnergySource` | Energy source config object |
208
218
  | `NeighbourhoodType` | Neighbourhood type with defaults and references |
@@ -106,6 +106,11 @@ export declare const getInfrastructureTypeNamesIdsAsArray: () => {
106
106
  id: import("..").InfrastructureTypeId;
107
107
  name: string;
108
108
  }[];
109
+ /**
110
+ * Singular i18n key for each infrastructure `units` key, for intensity labels
111
+ * such as `$/stall/yr` (e.g. `InfrastructureUnitSingular['general.stalls']` → `'general.stall'`).
112
+ */
113
+ export { InfrastructureUnitSingular } from '../config/types';
109
114
  /** Sorted array of all transportation type objects. */
110
115
  export declare const getTransportationTypes: () => import("..").TransportationConfig[];
111
116
  /** Array of `{ id, name }` pairs for all transportation types. */
@@ -131,6 +131,11 @@ export const getServiceNamesIdsAsArray = () => servicesConfig().getServiceNamesI
131
131
  export const getInfrastructureTypes = () => infrastructureConfig().getInfrastructureTypesAsArray();
132
132
  /** Array of `{ id, name }` pairs for all infrastructure types. */
133
133
  export const getInfrastructureTypeNamesIdsAsArray = () => infrastructureConfig().getInfrastructureTypeNamesIdsAsArray();
134
+ /**
135
+ * Singular i18n key for each infrastructure `units` key, for intensity labels
136
+ * such as `$/stall/yr` (e.g. `InfrastructureUnitSingular['general.stalls']` → `'general.stall'`).
137
+ */
138
+ export { InfrastructureUnitSingular } from '../config/types';
134
139
  // ── Transportation ────────────────────────────────────────────────────────────
135
140
  /** Sorted array of all transportation type objects. */
136
141
  export const getTransportationTypes = () => transportationConfig().getTransAsArray();
@@ -99,7 +99,9 @@ declare const _default: {
99
99
  students: string;
100
100
  dwelling: string;
101
101
  dwellings: string;
102
+ meter: string;
102
103
  meters: string;
104
+ stall: string;
103
105
  stalls: string;
104
106
  referencesTitle: string;
105
107
  referencesNone: string;
@@ -116,6 +118,17 @@ declare const _default: {
116
118
  title: string;
117
119
  capital: string;
118
120
  maintenance: string;
121
+ unit: string;
122
+ annualAvg: string;
123
+ cumulativeTotal: string;
124
+ maintTotal: string;
125
+ propTaxTotal: string;
126
+ net: string;
127
+ netPropTaxes: string;
128
+ maintOnly: string;
129
+ netDevCharges: string;
130
+ capitalOnlyBuildOut: string;
131
+ grandTotal: string;
119
132
  vkt: string;
120
133
  akt: string;
121
134
  kt: string;
@@ -178,7 +191,11 @@ declare const _default: {
178
191
  totalDwellings: string;
179
192
  perDwelling: string;
180
193
  assumptionsRefs: string;
194
+ avgAnnualEnergyEmissions: string;
195
+ multiYearSummary: string;
181
196
  modules: {
197
+ category: string;
198
+ metric: string;
182
199
  scenario: string;
183
200
  buildings: string;
184
201
  buildingsRefs: string;
@@ -654,6 +671,8 @@ declare const _default: {
654
671
  emissionFactors: string;
655
672
  inputPrefix: string;
656
673
  calcSuffix: string;
674
+ scenarioDetails: string;
675
+ detailsSuffix: string;
657
676
  assumptions_buildings: string;
658
677
  assumptions_services: string;
659
678
  assumptions_infrastructure: string;
@@ -101,7 +101,9 @@ export default {
101
101
  students: `students`,
102
102
  dwelling: `dwelling`,
103
103
  dwellings: `dwellings`,
104
+ meter: `metre`,
104
105
  meters: `metres`,
106
+ stall: `stall`,
105
107
  stalls: `stalls`,
106
108
  referencesTitle: `References`,
107
109
  referencesNone: `No references listed`,
@@ -118,6 +120,17 @@ export default {
118
120
  title: `title`,
119
121
  capital: `Capital`,
120
122
  maintenance: `Maintenance`,
123
+ unit: `Unit`,
124
+ annualAvg: `Annual Average`,
125
+ cumulativeTotal: `Cumulative Total`,
126
+ maintTotal: `Maintenance total`,
127
+ propTaxTotal: `Property Taxes total`,
128
+ net: `Net`,
129
+ netPropTaxes: `Property taxes minus services and infrastructure`,
130
+ maintOnly: `maintenance only`,
131
+ netDevCharges: `Development charges minus services and infrastructure`,
132
+ capitalOnlyBuildOut: `capital only, build-out year`,
133
+ grandTotal: `Total`,
121
134
  vkt: `VKT`,
122
135
  akt: `AKT`,
123
136
  kt: `KT`,
@@ -221,7 +234,11 @@ export default {
221
234
  totalDwellings: `Total Dwellings`,
222
235
  perDwelling: `Per Dwelling`,
223
236
  assumptionsRefs: `Assumptions & References`,
237
+ avgAnnualEnergyEmissions: `Average Annual Energy & Emissions`,
238
+ multiYearSummary: `Multi-Year Summary`,
224
239
  modules: {
240
+ category: `Category`,
241
+ metric: `Metric`,
225
242
  scenario: `Scenario Info`,
226
243
  buildings: `Buildings`,
227
244
  buildingsRefs: `Buildings References`,
@@ -698,6 +715,8 @@ export default {
698
715
  emissionFactors: `Emission Factors`,
699
716
  inputPrefix: `Input_`,
700
717
  calcSuffix: ` Calc`,
718
+ scenarioDetails: `Scenario Details`,
719
+ detailsSuffix: ` Details`,
701
720
  assumptions_buildings: `Assumptions_Buildings`,
702
721
  assumptions_services: `Assumptions_Services`,
703
722
  assumptions_infrastructure: `Assumptions_Infrastructure`,
@@ -99,7 +99,9 @@ declare const _default: {
99
99
  students: string;
100
100
  dwelling: string;
101
101
  dwellings: string;
102
+ meter: string;
102
103
  meters: string;
104
+ stall: string;
103
105
  stalls: string;
104
106
  referencesTitle: string;
105
107
  referencesNone: string;
@@ -116,6 +118,17 @@ declare const _default: {
116
118
  title: string;
117
119
  capital: string;
118
120
  maintenance: string;
121
+ unit: string;
122
+ annualAvg: string;
123
+ cumulativeTotal: string;
124
+ maintTotal: string;
125
+ propTaxTotal: string;
126
+ net: string;
127
+ netPropTaxes: string;
128
+ maintOnly: string;
129
+ netDevCharges: string;
130
+ capitalOnlyBuildOut: string;
131
+ grandTotal: string;
119
132
  vkt: string;
120
133
  akt: string;
121
134
  kt: string;
@@ -178,7 +191,11 @@ declare const _default: {
178
191
  totalDwellings: string;
179
192
  perDwelling: string;
180
193
  assumptionsRefs: string;
194
+ avgAnnualEnergyEmissions: string;
195
+ multiYearSummary: string;
181
196
  modules: {
197
+ category: string;
198
+ metric: string;
182
199
  scenario: string;
183
200
  buildings: string;
184
201
  buildingsRefs: string;
@@ -654,6 +671,8 @@ declare const _default: {
654
671
  emissionFactors: string;
655
672
  inputPrefix: string;
656
673
  calcSuffix: string;
674
+ scenarioDetails: string;
675
+ detailsSuffix: string;
657
676
  assumptions_buildings: string;
658
677
  assumptions_services: string;
659
678
  assumptions_infrastructure: string;
@@ -101,7 +101,9 @@ export default {
101
101
  students: `élèves`,
102
102
  dwelling: `logement`,
103
103
  dwellings: `logements`,
104
+ meter: `mètre`,
104
105
  meters: `mètres`,
106
+ stall: `stationnement`,
105
107
  stalls: `stationnements`,
106
108
  referencesTitle: `Références`,
107
109
  referencesNone: `Aucune référence listée`,
@@ -118,6 +120,17 @@ export default {
118
120
  title: `titre`,
119
121
  capital: `Capital`,
120
122
  maintenance: `Maintenance`,
123
+ unit: `Unité`,
124
+ annualAvg: `Moyenne annuelle`,
125
+ cumulativeTotal: `Total cumulatif`,
126
+ maintTotal: `Total de maintenance`,
127
+ propTaxTotal: `Total des taxes foncières`,
128
+ net: `Net`,
129
+ netPropTaxes: `Taxes foncières moins services et infrastructures`,
130
+ maintOnly: `maintenance seulement`,
131
+ netDevCharges: `Frais de développement moins services et infrastructures`,
132
+ capitalOnlyBuildOut: `capital seulement, année de construction complète`,
133
+ grandTotal: `Total`,
121
134
  vkt: `KPV`,
122
135
  akt: `KPA`,
123
136
  kt: `KP`,
@@ -224,7 +237,11 @@ export default {
224
237
  totalDwellings: `Nombre total de logements`,
225
238
  perDwelling: `Par logement`,
226
239
  assumptionsRefs: `Hypothèses & Références`,
240
+ avgAnnualEnergyEmissions: `Énergie & émissions annuelles moyennes`,
241
+ multiYearSummary: `Résumé pluriannuel`,
227
242
  modules: {
243
+ category: `Catégorie`,
244
+ metric: `Indicateur`,
228
245
  scenario: `Information concernant le scénario`,
229
246
  buildings: `Bâtiments`,
230
247
  buildingsRefs: `Références des bâtiments`,
@@ -701,6 +718,8 @@ export default {
701
718
  emissionFactors: `Facteurs d'émission`,
702
719
  inputPrefix: `Entrée_`,
703
720
  calcSuffix: ` Calc`,
721
+ scenarioDetails: `Détails du scénario`,
722
+ detailsSuffix: ` Détails`,
704
723
  assumptions_buildings: `Hypothèses_Bâtiments`,
705
724
  assumptions_services: `Hypothèses_Services`,
706
725
  assumptions_infrastructure: `Hypothèses_Infrastructures`,
@@ -53,6 +53,8 @@ export declare enum InfrastructureUnit {
53
53
  Meters = "general.meters",
54
54
  Stalls = "general.stalls"
55
55
  }
56
+ /** Singular i18n key for each unit, for cost intensity labels such as `$/stall/yr`. */
57
+ export declare const InfrastructureUnitSingular: Record<InfrastructureUnit, string>;
56
58
  export interface InfrastructureType {
57
59
  id: string;
58
60
  name: string;
@@ -7,3 +7,8 @@ export var InfrastructureUnit;
7
7
  InfrastructureUnit["Meters"] = "general.meters";
8
8
  InfrastructureUnit["Stalls"] = "general.stalls";
9
9
  })(InfrastructureUnit || (InfrastructureUnit = {}));
10
+ /** Singular i18n key for each unit, for cost intensity labels such as `$/stall/yr`. */
11
+ export const InfrastructureUnitSingular = {
12
+ [InfrastructureUnit.Meters]: 'general.meter',
13
+ [InfrastructureUnit.Stalls]: 'general.stall',
14
+ };
@@ -17,6 +17,9 @@ import { GeneratorConfig } from '../types/config.types';
17
17
  * @param config - Optional generator configuration.
18
18
  * @param config.locale - Locale string for date/number formatting (default: `'en'`).
19
19
  * @param config.theme - `WorkbookTheme` for custom styling (default: `defaultTheme`).
20
+ * @param config.outputMode - `'single-year'` (default) produces the 1.3.0 workbook, with one Calc
21
+ * sheet per scenario. `'multi-year'` adds a Details sheet per scenario with a year-by-year forecast
22
+ * to 2050, maintenance and cumulative totals, and line charts.
20
23
  * @returns A `WorkbookSpec` describing all sheets, cells, formulas, and charts.
21
24
  *
22
25
  * @example
@@ -24,6 +27,7 @@ import { GeneratorConfig } from '../types/config.types';
24
27
  * import { generateWorkbook, JsonExporter, sunsetTheme } from '@ssg-coop/luic-calculator-core';
25
28
  *
26
29
  * const spec = generateWorkbook(scenarios, { locale: 'fr', theme: sunsetTheme });
30
+ * const multiYearSpec = generateWorkbook(scenarios, { outputMode: 'multi-year' });
27
31
  * const json = JsonExporter.serialize(spec);
28
32
  * ```
29
33
  */
@@ -1,10 +1,11 @@
1
1
  import { AssumptionsBuilder } from './builders/AssumptionsBuilder';
2
2
  import { ScenarioSheetBuilder } from './builders/ScenarioSheetBuilder';
3
+ import { ScenarioDetailsBuilder } from './builders/ScenarioDetailsBuilder';
4
+ import { CalculationSheetBuilder } from './builders/CalculationSheetBuilder';
3
5
  import { SummarySheetBuilder } from './builders/SummarySheetBuilder';
4
6
  import { ReactivityUtils } from '../utils/ReactivityUtils';
5
7
  import { InputDataSheetBuilder } from './builders/InputDataSheetBuilder';
6
8
  import { EmissionFactorsSheetBuilder } from './builders/EmissionFactorsSheetBuilder';
7
- import { CalculationSheetBuilder } from './builders/CalculationSheetBuilder';
8
9
  import { ChartDataSheetBuilder } from './builders/ChartDataSheetBuilder';
9
10
  import { ChartsSheetBuilder } from './builders/ChartsSheetBuilder';
10
11
  import { defaultTheme } from '../theme';
@@ -25,6 +26,9 @@ import packageJson from '../../package.json' with { type: 'json' };
25
26
  * @param config - Optional generator configuration.
26
27
  * @param config.locale - Locale string for date/number formatting (default: `'en'`).
27
28
  * @param config.theme - `WorkbookTheme` for custom styling (default: `defaultTheme`).
29
+ * @param config.outputMode - `'single-year'` (default) produces the 1.3.0 workbook, with one Calc
30
+ * sheet per scenario. `'multi-year'` adds a Details sheet per scenario with a year-by-year forecast
31
+ * to 2050, maintenance and cumulative totals, and line charts.
28
32
  * @returns A `WorkbookSpec` describing all sheets, cells, formulas, and charts.
29
33
  *
30
34
  * @example
@@ -32,6 +36,7 @@ import packageJson from '../../package.json' with { type: 'json' };
32
36
  * import { generateWorkbook, JsonExporter, sunsetTheme } from '@ssg-coop/luic-calculator-core';
33
37
  *
34
38
  * const spec = generateWorkbook(scenarios, { locale: 'fr', theme: sunsetTheme });
39
+ * const multiYearSpec = generateWorkbook(scenarios, { outputMode: 'multi-year' });
35
40
  * const json = JsonExporter.serialize(spec);
36
41
  * ```
37
42
  */
@@ -41,12 +46,15 @@ export function generateWorkbook(rawScenarios, config = {}) {
41
46
  // Ensure config is populated with defaults
42
47
  config.theme = config.theme || defaultTheme;
43
48
  config.locale = config.locale || 'en';
49
+ config.outputMode = config.outputMode || 'single-year';
50
+ const multiYear = config.outputMode === 'multi-year';
44
51
  const assumptionsBuilder = new AssumptionsBuilder(config);
45
52
  const inputBuilder = new InputDataSheetBuilder(config);
46
53
  const scenarioBuilder = new ScenarioSheetBuilder(config);
47
54
  const summaryBuilder = new SummarySheetBuilder(config);
48
- const emissionFactorsBuilder = new EmissionFactorsSheetBuilder(config);
55
+ const detailsBuilder = new ScenarioDetailsBuilder(config);
49
56
  const calcBuilder = new CalculationSheetBuilder(config);
57
+ const emissionFactorsBuilder = new EmissionFactorsSheetBuilder(config);
50
58
  const chartDataBuilder = new ChartDataSheetBuilder(config);
51
59
  const chartsBuilder = new ChartsSheetBuilder(config);
52
60
  // 1. Generate Assumptions Tables
@@ -55,35 +63,87 @@ export function generateWorkbook(rawScenarios, config = {}) {
55
63
  // 2. Generate Scenarios and Input Data sheets
56
64
  const scenarioSheets = [];
57
65
  const inputSheets = [];
66
+ const detailsSheets = [];
67
+ const allDetailsRefs = [];
68
+ const allScenarioOutputRefs = [];
58
69
  for (const scenario of scenarios) {
59
70
  // Build Input sheet first to get external references
60
71
  const inputResult = inputBuilder.build(scenario, assumptionsResult.tables);
61
72
  inputSheets.push(inputResult.sheet);
62
73
  // Build Scenario sheet, injecting input references
63
- const { sheet: scenarioSheet, calcContexts } = scenarioBuilder.build(scenario, assumptionsResult.tables, inputResult.refs);
74
+ const { sheet: scenarioSheet, calcContexts, scenarioOutputRefs } = scenarioBuilder.build(scenario, assumptionsResult.tables, inputResult.refs);
64
75
  scenarioSheets.push(scenarioSheet);
65
- // Build Calculation Sheet
66
- const { sheet: calcSheet } = calcBuilder.build(scenario.title, calcContexts, assumptionsResult.tables, scenarioSheet.name);
67
- scenarioSheets.push(calcSheet);
76
+ if (!multiYear) {
77
+ // Single-year (1.3.0): a Calc sheet right after each Scenario sheet holds the emission calculations
78
+ const { sheet: calcSheet } = calcBuilder.build(scenario.title, calcContexts, assumptionsResult.tables, scenarioSheet.name);
79
+ scenarioSheets.push(calcSheet);
80
+ continue;
81
+ }
82
+ // Build Details sheet (multi-year forecast)
83
+ const { sheet: detailsSheet, detailsRefs } = detailsBuilder.build(scenario, scenarioOutputRefs);
84
+ allDetailsRefs.push(detailsRefs);
85
+ allScenarioOutputRefs.push(scenarioOutputRefs);
86
+ detailsSheets.push(detailsSheet);
87
+ // Inject Details sheet back-references into Scenario sheet (replace placeholder formulas)
88
+ const escapedDetailsName = detailsSheet.name.replace(/'/g, "''");
89
+ for (const row of scenarioSheet.rows) {
90
+ if (!row.cells)
91
+ continue;
92
+ for (const cell of row.cells) {
93
+ if (!cell.formula?.startsWith('__DETAILS_'))
94
+ continue;
95
+ // Building gas placeholders: __DETAILS_AVG_<bKey>_<gas>__
96
+ const mBldg = cell.formula.match(/^__DETAILS_(AVG|CUM)_(\w+)_(co2|ch4|n2o)__$/);
97
+ if (mBldg) {
98
+ const [, type, bKey, gasLower] = mBldg;
99
+ const gas = gasLower.toUpperCase();
100
+ const gr = detailsRefs.buildingGasRows[bKey];
101
+ if (!gr)
102
+ continue;
103
+ const rowNum = type === 'AVG'
104
+ ? (gas === 'CO2' ? gr.co2AvgRow : gas === 'CH4' ? gr.ch4AvgRow : gr.n2oAvgRow)
105
+ : (gas === 'CO2' ? gr.co2CumRow : gas === 'CH4' ? gr.ch4CumRow : gr.n2oCumRow);
106
+ const col = type === 'AVG' ? detailsRefs.avgCol : detailsRefs.cumCol;
107
+ cell.formula = `='${escapedDetailsName}'!${col}${rowNum}`;
108
+ continue;
109
+ }
110
+ // Transport gas placeholders: __DETAILS_TPT_AVG_<tKey>_<gas>__
111
+ const mTpt = cell.formula.match(/^__DETAILS_TPT_(AVG|CUM)_(\w+)_(co2|ch4|n2o)__$/);
112
+ if (mTpt) {
113
+ const [, type, tKey, gasLower] = mTpt;
114
+ const gas = gasLower.toUpperCase();
115
+ const gr = detailsRefs.tptGasRows[tKey];
116
+ if (!gr)
117
+ continue;
118
+ const rowNum = type === 'AVG'
119
+ ? (gas === 'CO2' ? gr.co2AvgRow : gas === 'CH4' ? gr.ch4AvgRow : gr.n2oAvgRow)
120
+ : (gas === 'CO2' ? gr.co2CumRow : gas === 'CH4' ? gr.ch4CumRow : gr.n2oCumRow);
121
+ const col = type === 'AVG' ? detailsRefs.avgCol : detailsRefs.cumCol;
122
+ cell.formula = `='${escapedDetailsName}'!${col}${rowNum}`;
123
+ }
124
+ }
125
+ }
68
126
  }
69
127
  // 3. Generate Summary
70
128
  const scenarioOnlySheets = scenarioSheets.filter(s => s.sheetType === 'scenario');
71
- const { sheet: summarySheet, summaryRefs } = summaryBuilder.build(scenarios, scenarioOnlySheets);
129
+ const { sheet: summarySheet, summaryRefs } = summaryBuilder.build(scenarios, scenarioOnlySheets, allDetailsRefs, allScenarioOutputRefs);
72
130
  // 4. Generate Chart Data Sheet
73
131
  const chartDataSheet = chartDataBuilder.build(scenarios, summaryRefs);
74
132
  // 5. Generate Charts Sheet
75
133
  const chartsSheet = chartsBuilder.build(scenarios, chartDataSheet);
76
134
  // 6. Generate Emission Factors
77
135
  const emissionFactorsSheet = emissionFactorsBuilder.build();
78
- // Gather
136
+ // Gather. Multi-year puts the Charts tab right after the Summary; single-year keeps the 1.3.0 order.
79
137
  const sheets = [
80
138
  summarySheet,
139
+ ...(multiYear ? [chartsSheet] : []),
81
140
  ...scenarioSheets,
141
+ ...detailsSheets,
82
142
  ...inputSheets,
83
143
  ...assumptionsResult.sheets,
84
144
  emissionFactorsSheet,
85
145
  chartDataSheet,
86
- chartsSheet,
146
+ ...(multiYear ? [] : [chartsSheet]),
87
147
  ];
88
148
  return {
89
149
  metadata: {
@@ -1,6 +1,16 @@
1
1
  import { SheetSpec, SummaryRefs } from '../../types/workbook.types';
2
2
  import { Scenario } from '../../types/scenario.types';
3
3
  import { GeneratorConfig } from '../../types/config.types';
4
+ /**
5
+ * Year range of the multi-year line charts: from the earliest build-out year to the app's end year.
6
+ * Shared by ChartDataSheetBuilder (writes the rows) and ChartsSheetBuilder (reads the range),
7
+ * so both always agree on the block layout.
8
+ */
9
+ export declare const lineChartYearRange: (scenarios: Scenario[]) => {
10
+ firstYear: number;
11
+ endYear: number;
12
+ nYears: number;
13
+ };
4
14
  export declare class ChartDataSheetBuilder {
5
15
  private config;
6
16
  constructor(config: GeneratorConfig);
@@ -1,19 +1,29 @@
1
1
  import { getColumnLetter } from '../../utils/cellAddressing';
2
+ import appConfig from '../../config/appConfig';
2
3
  import useCalculatorUtils from '../../config/core/calculatorUtils';
3
4
  import neighbourhoodTypesConfigFn from '../../config/domain/neighbourhoodTypes';
5
+ /**
6
+ * Year range of the multi-year line charts: from the earliest build-out year to the app's end year.
7
+ * Shared by ChartDataSheetBuilder (writes the rows) and ChartsSheetBuilder (reads the range),
8
+ * so both always agree on the block layout.
9
+ */
10
+ export const lineChartYearRange = (scenarios) => {
11
+ const { startYear, endYear } = appConfig();
12
+ const earliest = scenarios.length > 0 ? Math.min(...scenarios.map(s => s.year)) : startYear;
13
+ const firstYear = Math.min(endYear, Math.max(startYear, earliest));
14
+ return { firstYear, endYear, nYears: endYear - firstYear + 1 };
15
+ };
4
16
  export class ChartDataSheetBuilder {
5
17
  config;
6
18
  constructor(config) {
7
19
  this.config = config;
8
20
  }
9
21
  build(scenarios, summaryRefs) {
22
+ const multiYear = this.config.outputMode === 'multi-year';
10
23
  const calc = useCalculatorUtils();
11
24
  const neighConfig = neighbourhoodTypesConfigFn();
12
25
  const rows = [];
13
26
  const N = scenarios.length;
14
- // Column in chart data sheet for scenario j (0-indexed): getColumnLetter(j+1) = B, C, D ...
15
- // Last scenario column letter:
16
- const lastDataCol = getColumnLetter(N);
17
27
  const summarySheetToken = 'i18n:worksheets.scenariosSummary';
18
28
  const SERIES = [
19
29
  {
@@ -173,20 +183,163 @@ export class ChartDataSheetBuilder {
173
183
  });
174
184
  });
175
185
  rows.push({ rowIndex: perHHHeaderRowIdx, cells: perHHHeaderCells });
176
- // Data row: pre-calculated per-dwelling static numbers
186
+ // Data row: per-dwelling values via formula references to the summary sheet
177
187
  const perHHDataCells = [
178
188
  { column: 'A', value: `${series.titleToken} i18n:scenario.perDwelling` },
179
189
  ];
180
190
  scenarios.forEach((scenario, j) => {
181
191
  const chartCol = getColumnLetter(j + 1);
182
- const totalHomes = neighConfig.totalHomesForNeighbourhood(scenario.buildings);
183
- const perHHValue = series.getPerHHValue(scenario, totalHomes);
184
- perHHDataCells.push({ column: chartCol, value: perHHValue });
192
+ if (!multiYear) {
193
+ // Single-year (1.3.0): pre-calculated per-dwelling number
194
+ const totalHomes = neighConfig.totalHomesForNeighbourhood(scenario.buildings);
195
+ perHHDataCells.push({ column: chartCol, value: series.getPerHHValue(scenario, totalHomes) });
196
+ return;
197
+ }
198
+ const summaryCol = getColumnLetter(j + 2);
199
+ perHHDataCells.push({
200
+ column: chartCol,
201
+ formula: `='${summarySheetToken}'!${summaryCol}${metricRows.perHHRow}`,
202
+ });
185
203
  });
186
204
  rows.push({ rowIndex: perHHDataRowIdx, cells: perHHDataCells });
187
205
  // Empty separator row
188
206
  rows.push({ rowIndex: perHHEmptyRowIdx, cells: [] });
189
207
  });
208
+ // ── Line chart data blocks (9 cumulative metrics, earliest build-out year–endYear) ─────
209
+ // Layout per metric block:
210
+ // header row: A="Year", B..N = scenario name formulas
211
+ // N_years rows: A=year, B..N = running cumulative from build-out year to Y
212
+ // separator row: empty
213
+ // 12 series × 2 groups × 3 rows = 72 bar rows; line data starts at row 73.
214
+ //
215
+ // Two data-source strategies:
216
+ // 'details' – SUM of per-year rows in Details sheet (energy, emissions: values
217
+ // vary year-to-year due to changing emission factors)
218
+ // 'summary' – annual total from Summary sheet × years elapsed (constant-annual
219
+ // metrics: serviceOM, infOM, taxes, puv, transit, bike, walk)
220
+ const { firstYear, endYear, nYears: N_years } = lineChartYearRange(scenarios);
221
+ const LINE_START_ROW = 12 * 2 * 3 + 1; // 73
222
+ const LINE_SERIES = [
223
+ {
224
+ seriesKey: 'energy',
225
+ titleToken: 'i18n:scenario.energyUse',
226
+ dataSource: 'details',
227
+ getDetailRows: (refs) => refs.detailsEnergyTotalRows,
228
+ },
229
+ {
230
+ seriesKey: 'emissions',
231
+ titleToken: 'i18n:scenario.emissions',
232
+ dataSource: 'details',
233
+ getDetailRows: (refs) => refs.detailsEmissionsTotalRows,
234
+ },
235
+ {
236
+ seriesKey: 'serviceOMCost',
237
+ titleToken: 'i18n:scenario.modules.servicesOMCost',
238
+ dataSource: 'summary',
239
+ getMetricRow: (refs) => refs.metrics.serviceOMCost.totalRow,
240
+ },
241
+ {
242
+ seriesKey: 'infOMCost',
243
+ titleToken: 'i18n:scenario.modules.infrastructureOMCost',
244
+ dataSource: 'summary',
245
+ getMetricRow: (refs) => refs.metrics.infOMCost.totalRow,
246
+ },
247
+ {
248
+ seriesKey: 'taxes',
249
+ titleToken: 'i18n:appConfig.revenue.revenueTypes.municipalRevTaxes',
250
+ dataSource: 'summary',
251
+ getMetricRow: (refs) => refs.metrics.taxes.totalRow,
252
+ },
253
+ {
254
+ seriesKey: 'puv',
255
+ titleToken: 'i18n:forms.fields.puvVKT',
256
+ dataSource: 'summary',
257
+ getMetricRow: (refs) => refs.metrics.puv.totalRow,
258
+ },
259
+ {
260
+ seriesKey: 'transit',
261
+ titleToken: 'i18n:forms.fields.transitVKT',
262
+ dataSource: 'summary',
263
+ getMetricRow: (refs) => refs.metrics.transit.totalRow,
264
+ },
265
+ {
266
+ seriesKey: 'bike',
267
+ titleToken: 'i18n:forms.fields.bikeKT',
268
+ dataSource: 'summary',
269
+ getMetricRow: (refs) => refs.metrics.bike.totalRow,
270
+ },
271
+ {
272
+ seriesKey: 'walk',
273
+ titleToken: 'i18n:forms.fields.walkKT',
274
+ dataSource: 'summary',
275
+ getMetricRow: (refs) => refs.metrics.walk.totalRow,
276
+ },
277
+ ];
278
+ // Line chart data exists only in multi-year mode
279
+ if (multiYear)
280
+ LINE_SERIES.forEach((series, ls) => {
281
+ // Each block: 1 title + 1 header + N_years data rows + 1 separator = N_years + 3 rows
282
+ const blockStart = LINE_START_ROW + ls * (N_years + 3);
283
+ const titleRow = blockStart;
284
+ const headerRow = blockStart + 1;
285
+ const separatorRow = blockStart + N_years + 2;
286
+ // Title row: A = series title, other columns empty
287
+ rows.push({ rowIndex: titleRow, cells: [{ column: 'A', value: series.titleToken }] });
288
+ // Header row: A="Year", B..N = scenario names from summary sheet
289
+ const headerCells = [{ column: 'A', value: 'i18n:general.year' }];
290
+ scenarios.forEach((_scenario, j) => {
291
+ const chartCol = getColumnLetter(j + 1);
292
+ const summaryCol = getColumnLetter(j + 2);
293
+ headerCells.push({
294
+ column: chartCol,
295
+ formula: `='${summarySheetToken}'!${summaryCol}${summaryRefs.scenarioNamesRow}`,
296
+ });
297
+ });
298
+ rows.push({ rowIndex: headerRow, cells: headerCells });
299
+ // Year data rows: running cumulative from build-out year to Y
300
+ for (let y = firstYear; y <= endYear; y++) {
301
+ const dataRowIdx = headerRow + 1 + (y - firstYear);
302
+ const dataCells = [
303
+ { column: 'A', value: y, format: { numberFormat: '0' } },
304
+ ];
305
+ scenarios.forEach((scenario, j) => {
306
+ const chartCol = getColumnLetter(j + 1);
307
+ if (y < scenario.year) {
308
+ // Before build-out year: blank (creates gap in line chart)
309
+ dataCells.push({ column: chartCol, value: null });
310
+ return;
311
+ }
312
+ const elapsed = y - scenario.year + 1; // years from build-out through Y
313
+ if (series.dataSource === 'details') {
314
+ // True running SUM of per-year Detail rows (handles year-varying values)
315
+ const detailRow = series.getDetailRows(summaryRefs)[j];
316
+ if (detailRow === undefined) {
317
+ dataCells.push({ column: chartCol, value: null });
318
+ return;
319
+ }
320
+ const firstYearCol = getColumnLetter(3); // D = build-out year
321
+ const thisYearCol = getColumnLetter(3 + (y - scenario.year));
322
+ const escapedSheet = summaryRefs.detailsSheetNames[j].replace(/'/g, "''");
323
+ dataCells.push({
324
+ column: chartCol,
325
+ formula: `=SUM('${escapedSheet}'!${firstYearCol}${detailRow}:${thisYearCol}${detailRow})`,
326
+ });
327
+ }
328
+ else {
329
+ // Constant annual value × elapsed years (summary-sourced metrics)
330
+ const metricRow = series.getMetricRow(summaryRefs);
331
+ const summaryCol = getColumnLetter(j + 2);
332
+ dataCells.push({
333
+ column: chartCol,
334
+ formula: `='${summarySheetToken}'!${summaryCol}${metricRow}*${elapsed}`,
335
+ });
336
+ }
337
+ });
338
+ rows.push({ rowIndex: dataRowIdx, cells: dataCells });
339
+ }
340
+ // Separator
341
+ rows.push({ rowIndex: separatorRow, cells: [] });
342
+ });
190
343
  return {
191
344
  name: 'i18n:worksheets.chartData',
192
345
  sheetType: 'chartData',