@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
@@ -1,10 +1,11 @@
1
- import { SheetSpec, SummaryRefs } from '../../types/workbook.types';
1
+ import { SheetSpec, SummaryRefs, DetailsRefs } from '../../types/workbook.types';
2
+ import { ScenarioOutputRefs } from './ScenarioDetailsBuilder';
2
3
  import { Scenario } from '../../types/scenario.types';
3
4
  import { GeneratorConfig } from '../../types/config.types';
4
5
  export declare class SummarySheetBuilder {
5
6
  private config;
6
7
  constructor(config: GeneratorConfig);
7
- build(scenarios: Scenario[], scenarioSheets: SheetSpec[]): {
8
+ build(scenarios: Scenario[], scenarioSheets: SheetSpec[], detailsRefs?: DetailsRefs[], scenarioOutputRefs?: ScenarioOutputRefs[]): {
8
9
  sheet: SheetSpec;
9
10
  summaryRefs: SummaryRefs;
10
11
  };
@@ -1,13 +1,16 @@
1
1
  import { getColumnLetter } from '../../utils/cellAddressing';
2
2
  import { ktUnitToken } from '../../utils/transportationUnits';
3
+ import en from '../../config/i18n/en';
4
+ import fr from '../../config/i18n/fr';
3
5
  export class SummarySheetBuilder {
4
6
  config;
5
7
  constructor(config) {
6
8
  this.config = config;
7
9
  }
8
- build(scenarios, scenarioSheets) {
10
+ build(scenarios, scenarioSheets, detailsRefs = [], scenarioOutputRefs = []) {
9
11
  const rows = [];
10
12
  let currentRow = 1;
13
+ const multiYear = this.config.outputMode === 'multi-year';
11
14
  const c = this.config.theme.summary;
12
15
  // 1. Title
13
16
  rows.push({
@@ -41,7 +44,7 @@ export class SummarySheetBuilder {
41
44
  const idx = sheet.rows.findIndex(r => r.cells.some(c => c.column === 'B' && c.value === label));
42
45
  if (idx !== -1 && idx + 1 < sheet.rows.length)
43
46
  return `=${getRef(sIdx, 'D', sheet.rows[idx + 1].rowIndex)}`;
44
- return '0';
47
+ return multiYear ? 0 : '0';
45
48
  };
46
49
  const getTransportVktRef = (sIdx, label, isTotal) => {
47
50
  const sheet = scenarioSheets[sIdx];
@@ -111,6 +114,7 @@ export class SummarySheetBuilder {
111
114
  });
112
115
  rows.push({ rowIndex: currentRow++, cells: provRow });
113
116
  // Row 8: Build Out Year — build-out year per scenario
117
+ const evalPeriodRowIndex = currentRow;
114
118
  const evalDataCells = [
115
119
  {
116
120
  column: 'B',
@@ -204,6 +208,19 @@ export class SummarySheetBuilder {
204
208
  rowIndex: currentRow++,
205
209
  cells: createDataRow(null, 'i18n:general.maintenance (i18n:general.total/i18n:general.yearAbbr)', c.headers.services, c.data.services, i => getTotalsSumFormula(i, srvSearchLabel, 'B', 'i18n:general.total', 'D'), '$#,##0')
206
210
  });
211
+ /** Label formula "<label> (<prefix><earliest build-out year>–2050)", read from the Year of Full Build-out row. */
212
+ const periodLabel = (label, prefix = '') => `="${label} (${prefix}" & TEXT(MIN(${getColumnLetter(2)}${evalPeriodRowIndex}:XFD${evalPeriodRowIndex}),"0") & "\u20132050)"`;
213
+ const srvOMCumTotalRow = multiYear ? currentRow : -1;
214
+ if (multiYear)
215
+ rows.push({
216
+ rowIndex: currentRow++,
217
+ cells: createDataRow(null, periodLabel('i18n:general.maintTotal'), c.headers.services, c.data.services, i => {
218
+ const r = scenarioOutputRefs[i];
219
+ if (!r || r.srvOMTotalRow < 0)
220
+ return '0';
221
+ return `='${r.sheetName.replace(/'/g, "''")}'!$E$${r.srvOMTotalRow}`;
222
+ }, '$#,##0')
223
+ });
207
224
  // 3. Infrastructure Cost Section
208
225
  const infSearchLabel = 'i18n:scenario.modules.infrastructure';
209
226
  const infDisplayLabel = 'i18n:scenario.modules.infrastructureCost';
@@ -235,6 +252,17 @@ export class SummarySheetBuilder {
235
252
  rowIndex: currentRow++,
236
253
  cells: createDataRow(null, 'i18n:general.maintenance (i18n:general.total/i18n:general.yearAbbr)', c.headers.infrastructure, c.data.infrastructure, i => getTotalsSumFormula(i, infSearchLabel, 'B', 'i18n:general.total', 'D'), '$#,##0')
237
254
  });
255
+ const infOMCumTotalRow = multiYear ? currentRow : -1;
256
+ if (multiYear)
257
+ rows.push({
258
+ rowIndex: currentRow++,
259
+ cells: createDataRow(null, periodLabel('i18n:general.maintTotal'), c.headers.infrastructure, c.data.infrastructure, i => {
260
+ const r = scenarioOutputRefs[i];
261
+ if (!r || r.infOMTotalRow < 0)
262
+ return '0';
263
+ return `='${r.sheetName.replace(/'/g, "''")}'!$E$${r.infOMTotalRow}`;
264
+ }, '$#,##0')
265
+ });
238
266
  // 4. Transportation Section
239
267
  const tptLabels = {
240
268
  puv: 'i18n:appConfig.transportation.transportationTypes.puv',
@@ -289,10 +317,37 @@ export class SummarySheetBuilder {
289
317
  const taxesTotalRow = currentRow;
290
318
  rows.push({
291
319
  rowIndex: currentRow++,
292
- // Property taxes (total) is uncolored in original (has `{}` in rowFormat position). Preserving layout.
293
- cells: createDataRow(null, 'i18n:appConfig.revenue.revenueTypes.propertyTaxes (i18n:general.total/i18n:general.yearAbbr)', c.headers.revenue, {}, i => getTotalsSumFormula(i, revLabel, 'C', 'i18n:appConfig.revenue.revenueTypes.propertyTaxes', 'D'), '$#,##0')
320
+ cells: createDataRow(null, 'i18n:appConfig.revenue.revenueTypes.propertyTaxes (i18n:general.total/i18n:general.yearAbbr)', c.headers.revenue, multiYear ? c.data.revenue : {}, i => getTotalsSumFormula(i, revLabel, 'C', 'i18n:appConfig.revenue.revenueTypes.propertyTaxes', 'D'), '$#,##0')
294
321
  });
295
- // 6. Energy Use Section
322
+ const propTaxCumTotalRow = multiYear ? currentRow : -1;
323
+ if (multiYear)
324
+ rows.push({
325
+ rowIndex: currentRow++,
326
+ cells: createDataRow(null, periodLabel('i18n:general.propTaxTotal'), c.headers.revenue, c.data.revenue, i => {
327
+ const r = scenarioOutputRefs[i];
328
+ if (!r || r.propTaxTotalRow < 0)
329
+ return '0';
330
+ return `='${r.sheetName.replace(/'/g, "''")}'!$E$${r.propTaxTotalRow}`;
331
+ }, '$#,##0')
332
+ });
333
+ // Net: revenue minus the services and infrastructure costs it pays for (multi-year only)
334
+ if (multiYear) {
335
+ rows.push({
336
+ rowIndex: currentRow++,
337
+ cells: createDataRow('i18n:general.net', periodLabel('i18n:general.netPropTaxes', 'i18n:general.maintOnly, '), c.headers.revenue, c.data.revenue, i => {
338
+ const col = getColumnLetter(i + 2);
339
+ return `=${col}${propTaxCumTotalRow}-${col}${srvOMCumTotalRow}-${col}${infOMCumTotalRow}`;
340
+ }, '$#,##0')
341
+ });
342
+ rows.push({
343
+ rowIndex: currentRow++,
344
+ cells: createDataRow(null, 'i18n:general.netDevCharges (i18n:general.capitalOnlyBuildOut)', c.headers.revenue, c.data.revenue, i => {
345
+ const col = getColumnLetter(i + 2);
346
+ return `=${col}${devChrgTotalRow}-${col}${srvCapCostTotalRow}-${col}${infCapCostTotalRow}`;
347
+ }, '$#,##0')
348
+ });
349
+ }
350
+ // 6. Energy Use Section — references Details sheet annual averages and cumulative totals
296
351
  const energyTotalRowIdx = currentRow + 1;
297
352
  const energyPerHHRow = currentRow;
298
353
  rows.push({
@@ -305,9 +360,24 @@ export class SummarySheetBuilder {
305
360
  const energyTotalRow = currentRow;
306
361
  rows.push({
307
362
  rowIndex: currentRow++,
308
- cells: createDataRow(null, 'i18n:general.total GJ/i18n:general.yearLower', c.headers.energy, c.data.energy, i => getSumAllFormula(i, 'C', 'i18n:scenario.energyUse', 'D'), '#,##0.00')
363
+ cells: createDataRow(null, 'i18n:general.total GJ/i18n:general.yearLower', c.headers.energy, c.data.energy, i => {
364
+ const d = detailsRefs[i];
365
+ if (!d)
366
+ return getSumAllFormula(i, 'C', 'i18n:scenario.energyUse', 'D');
367
+ return `='${d.sheetName.replace(/'/g, "''")}'!${d.avgCol}${d.energyTotalAvgRow}`;
368
+ }, '#,##0.00')
309
369
  });
310
- // 7. Emissions Section
370
+ if (multiYear)
371
+ rows.push({
372
+ rowIndex: currentRow++,
373
+ cells: createDataRow(null, periodLabel('i18n:general.cumulativeTotal GJ'), c.headers.energy, c.data.energy, i => {
374
+ const d = detailsRefs[i];
375
+ if (!d)
376
+ return '0';
377
+ return `='${d.sheetName.replace(/'/g, "''")}'!${d.cumCol}${d.energyTotalAvgRow}`;
378
+ }, '#,##0.00')
379
+ });
380
+ // 7. Emissions Section — references Details sheet annual averages and cumulative totals
311
381
  const emTotalRowIdx = currentRow + 1;
312
382
  const emPerHHRow = currentRow;
313
383
  rows.push({
@@ -320,9 +390,33 @@ export class SummarySheetBuilder {
320
390
  const emTotalRow = currentRow;
321
391
  rows.push({
322
392
  rowIndex: currentRow++,
323
- cells: createDataRow(null, 'i18n:general.total tCO2e/i18n:general.yearLower', c.headers.emissions, c.data.emissions, i => getSumAllFormula(i, 'C', 'i18n:general.total', 'D'), '#,##0.00')
393
+ cells: createDataRow(null, 'i18n:general.total tCO2e/i18n:general.yearLower', c.headers.emissions, c.data.emissions, i => {
394
+ const d = detailsRefs[i];
395
+ if (!d)
396
+ return getSumAllFormula(i, 'C', 'i18n:general.total', 'D');
397
+ return `='${d.sheetName.replace(/'/g, "''")}'!${d.avgCol}${d.emissionsTotalAvgRow}`;
398
+ }, '#,##0.00')
324
399
  });
400
+ if (multiYear)
401
+ rows.push({
402
+ rowIndex: currentRow++,
403
+ cells: createDataRow(null, periodLabel('i18n:general.cumulativeTotal tCO2e'), c.headers.emissions, c.data.emissions, i => {
404
+ const d = detailsRefs[i];
405
+ if (!d)
406
+ return '0';
407
+ return `='${d.sheetName.replace(/'/g, "''")}'!${d.cumCol}${d.emissionsTotalAvgRow}`;
408
+ }, '#,##0.00')
409
+ });
325
410
  // Create the final sheet
411
+ // Multi-year: column B fits the longest label, the Net rows, in the workbook's language.
412
+ // The value columns are filled, so Excel would otherwise cut the label at the column edge.
413
+ let colBWidth = c.columns.B.width;
414
+ if (multiYear) {
415
+ const g = (this.config.locale === 'fr' ? fr : en).general;
416
+ const longest = Math.max(`${g.netPropTaxes} (${g.maintOnly}, 2025\u20132050)`.length, `${g.netDevCharges} (${g.capitalOnlyBuildOut})`.length);
417
+ // Writers convert width to Excel character units at 7 per character; +2 characters of padding
418
+ colBWidth = Math.max(colBWidth, (longest + 2) * 7);
419
+ }
326
420
  const sheet = {
327
421
  name: 'i18n:worksheets.scenariosSummary',
328
422
  sheetType: 'summary',
@@ -334,7 +428,7 @@ export class SummarySheetBuilder {
334
428
  },
335
429
  columnWidths: [
336
430
  { range: 'A:A', width: c.columns.A.width },
337
- { range: 'B:B', width: c.columns.B.width },
431
+ { range: 'B:B', width: colBWidth },
338
432
  { range: `C:${getColumnLetter(scenarios.length + 1)}`, width: c.columns.C.width },
339
433
  { range: 'D:D', width: c.columns.D.width }
340
434
  ],
@@ -346,6 +440,12 @@ export class SummarySheetBuilder {
346
440
  scenarioNamesRow: capturedScenarioNamesRow,
347
441
  totalDwellingsRow,
348
442
  dataStartCol: 'C',
443
+ detailsSheetNames: detailsRefs.map(d => d.sheetName),
444
+ detailsAvgCol: detailsRefs[0]?.avgCol ?? '',
445
+ srvOMCumTotalRow,
446
+ infOMCumTotalRow,
447
+ detailsEnergyTotalRows: detailsRefs.map(d => d.energyTotalAvgRow),
448
+ detailsEmissionsTotalRows: detailsRefs.map(d => d.emissionsTotalAvgRow),
349
449
  metrics: {
350
450
  energy: { totalRow: energyTotalRow, perHHRow: energyPerHHRow },
351
451
  emissions: { totalRow: emTotalRow, perHHRow: emPerHHRow },
@@ -54,7 +54,16 @@ export interface WorkbookTheme {
54
54
  * The Master Configuration object passed into the workbook builder,
55
55
  * containing the locale (language) and the full WorkbookTheme.
56
56
  */
57
+ /**
58
+ * Which workbook `generateWorkbook` produces.
59
+ * - `'single-year'` (default): the 1.3.0 workbook, with one Calc sheet per scenario.
60
+ * - `'multi-year'`: adds a Details sheet per scenario with a year-by-year forecast to 2050,
61
+ * maintenance and cumulative totals, and line charts.
62
+ */
63
+ export type OutputMode = 'single-year' | 'multi-year';
57
64
  export interface GeneratorConfig {
58
65
  locale?: string;
59
66
  theme?: WorkbookTheme;
67
+ /** Workbook layout to produce. Defaults to `'single-year'`. */
68
+ outputMode?: OutputMode;
60
69
  }
@@ -40,6 +40,10 @@ export type ChartSeriesBy = 'Auto' | 'Columns' | 'Rows';
40
40
  /**
41
41
  * Chart legend position - matches Excel.ChartLegendPosition
42
42
  */
43
+ /**
44
+ * Chart series marker style - matches Excel.ChartMarkerStyle
45
+ */
46
+ export type ChartMarkerStyle = 'Automatic' | 'None' | 'Square' | 'Diamond' | 'Triangle' | 'X' | 'Star' | 'Dot' | 'Dash' | 'Circle' | 'Plus';
43
47
  export type ChartLegendPosition = 'Invalid' | 'Top' | 'Bottom' | 'Left' | 'Right' | 'Corner' | 'Custom';
44
48
  /**
45
49
  * Axis type - matches Excel.ChartAxisType
@@ -86,7 +90,7 @@ export interface SheetSpec {
86
90
  mergedRanges: string[];
87
91
  charts?: ChartSpec[];
88
92
  }
89
- export type SheetType = 'scenario' | 'summary' | 'assumptions' | 'chartData' | 'charts' | 'data';
93
+ export type SheetType = 'scenario' | 'scenarioDetails' | 'summary' | 'assumptions' | 'chartData' | 'charts' | 'data';
90
94
  export interface ColumnWidthSpec {
91
95
  range: string;
92
96
  width: number;
@@ -172,6 +176,10 @@ export interface ChartSpec {
172
176
  };
173
177
  /** Override series names */
174
178
  series?: ChartSeriesSpec[];
179
+ /** Marker drawn at each data point of every series (line charts). Omitted = writer default. */
180
+ markerStyle?: ChartMarkerStyle;
181
+ /** Marker size in points (Excel accepts 2–72). */
182
+ markerSize?: number;
175
183
  }
176
184
  export interface ChartAxisSpec {
177
185
  title?: {
@@ -202,6 +210,19 @@ export interface SummaryRefs {
202
210
  totalDwellingsRow: number;
203
211
  /** Column letter where scenario data starts (always 'C' in the current builder) */
204
212
  dataStartCol: string;
213
+ /** Details sheet names (one per scenario, in same order as scenarios[]) */
214
+ detailsSheetNames: string[];
215
+ /** AVG_COL letter used in all Details sheets (same for all when endYear is fixed) */
216
+ detailsAvgCol: string;
217
+ /** 1-based row in the Summary sheet for the Services cumulative maintenance total */
218
+ srvOMCumTotalRow: number;
219
+ /** 1-based row in the Summary sheet for the Infrastructure cumulative maintenance total */
220
+ infOMCumTotalRow: number;
221
+ /** Per-scenario row index in each Details sheet for "Total Annual Energy" (Section I).
222
+ * Used to build year-by-year formula references for line charts. */
223
+ detailsEnergyTotalRows: number[];
224
+ /** Per-scenario row index in each Details sheet for "Total Annual Emissions" (Section I). */
225
+ detailsEmissionsTotalRows: number[];
205
226
  /** Row indices for each of the 12 chart metrics */
206
227
  metrics: {
207
228
  energy: SummaryMetricRows;
@@ -218,3 +239,33 @@ export interface SummaryRefs {
218
239
  walk: SummaryMetricRows;
219
240
  };
220
241
  }
242
+ /** Per-building-type gas row indices in the Details sheet (AVG_COL and CUM_COL rows) */
243
+ export interface DetailsGasRows {
244
+ co2AvgRow: number;
245
+ ch4AvgRow: number;
246
+ n2oAvgRow: number;
247
+ co2CumRow: number;
248
+ ch4CumRow: number;
249
+ n2oCumRow: number;
250
+ }
251
+ /** References returned by ScenarioDetailsBuilder for cross-sheet formula injection */
252
+ export interface DetailsRefs {
253
+ /** Sheet tab name of the Details sheet */
254
+ sheetName: string;
255
+ /** Column letter of the Average Annual column (AVG_COL) */
256
+ avgCol: string;
257
+ /** Column letter of the Cumulative Total column (CUM_COL) */
258
+ cumCol: string;
259
+ /** Gas avg/cum row indices per building type key */
260
+ buildingGasRows: Record<string, DetailsGasRows>;
261
+ /** Gas avg/cum row indices per transport mode key (e.g. 'puv', 'transit') */
262
+ tptGasRows: Record<string, DetailsGasRows>;
263
+ /** 1-based row for Section I Total Annual Energy, AVG_COL cell */
264
+ energyTotalAvgRow: number;
265
+ /** 1-based row for Section I Energy Per Dwelling, AVG_COL cell */
266
+ energyPerDwellingAvgRow: number;
267
+ /** 1-based row for Section I Total Annual Emissions, AVG_COL cell */
268
+ emissionsTotalAvgRow: number;
269
+ /** 1-based row for Section I Emissions Per Dwelling, AVG_COL cell */
270
+ emissionsPerDwellingAvgRow: number;
271
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssg-coop/luic-calculator-core",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Core math and configs for the LUIC project",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
package/dist/package.json DELETED
@@ -1,31 +0,0 @@
1
- {
2
- "name": "luic-calculator-core",
3
- "version": "1.0.2",
4
- "description": "Core math and configs for the LUIC project",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "type": "module",
9
- "exports": {
10
- ".": {
11
- "import": "./dist/index.js",
12
- "require": "./dist/index.js",
13
- "types": "./dist/index.d.ts"
14
- }
15
- },
16
- "scripts": {
17
- "build": "tsc",
18
- "test": "vitest run",
19
- "test:e2e": "python3 tests/e2e_test.py",
20
- "lint": "eslint src --ext .ts",
21
- "test:scenario": "npx tsx tests/runners/test-scenario.ts"
22
- },
23
- "dependencies": {
24
- "convert-units": "^3.0.0-beta.5"
25
- },
26
- "devDependencies": {
27
- "typescript": "^5.0.0",
28
- "vitest": "^1.0.0",
29
- "@types/node": "^20.0.0"
30
- }
31
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * © Copyright 2023, LUIC-CIUT's Contributors
3
- * high level generic app settings
4
- */
5
- export default function appConfig(): {
6
- startYear: number;
7
- endYear: number;
8
- getYearsArray: (startAt?: number | string) => number[];
9
- getYearsArrayAsStrings: (startAt?: number | string) => string[];
10
- latestIntroAvailable: string;
11
- };
@@ -1,38 +0,0 @@
1
- /**
2
- * © Copyright 2023, LUIC-CIUT's Contributors
3
- * high level generic app settings
4
- */
5
- export default function appConfig() {
6
- const startYear = 2023;
7
- const endYear = 2050;
8
- const latestIntroAvailable = "1.0.0 Beta";
9
- /**
10
- * gets an array of years ranging from the app start year to the app end year
11
- * @param {number|string} startAt - the start year to begin the years array with. Default = app config startYear
12
- * @returns an array of all years from startAt to the app config endYear
13
- */
14
- const getYearsArray = (startAt = startYear) => {
15
- let arr = [];
16
- for (let i = typeof startAt === 'string' ? parseInt(startAt) : startAt; i <= endYear; arr.push(i++))
17
- ;
18
- return arr;
19
- };
20
- /**
21
- * gets an array of years represented as strings ranging from the app start year to the app end year
22
- * @param {number|string} startAt - the start year to begin the years array with. Default = app config startYear
23
- * @returns an array of all years in string format from startAt to the app config endYear
24
- */
25
- const getYearsArrayAsStrings = (startAt = startYear) => {
26
- let arr = [];
27
- for (let i = typeof startAt === 'string' ? parseInt(startAt) : startAt; i <= endYear; arr.push((i++).toString()))
28
- ;
29
- return arr;
30
- };
31
- return {
32
- startYear,
33
- endYear,
34
- getYearsArray,
35
- getYearsArrayAsStrings,
36
- latestIntroAvailable,
37
- };
38
- }
@@ -1,17 +0,0 @@
1
- export default function useCalculatorUtils(): {
2
- sumEnergyFromSources: (energySources: any, units: any, t: any, provId?: string) => number;
3
- sumEnergyFromObjCollection: (obj: any) => number;
4
- sumEmissionsFromObjCollection: (obj: any) => number;
5
- sumEnergyForScenarioGJ: (scenario: any) => number;
6
- sumEnergyForScenario: (scenario: any) => number;
7
- sumEmissionsForScenario: (scenario: any) => number;
8
- sumCostsForObj: (scenario: any, obj: string, key: string) => number;
9
- sumRevenueForObj: (scenario: any, obj: string, key: string) => number;
10
- computeGHGsFromSource: (t: any, sourceId: string, year: number | string, srcEnergy: number, provId?: string) => any;
11
- computeGhGsFromSourcesList: (t: any, provId: string | undefined, sourcesList: any, year: number | string, sourceListMode: string, energyExisting: number, energyFactor?: number | null) => any;
12
- computeTransportEnergyFromSourcesList: (t: any, sourcesList: any, transportationType: string, vkt: number) => number;
13
- convert: (value?: number) => import("convert-units").Converter<"energy" | "length" | "volumeToEnergy" | "area", string, string, number>;
14
- convertMPGtoLP100km: (MPG: number) => number;
15
- stripUnitsYr: (units: string) => string;
16
- stripUnits: (units: string, strip_units: string) => string;
17
- };
@@ -1,212 +0,0 @@
1
- /**
2
- * © Copyright 2023, LUIC-CIUT's Contributors
3
- * utilities for calculating ghgs and stuff
4
- */
5
- // @ts-ignore
6
- import configureMeasurements from 'convert-units';
7
- // @ts-ignore
8
- import energy from 'convert-units/definitions/energy';
9
- // @ts-ignore
10
- import area from 'convert-units/definitions/area';
11
- // @ts-ignore
12
- import length from 'convert-units/definitions/length';
13
- import energySourcesConfig from '../domain/energySources';
14
- import transportationConfig from '../domain/transportation';
15
- export default function useCalculatorUtils() {
16
- /**
17
- * calculate sum of energy source absolute values into a total to update inputExistingEnergy with
18
- * @param {any} energySources - Object containing keys for each energy source
19
- * @param {any} units - units to output energy in
20
- * @param {any} t - translation function
21
- * @param {string} provId - province id
22
- * @returns energy sum as a float
23
- */
24
- const sumEnergyFromSources = (energySources, units, t, provId = '') => {
25
- let energySum = 0;
26
- Object.keys(energySources).forEach((src) => {
27
- const _src = energySources[src];
28
- const srcVal = convert(_src.value)
29
- .from(energySourcesConfig(t, provId).energySources[src].convUnit)
30
- .to(stripUnitsYr(units));
31
- energySum += parseFloat(String(srcVal));
32
- });
33
- return energySum;
34
- };
35
- const sumEnergyFromObjCollection = (obj) => {
36
- let energySum = 0;
37
- Object.keys(obj).forEach((objType) => {
38
- energySum += obj[objType].energyUse;
39
- });
40
- return energySum;
41
- };
42
- const sumEmissionsFromObjCollection = (obj) => {
43
- let emissionsSum = 0;
44
- Object.keys(obj).forEach((objType) => {
45
- emissionsSum += obj[objType].emissions.total;
46
- });
47
- return emissionsSum;
48
- };
49
- const sumEnergyForScenario = (scenario) => {
50
- return (sumEnergyFromObjCollection(scenario.buildings) +
51
- sumEnergyFromObjCollection(scenario.transportation));
52
- };
53
- const sumEnergyForScenarioGJ = (scenario) => {
54
- return (sumEnergyForScenario(scenario) / 1000);
55
- };
56
- const sumEmissionsForScenario = (scenario) => {
57
- return (sumEmissionsFromObjCollection(scenario.buildings) +
58
- sumEmissionsFromObjCollection(scenario.transportation));
59
- };
60
- const sumCostsForObj = (scenario, obj, key) => {
61
- let costSum = 0;
62
- Object.keys(scenario[obj]).forEach((objType) => {
63
- costSum += scenario[obj][objType][key];
64
- });
65
- return costSum;
66
- };
67
- const sumRevenueForObj = (scenario, obj, key) => {
68
- const revenueObj = scenario[obj][key];
69
- let revenueSum = 0;
70
- Object.keys(revenueObj).forEach((item) => {
71
- revenueSum += revenueObj[item].perUnit * scenario.buildings[item].qty;
72
- });
73
- return revenueSum;
74
- };
75
- const computeGHGsFromSourceForYear = (t, sourceId, year, srcEnergy, ghgs, provId = '') => {
76
- const _year = typeof year === 'string' ? parseInt(year) : year;
77
- const source = energySourcesConfig(t, provId).energySources[sourceId];
78
- let total = 'total' in ghgs ? ghgs.total : 0;
79
- Object.keys(source.emissionsFactors).forEach((gas) => {
80
- if (!(gas in ghgs)) {
81
- ghgs[gas] = 0;
82
- }
83
- let gasGhgs = energySourcesConfig(t, provId).getEFForSourceByIdGasYear(sourceId, gas, _year) * srcEnergy;
84
- if (gas !== 'CO2') {
85
- gasGhgs = gasGhgs * energySourcesConfig(t, provId).gwp.values[gas];
86
- }
87
- gasGhgs = gasGhgs / 1e6;
88
- ghgs[gas] += gasGhgs;
89
- total += gasGhgs;
90
- });
91
- ghgs.total = total;
92
- };
93
- const computeGHGsFromSource = (t, sourceId, year, srcEnergy, provId = '') => {
94
- const _year = typeof year === 'string' ? parseInt(year) : year;
95
- let ghgs = null;
96
- const source = energySourcesConfig(t, provId).energySources[sourceId];
97
- const timeVariance = Array.isArray(source.emissionsFactors.CO2);
98
- if (timeVariance) {
99
- ghgs = [];
100
- let currentYear = _year;
101
- let _ghgs = null;
102
- while (currentYear <= energySourcesConfig(t, provId).efEndYear) {
103
- _ghgs = {};
104
- computeGHGsFromSourceForYear(t, sourceId, currentYear, srcEnergy, _ghgs, provId);
105
- ghgs.push(_ghgs);
106
- currentYear += 1;
107
- }
108
- }
109
- else {
110
- const _ghgs = {};
111
- computeGHGsFromSourceForYear(t, sourceId, _year, srcEnergy, _ghgs, provId);
112
- ghgs = _ghgs;
113
- }
114
- return ghgs;
115
- };
116
- const computeGhGsFromSourcesList = (t, provId = '', sourcesList, year, sourceListMode, energyExisting, energyFactor = null) => {
117
- const _year = typeof year === 'string' ? parseInt(year) : year;
118
- let timeVariance = false;
119
- const computeSources = (yr) => {
120
- const _ghgs = {};
121
- Object.keys(sourcesList).forEach((src) => {
122
- let srcEnergy = 0;
123
- if (sourceListMode === 'abs') {
124
- let fromUnits = stripUnitsYr(sourcesList[src].units);
125
- // @ts-ignore
126
- if (!convert().possibilities().includes(fromUnits)) {
127
- fromUnits = `${fromUnits}${src}`;
128
- }
129
- srcEnergy = convert(sourcesList[src].value).from(fromUnits).to('MJ');
130
- }
131
- else {
132
- srcEnergy = (sourcesList[src].value / 100) * energyExisting;
133
- }
134
- if (energyFactor !== null) {
135
- srcEnergy *= energyFactor;
136
- }
137
- computeGHGsFromSourceForYear(t, src, yr, srcEnergy, _ghgs, provId);
138
- });
139
- return _ghgs;
140
- };
141
- let ghgs = null;
142
- if (timeVariance) {
143
- ghgs = [];
144
- let currentYear = _year;
145
- while (currentYear <= energySourcesConfig(t).efEndYear) {
146
- ghgs.push(computeSources(currentYear));
147
- currentYear += 1;
148
- }
149
- }
150
- else {
151
- ghgs = computeSources(_year);
152
- }
153
- return ghgs;
154
- };
155
- const computeTransportEnergyFromSourcesList = (t, sourcesList, transportationType, vkt) => {
156
- let srcEnergy = 0;
157
- Object.keys(sourcesList).forEach((src) => {
158
- const fuelConsumption = transportationConfig(t).transportationTypes[transportationType]
159
- ?.fuelConsumption?.[src] ?? 0;
160
- srcEnergy +=
161
- (sourcesList[src].value / 100) * fuelConsumption * (vkt / 100);
162
- });
163
- return srcEnergy;
164
- };
165
- const buildConversionDef = (src) => {
166
- return {
167
- name: {
168
- singular: src.convUnit,
169
- plural: src.convUnit,
170
- },
171
- to_anchor: src.convVal,
172
- };
173
- };
174
- const volumeToEnergy = energySourcesConfig()
175
- .getEnergySourcesAsArray()
176
- .filter((src) => 'convVal' in src)
177
- .reduce((units, src) => ((units.systems.SI[src.convUnit] = buildConversionDef(src)), units), {
178
- ...energy,
179
- });
180
- const convert = configureMeasurements({
181
- volumeToEnergy,
182
- energy,
183
- area,
184
- length,
185
- });
186
- const stripUnitsYr = (units) => {
187
- return units.replace('/yr', '').replace('/an', '');
188
- };
189
- const stripUnits = (units, strip_units) => {
190
- return units.replace(strip_units, '');
191
- };
192
- const convertMPGtoLP100km = (MPG) => {
193
- return 235.22 / MPG;
194
- };
195
- return {
196
- sumEnergyFromSources,
197
- sumEnergyFromObjCollection,
198
- sumEmissionsFromObjCollection,
199
- sumEnergyForScenarioGJ,
200
- sumEnergyForScenario,
201
- sumEmissionsForScenario,
202
- sumCostsForObj,
203
- sumRevenueForObj,
204
- computeGHGsFromSource,
205
- computeGhGsFromSourcesList,
206
- computeTransportEnergyFromSourcesList,
207
- convert,
208
- convertMPGtoLP100km,
209
- stripUnitsYr,
210
- stripUnits,
211
- };
212
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * © Copyright 2023, LUIC-CIUT's Contributors
3
- * generic utilities for managing arrays and objects
4
- */
5
- export default function genericUtils(): {
6
- getObjectKeysAsArray: (Obj: any, keys?: string[] | null) => any[];
7
- resolveObjPath: (object: any, path: string, defaultValue?: any) => any;
8
- getUniqueName: (newName: string, nameCollection: string[], delimiter?: string | null, maxLength?: number) => string;
9
- getImageUrl: (name: string) => string;
10
- };