forked from Ke0xes/Aegis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
2056 lines (1775 loc) · 115 KB
/
script.js
File metadata and controls
2056 lines (1775 loc) · 115 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const START_YEAR = 2024;
const END_YEAR = 2040;
const YEARS_TO_PROJECT = END_YEAR - START_YEAR + 1;
// Initialize everything when the DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
// Initialize theme
const themeToggle = document.getElementById('themeToggle');
themeToggle.checked = true;
document.getElementById('currentThemeLabel').textContent = 'Dark Theme';
document.body.classList.add('professional-theme');
themeToggle.addEventListener('change', () => {
document.body.classList.toggle('professional-theme', themeToggle.checked);
document.getElementById('currentThemeLabel').textContent = themeToggle.checked ? 'Dark Theme' : 'Classic Theme';
});
// Setup all handlers and initialize components
setupDecimalHandling();
setupEventHandlers();
initializeCalculations();
// Setup mode toggles
document.querySelectorAll('.toggle-input-mode').forEach(toggle => {
toggle.addEventListener('change', function() {
const category = this.dataset.category;
const yearly = this.checked;
toggleInputMode(category, yearly);
});
});
});
function setupEventHandlers() {
// Set up investment model handlers
document.getElementById('inflationRate').addEventListener('change', calculateInvestmentBreakdown);
document.getElementById('yearSlider').addEventListener('change', calculateInvestmentBreakdown);
// Set up country selector handler
const countrySelector = document.getElementById('countrySelector');
if (countrySelector) {
countrySelector.addEventListener('change', updateGdpByCountry);
}
// Set up all utilization and investment handlers
document.querySelectorAll([
'#utilizationPeople', '#utilizationProcess', '#utilizationTechnology',
'#peopleCapex', '#peopleOpex', '#peopleRecCapex', '#peopleIncOpex',
'#processCapex', '#processOpex', '#processRecCapex', '#processIncOpex',
'#techCapex', '#techOpex', '#techRecCapex', '#techIncOpex'
].join(',')).forEach(el => el.addEventListener('change', calculateInvestmentBreakdown));
}
// Initialize all calculations
function initializeCalculations() {
calculateModel();
setupInfoIcons();
updateConflictWarnings(); // Check for conflicts on page load
updateGdpInWords();
// Initialize budget utilization view (default to CDC)
document.getElementById('cdcViewBtn').classList.add('active');
calculateInvestmentBreakdown();
// Set up year slider to update labels
const yearSlider = document.getElementById('yearSlider');
yearSlider.addEventListener('input', () => {
const selectedYear = yearSlider.value;
document.getElementById('sliderYearLabel').textContent = selectedYear;
});
}
// Setup decimal place handling for numeric inputs
function setupDecimalHandling() {
const decimalInputs = [
'nationalGdpGrowthRate',
'militaryGdpAllocation',
'overallCyberActivitiesApportionment'
];
function formatValue(input) {
const value = parseFloat(input.value);
if (!isNaN(value)) {
// Store the formatted value with 2 decimal places
input.setAttribute('data-value', value.toFixed(2));
input.value = value.toFixed(2);
}
}
decimalInputs.forEach(id => {
const input = document.getElementById(id);
if (input) {
// Format on load
formatValue(input);
// Format on change
input.addEventListener('change', (e) => {
formatValue(e.target);
});
// Store the original value when focusing
input.addEventListener('focus', (e) => {
const storedValue = e.target.getAttribute('data-value');
if (storedValue) {
e.target.value = storedValue;
}
});
// Restore the formatted value when leaving the field
input.addEventListener('blur', (e) => {
formatValue(e.target);
});
}
});
}
function numberToWords(num) {
const ones = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
const tens = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
const teens = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];
const scales = ['', 'thousand', 'million', 'billion', 'trillion'];
function processTriplet(triplet) {
let result = '';
if (triplet >= 100) {
result += ones[Math.floor(triplet / 100)] + ' hundred ';
triplet %= 100;
if (triplet > 0) result += 'and ';
}
if (triplet >= 20) {
result += tens[Math.floor(triplet / 10)] + ' ';
if (triplet % 10 > 0) result += ones[triplet % 10] + ' ';
} else if (triplet >= 10) {
result += teens[triplet - 10] + ' ';
} else if (triplet > 0) {
result += ones[triplet] + ' ';
}
return result;
}
if (num === 0) return 'zero';
let result = '';
let scaleIndex = 0;
while (num > 0) {
const triplet = num % 1000;
if (triplet > 0) {
result = processTriplet(triplet) + scales[scaleIndex] + ' ' + result;
}
scaleIndex++;
num = Math.floor(num / 1000);
}
return result.trim() + ' US dollars';
}
function applyGdpPresetModel(type) {
// GDP growth scenarios
const scenarios = {
robust: { // Strong Recovery & Innovation-Led Growth
2024: 0.8, 2025: 1.4, 2026: 2.1, 2027: 3.2, 2028: 3.8,
2029: 3.5, 2030: 2.9, 2031: 2.2, 2032: 2.6, 2033: 3.1,
2034: 3.4, 2035: 2.8, 2036: 2.1, 2037: 2.5, 2038: 2.7,
2039: 2.3, 2040: 2.6
},
moderate: { // Steady Nordic Model Growth
2024: 0.8, 2025: 1.1, 2026: 1.8, 2027: 2.3, 2028: 2.6,
2029: 2.1, 2030: 1.7, 2031: 1.9, 2032: 2.2, 2033: 2.4,
2034: 2.3, 2035: 2.0, 2036: 1.8, 2037: 2.1, 2038: 2.2,
2039: 2.0, 2040: 2.1
},
cautious: { // Constrained Growth with Headwinds
2024: 0.8, 2025: 0.9, 2026: 1.2, 2027: 1.6, 2028: 1.9,
2029: 1.5, 2030: 0.8, 2031: 1.1, 2032: 1.4, 2033: 1.7,
2034: 1.6, 2035: 1.2, 2036: 1.0, 2037: 1.3, 2038: 1.5,
2039: 1.4, 2040: 1.3
}
};
// Enable variable rate mode
const toggle = document.getElementById('gdpGrowthModeToggle');
toggle.checked = true;
toggleInputMode('gdpGrowth', true);
// DON'T overwrite the fixed rate input - preserve user's original value
// Only set the yearly values for variable mode
// Set values for each year
for (let year = START_YEAR; year <= END_YEAR; year++) {
const yearInput = document.getElementById(`gdpGrowth${year}`);
if (yearInput) {
yearInput.value = parseFloat(scenarios[type][year]).toFixed(2);
}
}
// Common disclaimer text
const disclaimerText = "DISCLAIMER: This is a theoretical example and not to be taken as fact-based forecasting.";
// Update source text with just the disclaimer
document.getElementById('nationalGdpGrowthRateSource').value = disclaimerText;
// Recalculate the model
calculateModel();
}
function applyMilitarySpendPreset(type) {
// Military spending scenarios
const scenarios = {
conservative: {
baseValue: 2.04,
name: 'EU Defense Model',
yearlyRates: {
2024: 2.04, 2025: 2.04, 2026: 2.04, 2027: 2.04, 2028: 2.04,
2029: 2.04, 2030: 2.04, 2031: 2.04, 2032: 2.04, 2033: 2.04,
2034: 2.04, 2035: 2.04, 2036: 2.04, 2037: 2.04, 2038: 2.04,
2039: 2.04, 2040: 2.04
}
},
balanced: {
baseValue: 2.30,
name: 'Nordic Defense Model',
yearlyRates: {
2024: 2.30, 2025: 2.30, 2026: 2.30, 2027: 2.30, 2028: 2.30,
2029: 2.30, 2030: 2.30, 2031: 2.30, 2032: 2.30, 2033: 2.30,
2034: 2.30, 2035: 2.30, 2036: 2.30, 2037: 2.30, 2038: 2.30,
2039: 2.30, 2040: 2.30
}
},
committed: {
baseValue: 2.20,
name: 'NATO Defense Model',
yearlyRates: {
2024: 2.14, 2025: 2.40, 2026: 2.40, 2027: 2.50, 2028: 2.60,
2029: 2.60, 2030: 3.50, 2031: 3.50, 2032: 3.50, 2033: 3.50,
2034: 3.50, 2035: 5.00, 2036: 5.00, 2037: 5.00, 2038: 5.00,
2039: 5.00, 2040: 5.00
}
}
};
// Enable variable rate mode
const toggle = document.getElementById('militaryAllocModeToggle');
toggle.checked = true;
toggleInputMode('militaryAllocation', true);
// DON'T overwrite the fixed rate input - preserve user's original value
// Only set the yearly values for variable mode
// Make sure yearly inputs are created and visible
const container = document.getElementById('yearlyMilitaryAllocationInputsContainer');
if (!container.querySelector('.yearly-input-item')) {
createYearlyInputs('militaryAllocation', 'yearlyMilitaryAllocationInputsContainer', 'militaryGdpAllocation');
}
// Set values for each year
for (let year = START_YEAR; year <= END_YEAR; year++) {
const yearInput = document.getElementById(`militaryAllocation${year}`);
if (yearInput) {
yearInput.value = scenarios[type].yearlyRates[year].toFixed(2);
}
}
// Set the source text
document.getElementById('militaryGdpAllocationSource').value =
`${scenarios[type].name} - DISCLAIMER: This is a theoretical example and not to be taken as fact-based forecasting.`;
// Recalculate the model
calculateModel();
}
function applyPresetModel(type) {
// Enable variable rate mode
const toggle = document.getElementById('overallCyberActivitiesApportionmentModeToggle');
toggle.checked = true;
toggleInputMode('overallCyberActivitiesApportionment', true);
// Get base value
const baseValue = parseFloat(document.getElementById('overallCyberActivitiesApportionment').value);
const increment = type === 'low' ? 0.25 : type === 'medium' ? 0.50 : 0.75;
// Set values for each year with incremental growth
for (let year = START_YEAR; year <= END_YEAR; year++) {
const yearInput = document.getElementById(`overallCyberActivitiesApportionment${year}`);
if (yearInput) {
const yearIndex = year - START_YEAR;
const value = baseValue + (increment * yearIndex);
yearInput.value = value.toFixed(2);
}
}
// Recalculate the model
calculateModel();
}
function updateGdpInWords() {
const gdpInput = document.getElementById('nationalGdp');
const gdpWordsDiv = document.getElementById('gdpInWords');
if (gdpInput && gdpWordsDiv) {
const value = parseFloat(gdpInput.value);
if (!isNaN(value)) {
gdpWordsDiv.textContent = numberToWords(Math.round(value));
} else {
gdpWordsDiv.textContent = '';
}
}
}
// Comprehensive Country GDP mapping based on World Bank/IMF 2024 data (in USD)
const COUNTRY_GDP_DATA = {
'US': { gdp: 27720700000000, name: 'United States', currency: 'USD' },
'CN': { gdp: 17794800000000, name: 'China', currency: 'CNY' },
'DE': { gdp: 4525700000000, name: 'Germany', currency: 'EUR' },
'JP': { gdp: 4204490000000, name: 'Japan', currency: 'JPY' },
'IN': { gdp: 3567550000000, name: 'India', currency: 'INR' },
'GB': { gdp: 3380850000000, name: 'United Kingdom', currency: 'GBP' },
'FR': { gdp: 3051830000000, name: 'France', currency: 'EUR' },
'IT': { gdp: 2300940000000, name: 'Italy', currency: 'EUR' },
'BR': { gdp: 2173670000000, name: 'Brazil', currency: 'BRL' },
'CA': { gdp: 2142470000000, name: 'Canada', currency: 'CAD' },
'RU': { gdp: 2021420000000, name: 'Russia', currency: 'RUB' },
'MX': { gdp: 1789110000000, name: 'Mexico', currency: 'MXN' },
'AU': { gdp: 1728060000000, name: 'Australia', currency: 'AUD' },
'KR': { gdp: 1712790000000, name: 'South Korea', currency: 'KRW' },
'ES': { gdp: 1620090000000, name: 'Spain', currency: 'EUR' },
'ID': { gdp: 1371170000000, name: 'Indonesia', currency: 'IDR' },
'NL': { gdp: 1154360000000, name: 'Netherlands', currency: 'EUR' },
'TR': { gdp: 1118250000000, name: 'Turkey', currency: 'TRY' },
'SA': { gdp: 1067580000000, name: 'Saudi Arabia', currency: 'SAR' },
'CH': { gdp: 884940000000, name: 'Switzerland', currency: 'CHF' },
'PL': { gdp: 809201000000, name: 'Poland', currency: 'PLN' },
'AR': { gdp: 646075000000, name: 'Argentina', currency: 'ARS' },
'BE': { gdp: 644783000000, name: 'Belgium', currency: 'EUR' },
'SE': { gdp: 584960000000, name: 'Sweden', currency: 'SEK' },
'IE': { gdp: 551395000000, name: 'Ireland', currency: 'EUR' },
'TH': { gdp: 514969000000, name: 'Thailand', currency: 'THB' },
'AE': { gdp: 514130000000, name: 'United Arab Emirates', currency: 'AED' },
'IL': { gdp: 513611000000, name: 'Israel', currency: 'ILS' },
'AT': { gdp: 511685000000, name: 'Austria', currency: 'EUR' },
'SG': { gdp: 501428000000, name: 'Singapore', currency: 'SGD' },
'NO': { gdp: 485311000000, name: 'Norway', currency: 'NOK' },
'BD': { gdp: 437415000000, name: 'Bangladesh', currency: 'BDT' },
'PH': { gdp: 437146000000, name: 'Philippines', currency: 'PHP' },
'VN': { gdp: 429717000000, name: 'Vietnam', currency: 'VND' },
'DK': { gdp: 407092000000, name: 'Denmark', currency: 'DKK' },
'IR': { gdp: 404626000000, name: 'Iran', currency: 'IRR' },
'MY': { gdp: 399705000000, name: 'Malaysia', currency: 'MYR' },
'EG': { gdp: 396002000000, name: 'Egypt', currency: 'EGP' },
'HK': { gdp: 380812000000, name: 'Hong Kong', currency: 'HKD' },
'ZA': { gdp: 380699000000, name: 'South Africa', currency: 'ZAR' },
'NG': { gdp: 363846000000, name: 'Nigeria', currency: 'NGN' },
'CO': { gdp: 363494000000, name: 'Colombia', currency: 'COP' },
'RO': { gdp: 350776000000, name: 'Romania', currency: 'RON' },
'CZ': { gdp: 343208000000, name: 'Czech Republic', currency: 'CZK' },
'PK': { gdp: 337912000000, name: 'Pakistan', currency: 'PKR' },
'CL': { gdp: 335533000000, name: 'Chile', currency: 'CLP' },
'FI': { gdp: 295532000000, name: 'Finland', currency: 'EUR' },
'PT': { gdp: 289114000000, name: 'Portugal', currency: 'EUR' },
'PE': { gdp: 267603000000, name: 'Peru', currency: 'PEN' },
'KZ': { gdp: 262642000000, name: 'Kazakhstan', currency: 'KZT' },
'NZ': { gdp: 252176000000, name: 'New Zealand', currency: 'NZD' },
'IQ': { gdp: 250843000000, name: 'Iraq', currency: 'IQD' },
'DZ': { gdp: 247626000000, name: 'Algeria', currency: 'DZD' },
'GR': { gdp: 243498000000, name: 'Greece', currency: 'EUR' },
'QA': { gdp: 213003000000, name: 'Qatar', currency: 'QAR' },
'HU': { gdp: 212389000000, name: 'Hungary', currency: 'HUF' },
'UA': { gdp: 178757000000, name: 'Ukraine', currency: 'UAH' },
'KW': { gdp: 163705000000, name: 'Kuwait', currency: 'KWD' },
'ET': { gdp: 163698000000, name: 'Ethiopia', currency: 'ETB' },
'MA': { gdp: 144417000000, name: 'Morocco', currency: 'MAD' },
'SK': { gdp: 132908000000, name: 'Slovakia', currency: 'EUR' },
'DO': { gdp: 121444000000, name: 'Dominican Republic', currency: 'DOP' },
'EC': { gdp: 118845000000, name: 'Ecuador', currency: 'USD' },
'SD': { gdp: 109266000000, name: 'Sudan', currency: 'SDG' },
'OM': { gdp: 108811000000, name: 'Oman', currency: 'OMR' },
'KE': { gdp: 108039000000, name: 'Kenya', currency: 'KES' },
'GT': { gdp: 104450000000, name: 'Guatemala', currency: 'GTQ' },
'BG': { gdp: 102408000000, name: 'Bulgaria', currency: 'BGN' },
'UZ': { gdp: 101592000000, name: 'Uzbekistan', currency: 'UZS' },
'CR': { gdp: 86497941439, name: 'Costa Rica', currency: 'CRC' },
'LU': { gdp: 85755006124, name: 'Luxembourg', currency: 'EUR' },
'AO': { gdp: 84824654482, name: 'Angola', currency: 'AOA' },
'HR': { gdp: 84393795502, name: 'Croatia', currency: 'HRK' },
'LK': { gdp: 84356863744, name: 'Sri Lanka', currency: 'LKR' },
'PA': { gdp: 83318176900, name: 'Panama', currency: 'USD' },
'RS': { gdp: 81342660752, name: 'Serbia', currency: 'RSD' },
'LT': { gdp: 79789877416, name: 'Lithuania', currency: 'EUR' },
'TZ': { gdp: 79062403821, name: 'Tanzania', currency: 'TZS' },
'CI': { gdp: 78875489245, name: 'Côte d\'Ivoire', currency: 'XOF' },
'UY': { gdp: 77240830877, name: 'Uruguay', currency: 'UYU' },
'GH': { gdp: 76370396722, name: 'Ghana', currency: 'GHS' },
'AZ': { gdp: 72356176471, name: 'Azerbaijan', currency: 'AZN' },
'BY': { gdp: 71857382746, name: 'Belarus', currency: 'BYN' },
'SI': { gdp: 69148468417, name: 'Slovenia', currency: 'EUR' },
'MM': { gdp: 66757619000, name: 'Myanmar', currency: 'MMK' },
'CD': { gdp: 66383287003, name: 'DR Congo', currency: 'CDF' },
'TM': { gdp: 60628857143, name: 'Turkmenistan', currency: 'TMT' }
};
function updateGdpByCountry() {
const countrySelector = document.getElementById('countrySelector');
const gdpInput = document.getElementById('nationalGdp');
const gdpSource = document.getElementById('nationalGdpSource');
const currencySelector = document.getElementById('currencySelector');
const exchangeRateInput = document.getElementById('currentExchangeRateInput');
if (!countrySelector || !gdpInput || !gdpSource) return;
const selectedCountry = countrySelector.value;
if (selectedCountry === 'custom' || selectedCountry === '') {
// Allow manual input for custom countries
gdpInput.readOnly = false;
gdpInput.placeholder = 'Enter GDP value manually';
if (selectedCountry === 'custom') {
gdpSource.value = 'Custom value - please specify source';
}
return;
}
const countryData = COUNTRY_GDP_DATA[selectedCountry];
if (countryData) {
// Debug logging
console.log('Setting GDP for country:', selectedCountry, 'GDP value:', countryData.gdp);
console.log('GDP input element before:', gdpInput.value);
// Update GDP
gdpInput.value = countryData.gdp;
gdpInput.readOnly = false; // Allow editing even after selection
gdpSource.value = `${countryData.name} - World Bank/IMF World Economic Outlook 2024`;
// Debug logging after setting
console.log('GDP input element after:', gdpInput.value);
// Simple approach - just set the value and trigger events
gdpInput.value = countryData.gdp;
gdpInput.dispatchEvent(new Event('input', { bubbles: true }));
gdpInput.dispatchEvent(new Event('change', { bubbles: true }));
updateGdpInWords();
console.log('Final GDP input value:', gdpInput.value);
// Auto-select currency based on country
const countryCurrency = COUNTRY_CURRENCY_MAP[selectedCountry];
if (countryCurrency && currencySelector) {
currencySelector.value = countryCurrency;
// Auto-populate exchange rate
if (exchangeRateInput && EXCHANGE_RATES[countryCurrency]) {
exchangeRateInput.value = EXCHANGE_RATES[countryCurrency].defaultRateFromUSD;
}
// Update formatter to match the new currency
updateFormatter(countryCurrency, true);
}
// Update the GDP in words display
updateGdpInWords();
// Recalculate the model with new GDP value
calculateModel();
}
}
// --- IMPORTANT: Current Exchange Rates (90-day averages approximated) ---
const EXCHANGE_RATES = {
'USD': { defaultRateFromUSD: 1.0, locale: 'en-US', symbol: '$' },
'EUR': { defaultRateFromUSD: 0.853, locale: 'de-DE', symbol: '€' },
'GBP': { defaultRateFromUSD: 0.738, locale: 'en-GB', symbol: '£' },
'JPY': { defaultRateFromUSD: 147.5, locale: 'ja-JP', symbol: '¥' },
'CAD': { defaultRateFromUSD: 1.384, locale: 'en-CA', symbol: 'C$' },
'AUD': { defaultRateFromUSD: 1.482, locale: 'en-AU', symbol: 'A$' },
'CHF': { defaultRateFromUSD: 0.933, locale: 'de-CH', symbol: 'Fr.' },
'SEK': { defaultRateFromUSD: 10.42, locale: 'sv-SE', symbol: 'kr' },
'NOK': { defaultRateFromUSD: 10.85, locale: 'no-NO', symbol: 'kr' },
'DKK': { defaultRateFromUSD: 6.36, locale: 'da-DK', symbol: 'kr' },
'PLN': { defaultRateFromUSD: 3.87, locale: 'pl-PL', symbol: 'zł' },
'CZK': { defaultRateFromUSD: 22.65, locale: 'cs-CZ', symbol: 'Kč' },
'HUF': { defaultRateFromUSD: 355.2, locale: 'hu-HU', symbol: 'Ft' },
'CNY': { defaultRateFromUSD: 7.12, locale: 'zh-CN', symbol: '¥' },
'INR': { defaultRateFromUSD: 83.25, locale: 'hi-IN', symbol: '₹' },
'KRW': { defaultRateFromUSD: 1325.5, locale: 'ko-KR', symbol: '₩' },
'SGD': { defaultRateFromUSD: 1.315, locale: 'en-SG', symbol: 'S$' },
'HKD': { defaultRateFromUSD: 7.78, locale: 'zh-HK', symbol: 'HK$' },
'NZD': { defaultRateFromUSD: 1.612, locale: 'en-NZ', symbol: 'NZ$' },
'ZAR': { defaultRateFromUSD: 17.85, locale: 'en-ZA', symbol: 'R' },
'BRL': { defaultRateFromUSD: 5.52, locale: 'pt-BR', symbol: 'R$' },
'MXN': { defaultRateFromUSD: 19.72, locale: 'es-MX', symbol: '$' },
'RUB': { defaultRateFromUSD: 96.25, locale: 'ru-RU', symbol: '₽' }
};
// --- Country to Currency Mapping ---
const COUNTRY_CURRENCY_MAP = {
'United States': 'USD',
'Canada': 'CAD',
'United Kingdom': 'GBP',
'Germany': 'EUR',
'France': 'EUR',
'Italy': 'EUR',
'Spain': 'EUR',
'Netherlands': 'EUR',
'Belgium': 'EUR',
'Austria': 'EUR',
'Portugal': 'EUR',
'Finland': 'EUR',
'Ireland': 'EUR',
'Luxembourg': 'EUR',
'Greece': 'EUR',
'Japan': 'JPY',
'Australia': 'AUD',
'Switzerland': 'CHF',
'Sweden': 'SEK',
'Norway': 'NOK',
'Denmark': 'DKK',
'Singapore': 'SGD',
'Hong Kong': 'HKD',
'China': 'CNY',
'India': 'INR',
'South Korea': 'KRW',
'New Zealand': 'NZD',
'Mexico': 'MXN',
'Brazil': 'BRL',
'South Africa': 'ZAR',
'Russia': 'RUB',
'Thailand': 'THB',
'Turkey': 'TRY',
'Poland': 'PLN'
};
// --- Definitions for Info Icons/Tooltips ---
const INFO_DEFINITIONS = {
currencySettings: {
label: "Currency Settings",
description: "Exchange rates shown are historical averages. Please adjust the rates according to current market values for more accurate projections.",
uniqueCode: "CURRENCYSETS"
},
nationalGdp: {
label: "Country's Gross Domestic Product (GDP) - Base Year",
description: `The total monetary value of all finished goods and services produced within a country's borders in the starting year (${START_YEAR}). This is the foundational economic indicator for the top-down approach.`,
uniqueCode: "NATLGDPTOTAL"
},
nationalGdpGrowthRate: {
label: "National GDP Annual Growth Rate",
description: "The projected annual percentage increase of the country's Gross Domestic Product (GDP). This value is used if 'Use Fixed Annual Rate' is selected.",
uniqueCode: "GDPGRWTHRATE"
},
militaryGdpAllocation: {
label: "Percentage of GDP Allocated to Military Spending",
description: "The specific percentage of the country's GDP that is designated for overall military expenditure. This value is used if 'Use Fixed Annual Rate' is selected.",
uniqueCode: "MILGDPCENTAG"
},
overallCyberActivitiesApportionment: {
label: "Percentage of Military Budget for All Cyber Activities",
description: "The percentage of the total military budget that is specifically allocated to cover all cyber-related activities. This value is used if 'Use Fixed Annual Rate' is selected.",
uniqueCode: "OVRCYBACTAPP"
},
cyberDefenseCenterSocAllocation: {
label: "Percentage of Cyber Activities Budget for CDC & SOC Combined",
description: "The percentage of the 'Overall Cyber Activities Budget' that is specifically dedicated to the CDC and the multiple SOCs.",
uniqueCode: "CYBDEFUSOCAL"
},
cyberDefenseVsSocSplit: {
label: "Allocation Split: CDC vs. SOCs (% for CDC)",
description: "The internal percentage breakdown of funds allocated between the dedicated CDC and multiple SOCs. This value represents the percentage for the CDC.",
uniqueCode: "CYBDEFVSOCSP"
},
threatLandscape: {
label: "Threat Landscape & Risk Assessment Input",
description: "Qualitative and quantitative data derived from the analysis of the current and projected cyber threat landscape and associated risks. This input informs strategic allocation and prioritization decisions within the cyber defense budget.",
uniqueCode: "THRTLNDRKSIN"
},
investmentParameters: {
label: "Investment Parameters",
description: "Key financial parameters that affect investment calculations. Annual Inflation Rate adjusts future costs for economic inflation, while Asset Lifecycle determines when technology assets require replacement or major upgrades (typically every 5 years for cyber defense equipment).",
uniqueCode: "INVSTPARAMS1"
},
// People Cost Allocation Tooltips
peopleCapexCosts: {
label: "People - CapEx Costs",
description: "Capital Expenditure refers to the funds an organization uses to acquire, upgrade, or maintain long-term assets.<br><br><strong>Examples include:</strong><ul><li>Purchase and setup of suitable office spaces</li><li>Initial purchase of office furniture and fixtures</li><li>Recruitment agency and marketing fees for specialist roles</li><li>Development of proprietary training and certification programs</li></ul>",
uniqueCode: "PEOPLECAPEX1"
},
peopleBaselineOpex: {
label: "People - Baseline OpEx Costs",
description: "Baseline Operating Expenses represent the established, ongoing costs an organization incurs for its normal, day-to-day operations.<br><br><strong>Examples include:</strong><ul><li>Office rental and associated utilities costs</li><li>Ongoing salaries, benefits and payroll taxes</li><li>Routine recruitment and onboarding expenses</li><li>Professional development and training</li><li>Conference attendance and travel</li></ul>",
uniqueCode: "PEOPLEBASEOPX"
},
peopleRecurringCapex: {
label: "People - Recurring CapEx Costs",
description: "Recurring Capital Expenditures are capital investments made repeatedly to maintain an organization's current operational capacity and replace aging assets.<br><br><strong>Examples include:</strong><ul><li>Expansion and setup of additional office space</li><li>Replacement of office furniture and fixtures</li><li>Further recruitment agency and marketing fees for specialist roles</li></ul>",
uniqueCode: "PEOPLERECCPX1"
},
peopleIncrementalOpex: {
label: "People - Incremental OpEx Costs",
description: "Incremental Operating Expenses are additional operational costs incurred due to an increase in organizational activity, such as the launch of new projects, or expansion.<br><br><strong>Examples include:</strong><ul><li>Hiring costs for new teams/capabilities</li><li>Ad hoc ongoing salaries, benefits and payroll taxes</li><li>Specialized training for new threats and technologies</li><li>Temporary staffing for a project</li><li>Costs of running new or expanded certification programs</li><li>Higher utility costs</li></ul>",
uniqueCode: "PEOPLEINCROPX"
},
// Process Cost Allocation Tooltips
processCapexCosts: {
label: "Process - CapEx Costs",
description: "Capital Expenditure refers to the funds an organization uses to acquire, upgrade, or maintain long-term assets.<br><br><strong>Examples include:</strong><ul><li>External consultancy fees to assist with the creation of appropriate governance structures and services</li><li>One-time cost for external audit and certification</li></ul>",
uniqueCode: "PROCESSCAPEX"
},
processBaselineOpex: {
label: "Process - Baseline OpEx Costs",
description: "Baseline Operating Expenses represent the established, ongoing costs an organization incurs for its normal, day-to-day operations.<br><br><strong>Examples include:</strong><ul><li>Ongoing external consultancy fees to assist with the creation of processes and metrics</li><li>Ongoing external audit and certification</li><li>Insurance premiums</li><li>Routine organizational administration, such as legal and accounting fees</li><li>Costs associated with continuous process improvement initiatives</li></ul>",
uniqueCode: "PROCESSBASOPX"
},
processRecurringCapex: {
label: "Process - Recurring CapEx Costs",
description: "Recurring Capital Expenditures are capital investments made repeatedly to maintain an organization's current operational capacity and replace aging assets.<br><br><strong>Examples include:</strong><ul><li>External consultancy fees to assist with transformation programs</li><li>External consultancy fees to assist with optimization programs</li><li>Capitalized investment in developing new automated playbooks</li></ul>",
uniqueCode: "PROCESSRECCX"
},
processIncrementalOpex: {
label: "Process - Incremental OpEx Costs",
description: "Incremental Operating Expenses are additional operational costs incurred due to an increase in organizational activity, such as the launch of new projects, or expansion.<br><br><strong>Examples include:</strong><ul><li>Ongoing external consultancy fees to assist with the optimization of processes and metrics</li><li>Costs of expanding compliance to new or updated regulatory frameworks</li><li>Running bug bounty or vulnerability programs</li></ul>",
uniqueCode: "PROCESSINCOX"
},
// Technology Cost Allocation Tooltips
technologyCapexCosts: {
label: "Technology - CapEx Costs",
description: "Capital Expenditure refers to the funds an organization uses to acquire, upgrade, or maintain long-term assets.<br><br><strong>Examples include:</strong><ul><li>Purchase of physical assets and equipment needed for operations</li><li>Initial procurement of core IT systems or platforms</li><li>Construction or major upgrades of facilities, data centers or infrastructure</li><li>One-time purchases of perpetual licenses</li></ul>",
uniqueCode: "TECHCAPEXCO1"
},
technologyBaselineOpex: {
label: "Technology - Baseline OpEx Costs",
description: "Baseline Operating Expenses represent the established, ongoing costs an organization incurs for its normal, day-to-day operations.<br><br><strong>Examples include:</strong><ul><li>Recurring software usage or service subscriptions</li><li>Service provider consumption costs (Cloud or any other service that is consumed with a cost associated to it)</li><li>Maintenance and support contracts for hardware and software</li><li>Consumable supplies required for ongoing operations, such as replacement parts for hardware (e.g., cables, batteries, etc.)</li></ul>",
uniqueCode: "TECHBASELOPX"
},
technologyRecurringCapex: {
label: "Technology - Recurring CapEx Costs",
description: "Recurring Capital Expenditures are capital investments made repeatedly to maintain an organization's current operational capacity and replace aging assets.<br><br><strong>Examples include:</strong><ul><li>Scheduled replacement or refresh cycles for IT equipment and infrastructure</li><li>Capitalized costs for major system upgrades or enhancements</li><li>Investments to expand capacity or capabilities</li></ul>",
uniqueCode: "TECHRECCAPX1"
},
technologyIncrementalOpex: {
label: "Technology - Incremental OpEx Costs",
description: "Incremental Operating Expenses are additional operational costs incurred due to an increase in organizational activity, such as the launch of new projects, or expansion.<br><br><strong>Examples include:</strong><ul><li>Budgets for evaluating or piloting emerging solutions</li><li>Licenses for additional modules or advanced features on current IT platforms</li><li>Data wipe services to securely remove recoverable information from devices</li><li>Higher data transfer or bandwidth costs</li><li>Surge costs for cloud services during peak usage</li></ul>",
uniqueCode: "TECHINCROPX1"
}
};
let currentFormatter;
let narrativeData = {};
let yearlyCdcBudgets = []; // Store calculated CDC budgets (in USD) for the utilization section
let yearlySocBudgets = []; // Store calculated SOC budgets (in USD) for the utilization section
let yearlyCombinedBudgets = []; // Store calculated CDC+SOC combined budgets (in USD) for the utilization section
// --- Main Calculation Engine ---
function calculateModel() {
const currencySelector = document.getElementById('currencySelector');
const selectedCurrencyCode = currencySelector.value;
const rateFromUSD = parseFloat(document.getElementById('currentExchangeRateInput').value);
updateFormatter(selectedCurrencyCode);
// --- 1. Retrieve Input Values ---
const nationalGdpUSD = parseFloat(document.getElementById('nationalGdp').value);
const initialCyberDefenseCenterSocAllocation = parseFloat(document.getElementById('cyberDefenseCenterSocAllocation').value) / 100;
const cyberDefenseVsSocSplit = parseFloat(document.getElementById('cyberDefenseVsSocSplit').value) / 100;
// --- 2. Initialize Data Arrays (all in USD) ---
const years = Array.from({ length: YEARS_TO_PROJECT }, (_, i) => START_YEAR + i);
const projGdp = new Array(YEARS_TO_PROJECT);
const projMilitarySpend = new Array(YEARS_TO_PROJECT);
const projOverallCyberSpend = new Array(YEARS_TO_PROJECT);
const projCdcSocSpend = new Array(YEARS_TO_PROJECT);
const projCdcSpend = new Array(YEARS_TO_PROJECT);
const projSocSpend = new Array(YEARS_TO_PROJECT);
// --- 3. NEW CALCULATION LOGIC BASED ON SPECIFICATIONS ---
// Helper function to get rate for current year (only when in variable mode)
const getYearlyRate = (inputId, year, defaultRate, isVariableMode) => {
// Only check for yearly inputs if we're actually in variable mode
if (!isVariableMode) {
return defaultRate;
}
const yearlyInput = document.getElementById(`${inputId}${year}`);
if (yearlyInput && yearlyInput.value !== '') {
return parseFloat(yearlyInput.value) / 100;
}
return defaultRate;
};
// Check which inputs are using variable/customize yearly rates
const gdpGrowthIsVariable = document.getElementById('gdpGrowthModeToggle').checked;
const militaryAllocIsVariable = document.getElementById('militaryAllocModeToggle').checked;
const cyberApportionmentIsVariable = document.getElementById('overallCyberActivitiesApportionmentModeToggle').checked;
// Get fixed rates
const fixedGdpGrowthRate = parseFloat(document.getElementById('nationalGdpGrowthRate').value) / 100;
const fixedMilitaryAllocRate = parseFloat(document.getElementById('militaryGdpAllocation').value) / 100;
const fixedCyberApportionmentRate = parseFloat(document.getElementById('overallCyberActivitiesApportionment').value) / 100;
// YEAR-BY-YEAR CALCULATIONS
for (let i = 0; i < YEARS_TO_PROJECT; i++) {
const currentYear = START_YEAR + i;
// STEP 1: Calculate GDP
if (i === 0) {
// Base year 2024
projGdp[i] = nationalGdpUSD;
} else {
// Get GDP growth rate for this year
let gdpGrowthRate;
if (gdpGrowthIsVariable) {
// In variable mode, get the specific yearly rate
gdpGrowthRate = getYearlyRate('gdpGrowth', currentYear, fixedGdpGrowthRate, true);
} else {
// In fixed mode, always use the fixed rate from the input box
gdpGrowthRate = fixedGdpGrowthRate;
}
projGdp[i] = projGdp[i - 1] * (1 + gdpGrowthRate);
}
// STEP 2: Calculate Military Budget
if (i === 0) {
// Base year: Calculate as percentage of GDP
let militaryAllocRate;
if (militaryAllocIsVariable) {
militaryAllocRate = getYearlyRate('militaryAllocation', currentYear, fixedMilitaryAllocRate, true);
} else {
militaryAllocRate = fixedMilitaryAllocRate;
}
projMilitarySpend[i] = projGdp[i] * militaryAllocRate;
} else {
// Subsequent years: Always use allocation approach (percentage of GDP)
let militaryAllocRate;
if (militaryAllocIsVariable) {
militaryAllocRate = getYearlyRate('militaryAllocation', currentYear, fixedMilitaryAllocRate, true);
} else {
militaryAllocRate = fixedMilitaryAllocRate;
}
projMilitarySpend[i] = projGdp[i] * militaryAllocRate;
}
// STEP 3: Calculate Cyber Budget (always as percentage of Military Budget)
let cyberApportionmentRate;
if (cyberApportionmentIsVariable) {
cyberApportionmentRate = getYearlyRate('overallCyberActivitiesApportionment', currentYear, fixedCyberApportionmentRate, true);
} else {
cyberApportionmentRate = fixedCyberApportionmentRate;
}
projOverallCyberSpend[i] = projMilitarySpend[i] * cyberApportionmentRate;
// STEP 4: Calculate CDC/SOC Combined Budget
if (i === 0) {
// Base year: Calculate as percentage of Cyber Budget
projCdcSocSpend[i] = projOverallCyberSpend[i] * initialCyberDefenseCenterSocAllocation;
} else {
// Subsequent years: Always use allocation approach (percentage of current year's Cyber Budget)
projCdcSocSpend[i] = projOverallCyberSpend[i] * initialCyberDefenseCenterSocAllocation;
}
// STEP 5: Split CDC/SOC Budget (always based on allocation split)
projCdcSpend[i] = projCdcSocSpend[i] * cyberDefenseVsSocSplit;
projSocSpend[i] = projCdcSocSpend[i] * (1 - cyberDefenseVsSocSplit);
}
yearlyCdcBudgets = [...projCdcSpend]; // Store for utilization section
yearlySocBudgets = [...projSocSpend]; // Store for utilization section
yearlyCombinedBudgets = [...projCdcSocSpend]; // Store for utilization section
// Calculate investment breakdown whenever the model is updated
const investmentBreakdownTotals = calculateInvestmentBreakdown();
// Calculate comprehensive investment totals for all views
const comprehensiveInvestmentTotals = calculateComprehensiveInvestmentTotals();
// --- 4. Store Data for Narrative ---
// Calculate cumulative totals for 2025-2040
const cumulativeCdcSpend = projCdcSpend.reduce((sum, value) => sum + value, 0);
const cumulativeSocSpend = projSocSpend.reduce((sum, value) => sum + value, 0);
const cumulativeCdcSocSpend = projCdcSocSpend.reduce((sum, value) => sum + value, 0);
narrativeData = {
finalCdcSocSpend: projCdcSocSpend[YEARS_TO_PROJECT - 1],
finalCdcSpend: projCdcSpend[YEARS_TO_PROJECT - 1],
finalSocSpend: projSocSpend[YEARS_TO_PROJECT - 1],
// Add 2025 (initial year) data
initialCdcSpend: projCdcSpend[1], // Index 1 = 2025
initialSocSpend: projSocSpend[1],
initialCdcSocSpend: projCdcSocSpend[1],
// Add cumulative totals from investment breakdown (sophisticated calculations)
cumulativeCdcSpend: investmentBreakdownTotals ? investmentBreakdownTotals.total : cumulativeCdcSpend,
cumulativeSocSpend: cumulativeSocSpend,
cumulativeCdcSocSpend: cumulativeCdcSocSpend,
// Store investment breakdown totals for detailed breakdown in narrative
investmentBreakdownTotals: investmentBreakdownTotals,
// Store comprehensive investment totals for all views
comprehensiveInvestmentTotals: comprehensiveInvestmentTotals,
threatLandscape: document.getElementById('threatLandscape').value,
inputValues: {
nationalGdp: document.getElementById('nationalGdp').value,
nationalGdpSource: document.getElementById('nationalGdpSource').value,
nationalGdpGrowthRate: document.getElementById('nationalGdpGrowthRate').value,
nationalGdpGrowthRateSource: document.getElementById('nationalGdpGrowthRateSource').value,
militaryGdpAllocation: document.getElementById('militaryGdpAllocation').value,
militaryGdpAllocationSource: document.getElementById('militaryGdpAllocationSource').value,
overallCyberActivitiesApportionment: document.getElementById('overallCyberActivitiesApportionment').value,
overallCyberActivitiesApportionmentSource: document.getElementById('overallCyberActivitiesApportionmentSource').value,
cyberDefenseCenterSocAllocation: document.getElementById('cyberDefenseCenterSocAllocation').value,
cyberDefenseCenterSocAllocationSource: document.getElementById('cyberDefenseCenterSocAllocationSource').value,
cyberDefenseVsSocSplit: document.getElementById('cyberDefenseVsSocSplit').value,
cyberDefenseVsSocSplitSource: document.getElementById('cyberDefenseVsSocSplitSource').value,
utilizationPeople: document.getElementById('utilizationPeople').value,
utilizationProcess: document.getElementById('utilizationProcess').value,
utilizationTechnology: document.getElementById('utilizationTechnology').value,
// People Cost Allocation
peopleCapex: document.getElementById('peopleCapex').value,
peopleOpex: document.getElementById('peopleOpex').value,
peopleRecCapex: document.getElementById('peopleRecCapex').value,
peopleIncOpex: document.getElementById('peopleIncOpex').value,
// Process Cost Allocation
processCapex: document.getElementById('processCapex').value,
processOpex: document.getElementById('processOpex').value,
processRecCapex: document.getElementById('processRecCapex').value,
processIncOpex: document.getElementById('processIncOpex').value,
// Technology Cost Allocation
techCapex: document.getElementById('techCapex').value,
techOpex: document.getElementById('techOpex').value,
techRecCapex: document.getElementById('techRecCapex').value,
techIncOpex: document.getElementById('techIncOpex').value
}
};
// --- 5. Populate Year-on-Year Summary Table ---
populateSummaryTable(years, rateFromUSD, projGdp, projMilitarySpend, projOverallCyberSpend, projCdcSocSpend, projSocSpend, projCdcSpend);
// --- 6. Calculate Investment Breakdown ---
calculateInvestmentBreakdown();
}
function populateSummaryTable(years, rateFromUSD, ...dataArrays) {
const combinedTableBody = document.querySelector('#yearlyCombinedSpendTable tbody');
const headerRow = document.querySelector('#yearlyCombinedSpendTable thead tr');
while (headerRow.children.length > 1) headerRow.removeChild(headerRow.lastChild);
years.forEach(year => {
const th = document.createElement('th');
th.textContent = year;
headerRow.appendChild(th);
});
// Correctly map data arrays to rows.
// Row 4 = SOC Budget (data index 4), Row 5 = CDC Budget (data index 5)
const mapping = [0, 1, 2, 3, 4, 5]; // GDP, Mil, Cyber, Combined, SOC, CDC
mapping.forEach((dataIndex, rowIndex) => {
const row = combinedTableBody.rows[rowIndex];
const dataArray = dataArrays[dataIndex];
while (row.cells.length > 1) row.deleteCell(1);
dataArray.forEach(value => {
row.insertCell().textContent = currentFormatter.format(value * rateFromUSD);
});
});
}
function generateNarrative() {
const pptPeople = parseFloat(document.getElementById('utilizationPeople').value) / 100;
const pptProcess = parseFloat(document.getElementById('utilizationProcess').value) / 100;
const pptTech = parseFloat(document.getElementById('utilizationTechnology').value) / 100;
const pptBoxes = [
document.getElementById('ppt-box-people'),
document.getElementById('ppt-box-process'),
document.getElementById('ppt-box-tech')
];
if (Math.abs(pptPeople + pptProcess + pptTech - 1) > 0.001) {
pptBoxes.forEach(box => box.classList.add('error-state'));
} else {
pptBoxes.forEach(box => box.classList.remove('error-state'));
}
const getCostBreakdown = (type) => {
const breakdown = {
capex: parseFloat(document.getElementById(`${type}Capex`).value) / 100,
opex: parseFloat(document.getElementById(`${type}Opex`).value) / 100,
recCapex: parseFloat(document.getElementById(`${type}RecCapex`).value) / 100,
incOpex: parseFloat(document.getElementById(`${type}IncOpex`).value) / 100
};
const inputs = ['Capex', 'Opex', 'RecCapex', 'IncOpex'].map(suffix => document.getElementById(`${type}${suffix}`));
if (Math.abs(breakdown.capex + breakdown.opex + breakdown.recCapex + breakdown.incOpex - 1) > 0.001) {
inputs.forEach(input => input.closest('.input-group').classList.add('error-state'));
} else {
inputs.forEach(input => input.closest('.input-group').classList.remove('error-state'));
}
return breakdown;
};
const peopleCosts = getCostBreakdown('people');
const processCosts = getCostBreakdown('process');
const techCosts = getCostBreakdown('tech');
const rateFromUSD = parseFloat(document.getElementById('currentExchangeRateInput').value);
// --- Generate Summary Cards Display ---
const slider = document.getElementById('yearSlider');
const selectedYear = parseInt(slider.value);
const yearIndex = selectedYear - START_YEAR;
const totalCdcBudget = yearlyCdcBudgets[yearIndex] || 0;
const yearSince = selectedYear - START_YEAR;
const peopleBudget = totalCdcBudget * pptPeople;
const processBudget = totalCdcBudget * pptProcess;
const techBudget = totalCdcBudget * pptTech;
// Apply the same logic as the breakdown table for recurring capex
const peopleComponents = {
capex: yearSince === 0 ? peopleBudget * peopleCosts.capex : 0, // Initial CAPEX only in first year
opex: peopleBudget * peopleCosts.opex,
recCapex: yearSince > 0 ? peopleBudget * peopleCosts.recCapex : 0, // Recurring CAPEX only after first year
incOpex: peopleBudget * peopleCosts.incOpex
};
const processComponents = {
capex: yearSince === 0 ? processBudget * processCosts.capex : 0, // Initial CAPEX only in first year
opex: processBudget * processCosts.opex,
recCapex: yearSince > 0 ? processBudget * processCosts.recCapex : 0, // Recurring CAPEX only after first year
incOpex: processBudget * processCosts.incOpex
};
const techComponents = {
capex: yearSince === 0 ? techBudget * techCosts.capex : 0, // Initial CAPEX only in first year
opex: techBudget * techCosts.opex,
recCapex: yearSince > 0 ? techBudget * techCosts.recCapex : 0, // Recurring CAPEX only after first year
incOpex: techBudget * techCosts.incOpex
};
const singleYearData = {
people: {
total: peopleComponents.capex + peopleComponents.opex + peopleComponents.recCapex + peopleComponents.incOpex,
...peopleComponents
},
process: {
total: processComponents.capex + processComponents.opex + processComponents.recCapex + processComponents.incOpex,
...processComponents
},
technology: {
total: techComponents.capex + techComponents.opex + techComponents.recCapex + techComponents.incOpex,
...techComponents
}
};
container.innerHTML = generateSummaryCards(singleYearData, rateFromUSD);
setupInfoIcons();
}
function generateSummaryCards(data, rateFromUSD) {
let cardsHtml = '<div class="summary-cards-container">';
const categories = ['people', 'process', 'technology'];
categories.forEach(cat => {
const catData = data[cat];
cardsHtml += `
<div class="summary-card">
<div class="card-header">
<h3>${cat.charAt(0).toUpperCase() + cat.slice(1)}</h3>
<div class="card-total">${currentFormatter.format(catData.total * rateFromUSD)}</div>
</div>
<div class="card-body">
<div class="card-item"><span>Capex</span> <span>${currentFormatter.format(catData.capex * rateFromUSD)}</span></div>
<div class="card-item"><span>Baseline Opex</span> <span>${currentFormatter.format(catData.opex * rateFromUSD)}</span></div>
<div class="card-item"><span>Recurring Capex</span> <span>${currentFormatter.format(catData.recCapex * rateFromUSD)}</span></div>
<div class="card-item"><span>Incremental Opex</span> <span>${currentFormatter.format(catData.incOpex * rateFromUSD)}</span></div>
</div>
</div>
`;
});
cardsHtml += '</div>';
return cardsHtml;
}
function generateDetailedTable(allYearsData, rateFromUSD) {
const years = Array.from({ length: YEARS_TO_PROJECT }, (_, i) => START_YEAR + i);
const costTypes = {
capex: 'Capex Costs',
opex: 'Baseline Opex',
recCapex: 'Recurring Capex',
incOpex: 'Incremental Opex'
};
let tableHtml = `
<div class="table-container">
<table id="utilizationDetailedTable">
<thead>
<tr>
<th>Sub-Category</th>
${years.map(year => `<th>${year}</th>`).join('')}
</tr>
</thead>
<tbody>`;
const createSection = (title, dataKey) => {
let sectionHtml = `<tr><th class="tbody-header" colspan="${YEARS_TO_PROJECT + 1}">${title}</th></tr>`;
Object.keys(costTypes).forEach(costKey => {
sectionHtml += `<tr><td>${costTypes[costKey]}</td>`;
allYearsData.forEach(yearData => {