Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
1768 lines (1623 loc) · 91.8 KB
/
Copy pathapp.py
File metadata and controls
1768 lines (1623 loc) · 91.8 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
from __future__ import annotations
import subprocess
import sys
from dataclasses import dataclass
from pathlib import Path
import networkx as nx
import numpy as np
import pandas as pd
import plotly.graph_objects as go
import requests
import streamlit as st
try:
from streamlit.runtime.scriptrunner import get_script_run_ctx
except ImportError:
from streamlit.runtime.scriptrunner_utils.script_run_context import get_script_run_ctx
if __name__ == "__main__" and get_script_run_ctx() is None:
subprocess.run([sys.executable, "-m", "streamlit", "run", __file__], check=False)
sys.exit()
st.set_page_config(page_title="War Impact On Trade", layout="wide")
st.markdown(
"""
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');
:root {
--bg-main: #040507;
--bg-shell: #090b10;
--bg-secondary: #0d1016;
--bg-tertiary: #121722;
--bg-elevated: #171d29;
--border: rgba(255,255,255,0.10);
--border-soft: rgba(255,255,255,0.07);
--text-primary: #f7f9fc;
--text-secondary: #a4aec3;
--text-dim: #6f7b92;
--accent: #32d7ff;
--accent-2: #7d6bff;
--accent-3: #ff53b5;
--accent-4: #ffb84f;
--shadow: 0 24px 48px rgba(0, 0, 0, 0.42);
--glow: 0 0 0 1px rgba(255,255,255,0.03), 0 0 56px rgba(125, 107, 255, 0.08);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body, .stApp {
background: linear-gradient(180deg, #090b11 0%, #040507 100%);
color: var(--text-primary);
font-family: "Inter", "Segoe UI Variable Display", "SF Pro Display", Arial, sans-serif;
}
.block-container {
max-width: 1580px;
padding: 1.2rem 1.8rem 2rem 1.8rem;
background: transparent;
}
[data-testid="stSidebar"] {
background: #0b0e14;
border-right: 1px solid var(--border-soft);
}
[data-testid="stSidebar"] > div:first-child {
background: #0b0e14;
}
[data-testid="stSidebar"] h2, [data-testid="stSidebar"] h3 { color: var(--text-primary); font-weight: 600; }
[data-testid="stSidebar"] label, [data-testid="stSidebar"] p { color: var(--text-secondary); font-size: 0.9rem; }
[data-testid="stSidebar"] [data-baseweb="radio"] > div { gap: 0.45rem; }
[data-testid="stSidebar"] [role="radiogroup"] label {
background:
linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0)),
linear-gradient(135deg, rgba(50,215,255,0.03), rgba(125,107,255,0.03) 52%, rgba(255,83,181,0.04)),
var(--bg-tertiary);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 8px;
padding: 0.7rem 0.8rem;
transition: all 0.15s ease;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.025);
pointer-events: auto !important;
}
[data-testid="stSidebar"] [role="radiogroup"] label:hover {
border-color: rgba(125, 107, 255, 0.22);
background:
linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0)),
linear-gradient(135deg, rgba(50,215,255,0.05), rgba(125,107,255,0.04) 52%, rgba(255,83,181,0.06)),
var(--bg-elevated);
transform: translateY(-1px);
}
[data-testid="stSidebar"] [role="radiogroup"] label[data-checked="true"] {
border-color: rgba(125, 107, 255, 0.34);
box-shadow:
inset 0 0 0 1px rgba(125, 107, 255, 0.16),
0 0 0 1px rgba(255, 83, 181, 0.06),
0 0 30px rgba(125, 107, 255, 0.10);
}
h1, h2, h3, h4 { color: var(--text-primary); }
h1 { font-weight: 800; font-size: 1.7rem; margin: 0; }
h2 { font-weight: 600; font-size: 1.4rem; margin: 1.2rem 0 0.8rem 0; }
h3 { font-weight: 600; font-size: 1.1rem; margin: 1rem 0 0.6rem 0; }
h4 { font-weight: 500; font-size: 1rem; margin: 0.8rem 0 0.4rem 0; }
p { color: var(--text-secondary); line-height: 1.5; }
div[data-testid="stSelectbox"] [data-baseweb="select"] {
background:
linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0)),
linear-gradient(135deg, rgba(50,215,255,0.03), rgba(125,107,255,0.03) 50%, rgba(255,83,181,0.03)),
var(--bg-tertiary) !important;
border: 1px solid rgba(255,255,255,0.08) !important;
border-radius: 8px !important;
min-height: 48px;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}
div[data-baseweb="popover"] ul {
background: #111621 !important;
border: 1px solid rgba(255,255,255,0.08) !important;
border-radius: 8px !important;
}
div[data-testid="stDataFrame"] {
background-color: var(--bg-tertiary) !important;
border: 1px solid rgba(255,255,255,0.08) !important;
border-radius: 8px !important;
box-shadow: var(--glow);
}
div[data-testid="stDataFrameRowHeaderCell"] { background-color: var(--bg-secondary) !important; }
[data-testid="stMetric"] {
background:
radial-gradient(circle at top right, rgba(255,83,181,0.13), transparent 26%),
radial-gradient(circle at 22% 10%, rgba(50,215,255,0.12), transparent 24%),
radial-gradient(circle at 50% 0%, rgba(125,107,255,0.10), transparent 18%),
linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)),
var(--bg-tertiary);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 8px;
padding: 1.1rem 1.2rem;
box-shadow: var(--shadow);
}
[data-testid="stMetricLabel"] p {
color: var(--text-secondary);
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
}
[data-testid="stMetricValue"] { color: var(--text-primary); font-size: 1.7rem; font-weight: 700; margin-top: 0.4rem; }
[data-testid="stAlert"] {
background:
linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)),
var(--bg-tertiary);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 8px;
color: var(--text-secondary);
}
[data-testid="stTabs"] [data-baseweb="tab"] {
background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)), transparent;
border: 1px solid transparent;
border-radius: 8px 8px 0 0;
color: var(--text-secondary);
font-weight: 600;
padding: 0.75rem 1rem;
}
# [data-testid="stTabs"] [aria-selected="true"] {
color: var(--text-primary);
border: 1px solid rgba(125, 107, 255, 0.28) !important;
background:
linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0)),
linear-gradient(135deg, rgba(50,215,255,0.06), rgba(125,107,255,0.07) 55%, rgba(255,83,181,0.08)),
var(--bg-tertiary);
box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), 0 0 26px rgba(125,107,255,0.08);
}
[data-testid="stTabs"] button p { font-weight: 600; color: inherit; }
[data-testid="stColumnBlock"] { gap: 1rem; }
.stDivider { margin: 1.5rem 0; border-color: var(--border) !important; }
hr { background-color: var(--border); border: none; height: 1px; }
.topbar {
height: 68px;
background:
radial-gradient(circle at 82% 18%, rgba(255,83,181,0.16), transparent 20%),
radial-gradient(circle at 18% 18%, rgba(50,215,255,0.10), transparent 20%),
radial-gradient(circle at 50% -10%, rgba(125,107,255,0.10), transparent 22%),
linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0)),
#0f131a;
border: 1px solid rgba(255,255,255,0.08);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 1rem 0 1.1rem;
margin-bottom: 1rem;
box-shadow: var(--shadow);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.7rem; }
.topbar-search {
min-width: 280px;
height: 38px;
border-radius: 999px;
background:
linear-gradient(135deg, rgba(50,215,255,0.04), rgba(125,107,255,0.04) 55%, rgba(255,83,181,0.05)),
rgba(255,255,255,0.03);
border: 1px solid rgba(255,255,255,0.07);
color: var(--text-dim);
display: flex;
align-items: center;
padding: 0 1rem;
font-size: 0.84rem;
font-weight: 500;
}
.topbar-icon, .topbar-chip {
border-radius: 8px;
background:
linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0)),
linear-gradient(135deg, rgba(50,215,255,0.04), rgba(125,107,255,0.04) 55%, rgba(255,83,181,0.04)),
var(--bg-tertiary);
border: 1px solid rgba(255,255,255,0.08);
box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
}
.topbar-icon {
width: 34px;
height: 34px;
display: inline-flex;
align-items: center;
justify-content: center;
color: var(--text-secondary);
font-size: 0.82rem;
font-weight: 700;
}
.topbar-brand {
width: 34px;
height: 34px;
border-radius: 8px;
background: linear-gradient(135deg, var(--accent), var(--accent-2) 48%, var(--accent-3) 76%, var(--accent-4));
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 0.95rem;
font-weight: 800;
box-shadow: 0 12px 28px rgba(125, 107, 255, 0.26);
}
.topbar-title { color: var(--text-primary); font-size: 0.96rem; font-weight: 700; }
.topbar-subtitle { color: var(--text-dim); font-size: 0.8rem; margin-top: 0.15rem; }
.topbar-chip {
height: 34px;
min-width: 36px;
padding: 0 0.9rem;
color: var(--text-secondary);
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 0.84rem;
font-weight: 600;
}
.topbar-chip.primary {
color: #070a11;
background: linear-gradient(135deg, var(--accent), var(--accent-2) 48%, var(--accent-3) 76%, var(--accent-4));
border-color: transparent;
box-shadow: 0 12px 28px rgba(125, 107, 255, 0.22);
}
.hero {
background:
radial-gradient(circle at 78% 22%, rgba(255,83,181,0.16), transparent 22%),
radial-gradient(circle at 14% 12%, rgba(50,215,255,0.16), transparent 22%),
radial-gradient(circle at 50% -10%, rgba(125,107,255,0.12), transparent 24%),
linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)),
var(--bg-secondary);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 8px;
padding: 1.25rem 1.3rem;
margin-bottom: 1rem;
box-shadow: var(--shadow);
}
.eyebrow {
color: var(--accent);
font-size: 0.76rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.06em;
margin-bottom: 0.35rem;
}
.hero h1 { font-size: 2.08rem; font-weight: 800; color: var(--text-primary); margin-bottom: 0.45rem; }
.hero p { max-width: 760px; color: var(--text-secondary); font-size: 0.96rem; }
.method-card, .paper-card, .metrics-card, .map-frame {
background:
linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)),
linear-gradient(135deg, rgba(50,215,255,0.025), rgba(125,107,255,0.025) 55%, rgba(255,83,181,0.03)),
var(--bg-secondary);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 8px;
box-shadow: var(--shadow);
}
.method-card { padding: 0.95rem 1rem; margin-bottom: 1rem; color: var(--text-secondary); }
.method-card strong { color: var(--text-primary); }
.map-frame {
padding: 0.55rem;
margin-bottom: 1rem;
background:
linear-gradient(180deg, rgba(255,255,255,0.018), rgba(255,255,255,0)),
linear-gradient(135deg, rgba(50,215,255,0.04), rgba(125,107,255,0.03) 50%, rgba(255,83,181,0.04)),
var(--bg-secondary);
}
.paper-card { padding: 1rem 1.1rem; margin-bottom: 1rem; }
.paper-card h2 { margin: 0 0 0.9rem 0; font-size: 1.15rem; }
.paper-card h3 { margin: 1rem 0 0.5rem 0; font-size: 1rem; }
.paper-card p, .paper-card li { color: var(--text-secondary); line-height: 1.7; font-size: 0.95rem; }
.paper-card ul { padding-left: 1.1rem; margin: 0.55rem 0 0.8rem 0; }
.paper-card .authors { color: var(--text-primary); font-weight: 600; margin-bottom: 1rem; }
.metrics-card { padding: 1rem 1.05rem; margin-bottom: 1rem; }
.metrics-card h3 { margin-top: 0; }
.small-note { color: var(--text-dim); font-size: 0.82rem; line-height: 1.55; }
.sidebar-section-label {
color: var(--text-dim);
font-size: 0.74rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.08em;
margin: 0.3rem 0 0.8rem 0;
}
.stPlotlyChart, div[data-testid="stPlotlyChart"] { border-radius: 8px; overflow: hidden; }
.stButton button, .stDownloadButton button {
border-radius: 8px !important;
background:
linear-gradient(135deg, rgba(50,215,255,0.14), rgba(125,107,255,0.16) 55%, rgba(255,83,181,0.16)),
#141927 !important;
color: #f7f9fc !important;
border: 1px solid rgba(255,255,255,0.10) !important;
font-weight: 600 !important;
box-shadow: 0 12px 28px rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.03);
}
</style>
""",
unsafe_allow_html=True,
)
COUNTRIES = [
"Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda",
"Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", "Bahamas",
"Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
"Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei",
"Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", "Cameroon",
"Canada", "Central African Republic", "Chad", "Chile", "China", "Colombia",
"Comoros", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus",
"Czechia", "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica",
"Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea",
"Eritrea", "Estonia", "Eswatini", "Ethiopia", "Fiji", "Finland", "France",
"Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada",
"Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hungary",
"Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy",
"Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait",
"Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya",
"Liechtenstein", "Lithuania", "Luxembourg", "Madagascar", "Malawi", "Malaysia",
"Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius",
"Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco",
"Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands",
"New Zealand", "Nicaragua", "Niger", "Nigeria", "North Korea", "North Macedonia",
"Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay",
"Peru", "Philippines", "Poland", "Portugal", "Qatar", "Romania", "Russia",
"Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines",
"Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia",
"Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia",
"Solomon Islands", "Somalia", "South Africa", "South Korea", "South Sudan",
"Spain", "Sri Lanka", "Sudan", "Suriname", "Sweden", "Switzerland", "Syria",
"Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tonga",
"Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda",
"Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay",
"Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe",
"Palestine", "Taiwan", "Kosovo", "Western Sahara", "Hong Kong", "Macau", "Vatican City",
"Puerto Rico",
]
COMMODITIES = ["Grains", "Coal", "Semiconductors", "Petrol", "Fertilizer"]
TRANSPORT_MODES = ["Sea", "Rail", "Road", "Pipeline", "Air"]
@dataclass(frozen=True)
class TensionEdge:
source: str
target: str
intensity: int
note: str
@dataclass(frozen=True)
class TradeFlow:
exporter: str
importer: str
commodity: str
modes: tuple[str, ...]
note: str
SEED_TENSIONS = [
TensionEdge("Russia", "Ukraine", 5, "Full-scale interstate war."),
TensionEdge("Israel", "Palestine", 5, "Gaza/West Bank conflict."),
TensionEdge("Israel", "Iran", 5, "Direct and proxy confrontation."),
TensionEdge("United States", "Iran", 5, "Direct military confrontation and escalation risk."),
TensionEdge("Israel", "Lebanon", 4, "Cross-border conflict involving Hezbollah."),
TensionEdge("Israel", "Syria", 4, "Repeated strikes and spillover risk."),
TensionEdge("Turkey", "Syria", 4, "Border and northern Syria military operations."),
TensionEdge("India", "Pakistan", 4, "Kashmir and border crisis risk."),
TensionEdge("China", "Taiwan", 4, "Cross-strait military pressure."),
TensionEdge("China", "Philippines", 4, "South China Sea incidents."),
TensionEdge("China", "India", 3, "Himalayan border standoff risk."),
TensionEdge("North Korea", "South Korea", 4, "Korean peninsula escalation risk."),
TensionEdge("Azerbaijan", "Armenia", 3, "Nagorno-Karabakh and border settlement risk."),
TensionEdge("Serbia", "Kosovo", 3, "Northern Kosovo and recognition disputes."),
TensionEdge("Morocco", "Western Sahara", 3, "Western Sahara status conflict."),
TensionEdge("Democratic Republic of the Congo", "Rwanda", 4, "Eastern DRC conflict and M23 accusations."),
TensionEdge("Ethiopia", "Eritrea", 3, "Post-Tigray and Red Sea security concerns."),
TensionEdge("Ethiopia", "Somalia", 3, "Port access and Somaliland dispute."),
TensionEdge("Venezuela", "Guyana", 3, "Essequibo territorial dispute."),
TensionEdge("United States", "Russia", 4, "Ukraine war and strategic confrontation."),
TensionEdge("United States", "China", 4, "Taiwan, trade, and military competition."),
TensionEdge("Greece", "Turkey", 2, "Aegean and eastern Mediterranean disputes."),
TensionEdge("Egypt", "Ethiopia", 3, "Nile/GERD dispute."),
TensionEdge("Saudi Arabia", "Yemen", 3, "Yemen conflict and border/drone risk."),
TensionEdge("Iran", "Saudi Arabia", 3, "Gulf security and proxy competition."),
TensionEdge("Qatar", "Iran", 2, "Gulf maritime and regional security tension."),
TensionEdge("United Arab Emirates", "Iran", 3, "Gulf islands and shipping security tension."),
TensionEdge("Iraq", "Iran", 2, "Border, militia, and regional security pressure."),
TensionEdge("Syria", "Iraq", 2, "Militant movement and border insecurity."),
TensionEdge("Lebanon", "Syria", 2, "Border and armed group spillover."),
TensionEdge("Sudan", "Chad", 3, "Civil-war spillover and refugee pressure."),
TensionEdge("Mali", "Niger", 2, "Shared Sahel insurgency theater."),
TensionEdge("Mali", "Burkina Faso", 2, "Shared Sahel insurgency theater."),
TensionEdge("Niger", "Nigeria", 2, "Lake Chad and Sahel militant movement."),
TensionEdge("Colombia", "Venezuela", 2, "Border armed groups and political tension."),
TensionEdge("United States", "Venezuela", 3, "Sanctions and military pressure risk."),
TensionEdge("Japan", "China", 3, "East China Sea maritime dispute."),
TensionEdge("Japan", "Russia", 2, "Kuril/Northern Territories dispute."),
TensionEdge("Cyprus", "Turkey", 2, "Northern Cyprus and maritime claims."),
TensionEdge("United States", "North Korea", 4, "Nuclear and missile threat escalation."),
TensionEdge("China", "Vietnam", 3, "South China Sea and land border disputes."),
TensionEdge("Turkey", "Armenia", 3, "Genocide recognition and border tensions."),
TensionEdge("Georgia", "Russia", 3, "Abkhazia and South Ossetia occupation."),
TensionEdge("Ukraine", "Belarus", 3, "Military cooperation and border tensions."),
TensionEdge("Poland", "Belarus", 2, "Border migrant crisis and sanctions."),
TensionEdge("Lithuania", "Belarus", 2, "Border migrant crisis and sanctions."),
TensionEdge("Estonia", "Russia", 3, "NATO border and cyber tensions."),
TensionEdge("Latvia", "Russia", 3, "NATO border and cyber tensions."),
TensionEdge("Finland", "Russia", 3, "NATO membership and border tensions."),
TensionEdge("Sweden", "Russia", 3, "NATO membership and border tensions."),
TensionEdge("United Kingdom", "Russia", 3, "Ukraine support and sanctions."),
TensionEdge("France", "Russia", 3, "Ukraine support and sanctions."),
TensionEdge("Germany", "Russia", 3, "Ukraine support and sanctions."),
TensionEdge("Italy", "Russia", 3, "Ukraine support and sanctions."),
TensionEdge("Spain", "Russia", 3, "Ukraine support and sanctions."),
TensionEdge("Netherlands", "Russia", 3, "Ukraine support and sanctions."),
TensionEdge("Belgium", "Russia", 3, "Ukraine support and sanctions."),
TensionEdge("Denmark", "Russia", 3, "Ukraine support and sanctions."),
TensionEdge("Norway", "Russia", 3, "Ukraine support and sanctions."),
TensionEdge("Canada", "Russia", 3, "Ukraine support and sanctions."),
TensionEdge("Australia", "China", 3, "Trade disputes and military presence."),
TensionEdge("New Zealand", "China", 2, "Trade and regional security."),
TensionEdge("South Korea", "China", 3, "THAAD deployment and trade tensions."),
TensionEdge("Hong Kong", "China", 4, "Autonomy and democracy protests."),
TensionEdge("Macau", "China", 2, "Autonomy issues."),
TensionEdge("United Kingdom", "China", 3, "Hong Kong and Xinjiang issues."),
TensionEdge("France", "China", 3, "Taiwan and human rights."),
TensionEdge("Germany", "China", 3, "Trade and human rights."),
TensionEdge("Italy", "China", 3, "Belt and Road investments."),
TensionEdge("Spain", "China", 2, "Regional influence."),
TensionEdge("Netherlands", "China", 3, "Semiconductor export controls."),
TensionEdge("Belgium", "China", 2, "Regional influence."),
TensionEdge("Denmark", "China", 2, "Regional influence."),
TensionEdge("Norway", "China", 2, "Regional influence."),
TensionEdge("Canada", "China", 3, "Huawei and trade disputes."),
# Added 2024-2026 Conflicts
TensionEdge("Sudan", "Egypt", 3, "Sudan civil war spillover and RSF backing."),
TensionEdge("Sudan", "Chad", 4, "Cross-border militant movement and refugee crisis."),
TensionEdge("Sudan", "United Arab Emirates", 4, "Accusations of RSF backing."),
TensionEdge("Ethiopia", "Somalia", 4, "Somaliland port deal and sovereignty dispute."),
TensionEdge("Niger", "France", 4, "Post-coup expulsion of military forces."),
TensionEdge("Mali", "France", 4, "Post-coup tensions and withdrawal."),
TensionEdge("Burkina Faso", "France", 4, "Post-coup tensions and withdrawal."),
TensionEdge("Venezuela", "Guyana", 4, "Essequibo territorial annexation threat."),
TensionEdge("Iran", "Israel", 5, "Direct military escalation and missile exchanges."),
TensionEdge("Yemen", "United States", 4, "Houthi Red Sea attacks and US strikes."),
TensionEdge("Yemen", "United Kingdom", 4, "Houthi Red Sea attacks and UK strikes."),
TensionEdge("Myanmar", "Thailand", 3, "Civil war spillover and border clashes."),
TensionEdge("Myanmar", "China", 3, "Border security and rebel backing."),
TensionEdge("Democratic Republic of the Congo", "Rwanda", 5, "M23 rebellion and direct border skirmishes."),
TensionEdge("Philippines", "China", 4, "Second Thomas Shoal blockades and clashes."),
TensionEdge("Ecuador", "Mexico", 3, "Embassy raid and diplomatic severing."),
TensionEdge("Haiti", "Dominican Republic", 3, "Border closure due to gang violence spillover."),
]
SEED_TRADE_FLOWS = [
# Petrol (Oil) - 40 routes
TradeFlow("Russia", "China", "Petrol", ("Pipeline", "Rail", "Sea"), "Major oil and refined-products route."),
TradeFlow("Saudi Arabia", "China", "Petrol", ("Sea",), "Major Gulf-to-Asia oil route."),
TradeFlow("Saudi Arabia", "India", "Petrol", ("Sea",), "Major Gulf-to-India oil route."),
TradeFlow("Saudi Arabia", "Japan", "Petrol", ("Sea",), "Major Gulf-to-East Asia oil route."),
TradeFlow("Iraq", "China", "Petrol", ("Sea",), "Crude oil route through Gulf shipping lanes."),
TradeFlow("Canada", "United States", "Petrol", ("Pipeline", "Rail", "Road"), "North American oil route."),
TradeFlow("United States", "Mexico", "Petrol", ("Pipeline", "Road", "Sea"), "Regional refined-products route."),
TradeFlow("Norway", "Germany", "Petrol", ("Pipeline", "Sea"), "European petroleum route."),
TradeFlow("Kazakhstan", "China", "Petrol", ("Pipeline", "Rail"), "Central Asia-to-China energy route."),
TradeFlow("Qatar", "Japan", "Petrol", ("Sea",), "Qatari oil to Japan."),
TradeFlow("Qatar", "South Korea", "Petrol", ("Sea",), "Qatari oil to South Korea."),
TradeFlow("United States", "Japan", "Petrol", ("Sea",), "US oil to Japan."),
TradeFlow("Australia", "Japan", "Petrol", ("Sea",), "Australian oil to Japan."),
TradeFlow("Australia", "South Korea", "Petrol", ("Sea",), "Australian oil to South Korea."),
TradeFlow("United Arab Emirates", "India", "Petrol", ("Sea",), "UAE oil to India."),
TradeFlow("Kuwait", "South Korea", "Petrol", ("Sea",), "Kuwaiti oil to South Korea."),
TradeFlow("Iran", "China", "Petrol", ("Sea",), "Iranian oil to China."),
TradeFlow("Nigeria", "United States", "Petrol", ("Sea",), "Nigerian oil to US."),
TradeFlow("Nigeria", "Netherlands", "Petrol", ("Sea",), "Nigerian oil to Europe."),
TradeFlow("Angola", "China", "Petrol", ("Sea",), "Angolan oil to China."),
TradeFlow("Angola", "India", "Petrol", ("Sea",), "Angolan oil to India."),
TradeFlow("Venezuela", "China", "Petrol", ("Sea",), "Venezuelan oil to China."),
TradeFlow("Venezuela", "United States", "Petrol", ("Sea",), "Venezuelan oil to US."),
TradeFlow("Algeria", "Italy", "Petrol", ("Sea",), "Algerian oil to Italy."),
TradeFlow("Algeria", "Spain", "Petrol", ("Sea",), "Algerian oil to Spain."),
TradeFlow("Libya", "Italy", "Petrol", ("Sea",), "Libyan oil to Italy."),
TradeFlow("Egypt", "Germany", "Petrol", ("Sea",), "Egyptian oil to Germany."),
TradeFlow("Oman", "India", "Petrol", ("Sea",), "Omani oil to India."),
TradeFlow("Oman", "China", "Petrol", ("Sea",), "Omani oil to China."),
TradeFlow("Azerbaijan", "Italy", "Petrol", ("Sea",), "Azerbaijani oil to Italy."),
TradeFlow("Azerbaijan", "Turkey", "Petrol", ("Sea",), "Azerbaijani oil to Turkey."),
TradeFlow("Turkmenistan", "China", "Petrol", ("Pipeline",), "Turkmen oil to China."),
TradeFlow("Uzbekistan", "China", "Petrol", ("Pipeline",), "Uzbek oil to China."),
TradeFlow("Mexico", "United States", "Petrol", ("Pipeline", "Sea"), "Mexican oil to US."),
TradeFlow("Brazil", "United States", "Petrol", ("Sea",), "Brazilian oil to US."),
TradeFlow("Colombia", "United States", "Petrol", ("Sea",), "Colombian oil to US."),
TradeFlow("Ecuador", "United States", "Petrol", ("Sea",), "Ecuadorian oil to US."),
TradeFlow("Peru", "China", "Petrol", ("Sea",), "Peruvian oil to China."),
TradeFlow("Peru", "United States", "Petrol", ("Sea",), "Peruvian oil to US."),
TradeFlow("United Kingdom", "Netherlands", "Petrol", ("Sea",), "UK oil to Netherlands."),
TradeFlow("United Kingdom", "Germany", "Petrol", ("Sea",), "UK oil to Germany."),
# Coal - 35 routes
TradeFlow("Australia", "Japan", "Coal", ("Sea",), "Australian coal to Japan."),
TradeFlow("Australia", "South Korea", "Coal", ("Sea",), "Australian coal to South Korea."),
TradeFlow("Australia", "China", "Coal", ("Sea",), "Australian coal to China."),
TradeFlow("Australia", "India", "Coal", ("Sea",), "Australian coal to India."),
TradeFlow("Indonesia", "China", "Coal", ("Sea",), "Indonesian coal to China."),
TradeFlow("Indonesia", "India", "Coal", ("Sea",), "Indonesian coal to India."),
TradeFlow("Indonesia", "Japan", "Coal", ("Sea",), "Indonesian coal to Japan."),
TradeFlow("Indonesia", "South Korea", "Coal", ("Sea",), "Indonesian coal to South Korea."),
TradeFlow("Russia", "China", "Coal", ("Rail", "Sea"), "Russian coal to China."),
TradeFlow("Russia", "Japan", "Coal", ("Sea",), "Russian coal to Japan."),
TradeFlow("Russia", "South Korea", "Coal", ("Sea",), "Russian coal to South Korea."),
TradeFlow("United States", "Japan", "Coal", ("Sea",), "US coal to Japan."),
TradeFlow("United States", "South Korea", "Coal", ("Sea",), "US coal to South Korea."),
TradeFlow("Colombia", "Europe", "Coal", ("Sea",), "Colombian coal to Europe."),
TradeFlow("South Africa", "India", "Coal", ("Sea",), "South African coal to India."),
TradeFlow("South Africa", "China", "Coal", ("Sea",), "South African coal to China."),
TradeFlow("Canada", "Japan", "Coal", ("Sea",), "Canadian coal to Japan."),
TradeFlow("Canada", "South Korea", "Coal", ("Sea",), "Canadian coal to South Korea."),
TradeFlow("Poland", "Germany", "Coal", ("Rail", "Sea"), "Polish coal to Germany."),
TradeFlow("Poland", "Ukraine", "Coal", ("Rail",), "Polish coal to Ukraine."),
TradeFlow("Kazakhstan", "China", "Coal", ("Rail",), "Kazakh coal to China."),
TradeFlow("Kazakhstan", "Russia", "Coal", ("Rail",), "Kazakh coal to Russia."),
TradeFlow("Mongolia", "China", "Coal", ("Rail",), "Mongolian coal to China."),
TradeFlow("Vietnam", "China", "Coal", ("Sea",), "Vietnamese coal to China."),
TradeFlow("Vietnam", "Japan", "Coal", ("Sea",), "Vietnamese coal to Japan."),
TradeFlow("Mozambique", "India", "Coal", ("Sea",), "Mozambican coal to India."),
TradeFlow("Mozambique", "China", "Coal", ("Sea",), "Mozambican coal to China."),
TradeFlow("Botswana", "India", "Coal", ("Sea",), "Botswana coal to India."),
TradeFlow("Botswana", "China", "Coal", ("Sea",), "Botswana coal to China."),
TradeFlow("Zimbabwe", "China", "Coal", ("Sea",), "Zimbabwe coal to China."),
TradeFlow("Zimbabwe", "India", "Coal", ("Sea",), "Zimbabwe coal to India."),
TradeFlow("Turkey", "Europe", "Coal", ("Sea",), "Turkish coal to Europe."),
TradeFlow("Greece", "Italy", "Coal", ("Sea",), "Greek coal to Italy."),
TradeFlow("Bulgaria", "Turkey", "Coal", ("Sea",), "Bulgarian coal to Turkey."),
TradeFlow("Serbia", "Bosnia", "Coal", ("Rail",), "Serbian coal to Bosnia."),
TradeFlow("Ukraine", "Poland", "Coal", ("Rail",), "Ukrainian coal to Poland."),
TradeFlow("Ukraine", "Slovakia", "Coal", ("Rail",), "Ukrainian coal to Slovakia."),
TradeFlow("Russia", "Japan", "Coal", ("Sea",), "Russian coal to Japan."),
TradeFlow("Russia", "South Korea", "Coal", ("Sea",), "Russian coal to South Korea."),
TradeFlow("Canada", "Japan", "Coal", ("Sea",), "Canadian coal to Japan."),
TradeFlow("Canada", "South Korea", "Coal", ("Sea",), "Canadian coal to South Korea."),
TradeFlow("Australia", "India", "Coal", ("Sea",), "Australian coal to India."),
# Grains - 30 routes
TradeFlow("Ukraine", "Egypt", "Grains", ("Sea",), "Black Sea grain route."),
TradeFlow("Ukraine", "Turkey", "Grains", ("Sea", "Rail"), "Black Sea grain route."),
TradeFlow("Russia", "Turkey", "Grains", ("Sea", "Rail"), "Black Sea grain route."),
TradeFlow("United States", "Mexico", "Grains", ("Rail", "Road"), "North American grain route."),
TradeFlow("United States", "Japan", "Grains", ("Sea",), "Pacific grain route."),
TradeFlow("Brazil", "China", "Grains", ("Sea",), "Major soybean/corn route."),
TradeFlow("Argentina", "China", "Grains", ("Sea",), "South America-to-China grain route."),
TradeFlow("India", "Bangladesh", "Grains", ("Road", "Rail", "Sea"), "Regional grain route."),
TradeFlow("Vietnam", "Philippines", "Grains", ("Sea",), "Regional rice/grain route."),
TradeFlow("United States", "China", "Grains", ("Sea",), "US grain to China."),
TradeFlow("United States", "South Korea", "Grains", ("Sea",), "US grain to South Korea."),
TradeFlow("United States", "Egypt", "Grains", ("Sea",), "US grain to Egypt."),
TradeFlow("United States", "Saudi Arabia", "Grains", ("Sea",), "US grain to Saudi Arabia."),
TradeFlow("Canada", "China", "Grains", ("Sea",), "Canadian grain to China."),
TradeFlow("Canada", "Japan", "Grains", ("Sea",), "Canadian grain to Japan."),
TradeFlow("Australia", "China", "Grains", ("Sea",), "Australian grain to China."),
TradeFlow("Australia", "Indonesia", "Grains", ("Sea",), "Australian grain to Indonesia."),
TradeFlow("Ukraine", "China", "Grains", ("Sea",), "Ukrainian grain to China."),
TradeFlow("Ukraine", "India", "Grains", ("Sea",), "Ukrainian grain to India."),
TradeFlow("Russia", "China", "Grains", ("Rail", "Sea"), "Russian grain to China."),
TradeFlow("Russia", "India", "Grains", ("Sea",), "Russian grain to India."),
TradeFlow("Kazakhstan", "China", "Grains", ("Rail",), "Kazakh grain to China."),
TradeFlow("Kazakhstan", "Turkey", "Grains", ("Rail",), "Kazakh grain to Turkey."),
TradeFlow("France", "Algeria", "Grains", ("Sea",), "French grain to Algeria."),
TradeFlow("France", "Morocco", "Grains", ("Sea",), "French grain to Morocco."),
TradeFlow("Germany", "Netherlands", "Grains", ("Road", "Rail"), "German grain to Netherlands."),
TradeFlow("Thailand", "Vietnam", "Grains", ("Sea",), "Thai rice to Vietnam."),
TradeFlow("Thailand", "Philippines", "Grains", ("Sea",), "Thai rice to Philippines."),
TradeFlow("Pakistan", "Bangladesh", "Grains", ("Sea",), "Pakistani grain to Bangladesh."),
TradeFlow("Pakistan", "Sri Lanka", "Grains", ("Sea",), "Pakistani grain to Sri Lanka."),
# Semiconductors - 30 routes (realistic Air/Sea mix based on value/urgency)
TradeFlow("Taiwan", "United States", "Semiconductors", ("Air", "Sea"), "Time-sensitive and bulk routes for US demand."),
TradeFlow("Taiwan", "China", "Semiconductors", ("Sea",), "Cost-optimized bulk commodity chip shipments."),
TradeFlow("South Korea", "China", "Semiconductors", ("Sea",), "Standard component sea freight via Busan."),
TradeFlow("South Korea", "United States", "Semiconductors", ("Air",), "Urgent memory chips and premium processors."),
TradeFlow("Japan", "United States", "Semiconductors", ("Air",), "High-value logic chips and advanced components."),
TradeFlow("Netherlands", "Taiwan", "Semiconductors", ("Air",), "Lithography equipment for TSMC - urgent."),
TradeFlow("Germany", "China", "Semiconductors", ("Sea",), "Bulk semiconductor manufacturing equipment."),
TradeFlow("Taiwan", "Japan", "Semiconductors", ("Air",), "Advanced chip orders require rapid delivery."),
TradeFlow("Taiwan", "South Korea", "Semiconductors", ("Air",), "Inter-Asian urgent semiconductor trade."),
TradeFlow("Taiwan", "Germany", "Semiconductors", ("Sea",), "European bulk orders via Suez Canal."),
TradeFlow("Taiwan", "United Kingdom", "Semiconductors", ("Sea",), "UK market through Mediterranean/Atlantic route."),
TradeFlow("South Korea", "Japan", "Semiconductors", ("Air",), "Regional rush orders and critical stock."),
TradeFlow("South Korea", "Germany", "Semiconductors", ("Sea",), "Container ship through Suez to Europe."),
TradeFlow("South Korea", "United Kingdom", "Semiconductors", ("Sea",), "Weekly container service to UK ports."),
TradeFlow("Japan", "Germany", "Semiconductors", ("Sea",), "Slow steaming trans-Pacific via Suez route."),
TradeFlow("Japan", "United Kingdom", "Semiconductors", ("Sea",), "Bulk container shipment to UK/Netherlands."),
TradeFlow("Netherlands", "United States", "Semiconductors", ("Air",), "Critical fab equipment and precision components."),
TradeFlow("Netherlands", "China", "Semiconductors", ("Sea",), "Large equipment shipments via Rotterdam port."),
TradeFlow("Germany", "United States", "Semiconductors", ("Air",), "High-value precision semiconductor equipment."),
TradeFlow("Germany", "Japan", "Semiconductors", ("Air",), "Equipment replacement and spare parts rush."),
TradeFlow("Malaysia", "United States", "Semiconductors", ("Air",), "Assembly/test facility products - air priority."),
TradeFlow("Malaysia", "China", "Semiconductors", ("Sea",), "Regional bulk shipments via South China Sea."),
TradeFlow("Singapore", "United States", "Semiconductors", ("Air",), "Hub consolidation center - air-only export."),
TradeFlow("Singapore", "China", "Semiconductors", ("Sea",), "Transhipment via Singapore port to China."),
TradeFlow("Philippines", "United States", "Semiconductors", ("Air",), "Fab outputs direct to US customer centers."),
TradeFlow("Philippines", "China", "Semiconductors", ("Sea",), "Container consolidation in South China Sea."),
TradeFlow("China", "United States", "Semiconductors", ("Sea",), "Commodity chips via TransPac container lines."),
TradeFlow("China", "Japan", "Semiconductors", ("Air",), "Premium automotive chip components urgent."),
TradeFlow("Israel", "United States", "Semiconductors", ("Air",), "High-tech fabless chip design outputs."),
TradeFlow("Israel", "Europe", "Semiconductors", ("Sea",), "Mediterranean route via Suez Canal to EU ports."),
# Fertilizer - 30 routes
TradeFlow("Russia", "Brazil", "Fertilizer", ("Sea",), "Fertilizer route exposed to war and sanctions."),
TradeFlow("Russia", "India", "Fertilizer", ("Sea", "Rail"), "Fertilizer route exposed to war and sanctions."),
TradeFlow("Belarus", "Brazil", "Fertilizer", ("Rail", "Sea"), "Potash route exposed to sanctions and regional war."),
TradeFlow("Canada", "India", "Fertilizer", ("Sea",), "Potash route."),
TradeFlow("Morocco", "India", "Fertilizer", ("Sea",), "Phosphate fertilizer route."),
TradeFlow("Morocco", "Brazil", "Fertilizer", ("Sea",), "Phosphate fertilizer route."),
TradeFlow("Saudi Arabia", "India", "Fertilizer", ("Sea",), "Ammonia/urea fertilizer route."),
TradeFlow("Qatar", "India", "Fertilizer", ("Sea",), "Ammonia/urea fertilizer route."),
TradeFlow("China", "Pakistan", "Fertilizer", ("Road", "Rail", "Sea"), "Regional fertilizer route."),
TradeFlow("Russia", "China", "Fertilizer", ("Rail", "Sea"), "Russian fertilizer to China."),
TradeFlow("Russia", "United States", "Fertilizer", ("Sea",), "Russian fertilizer to US."),
TradeFlow("Belarus", "India", "Fertilizer", ("Sea",), "Belarusian fertilizer to India."),
TradeFlow("Belarus", "China", "Fertilizer", ("Rail", "Sea"), "Belarusian fertilizer to China."),
TradeFlow("Canada", "China", "Fertilizer", ("Sea",), "Canadian fertilizer to China."),
TradeFlow("Canada", "Brazil", "Fertilizer", ("Sea",), "Canadian fertilizer to Brazil."),
TradeFlow("Morocco", "China", "Fertilizer", ("Sea",), "Moroccan fertilizer to China."),
TradeFlow("Morocco", "United States", "Fertilizer", ("Sea",), "Moroccan fertilizer to US."),
TradeFlow("Saudi Arabia", "China", "Fertilizer", ("Sea",), "Saudi fertilizer to China."),
TradeFlow("Saudi Arabia", "Brazil", "Fertilizer", ("Sea",), "Saudi fertilizer to Brazil."),
TradeFlow("Qatar", "China", "Fertilizer", ("Sea",), "Qatari fertilizer to China."),
TradeFlow("Qatar", "Brazil", "Fertilizer", ("Sea",), "Qatari fertilizer to Brazil."),
TradeFlow("Egypt", "India", "Fertilizer", ("Sea",), "Egyptian fertilizer to India."),
TradeFlow("Egypt", "China", "Fertilizer", ("Sea",), "Egyptian fertilizer to China."),
TradeFlow("Tunisia", "Italy", "Fertilizer", ("Sea",), "Tunisian fertilizer to Italy."),
TradeFlow("Tunisia", "Spain", "Fertilizer", ("Sea",), "Tunisian fertilizer to Spain."),
TradeFlow("Jordan", "India", "Fertilizer", ("Sea",), "Jordanian fertilizer to India."),
TradeFlow("Jordan", "Turkey", "Fertilizer", ("Sea",), "Jordanian fertilizer to Turkey."),
TradeFlow("Syria", "Lebanon", "Fertilizer", ("Road", "Rail"), "Syrian fertilizer to Lebanon."),
TradeFlow("Syria", "Jordan", "Fertilizer", ("Road", "Rail"), "Syrian fertilizer to Jordan."),
TradeFlow("Israel", "Turkey", "Fertilizer", ("Sea",), "Israeli fertilizer to Turkey."),
# More Petrol routes
TradeFlow("Iraq", "Japan", "Petrol", ("Sea",), "Iraqi oil to Japan."),
TradeFlow("Iran", "Japan", "Petrol", ("Sea",), "Iranian oil to Japan."),
TradeFlow("Kuwait", "Japan", "Petrol", ("Sea",), "Kuwaiti oil to Japan."),
TradeFlow("UAE", "Japan", "Petrol", ("Sea",), "UAE oil to Japan."),
TradeFlow("Saudi Arabia", "South Korea", "Petrol", ("Sea",), "Saudi oil to South Korea."),
# More Coal routes
TradeFlow("Qatar", "United States", "Coal", ("Sea",), "Qatari coal to US."),
TradeFlow("Australia", "United States", "Coal", ("Sea",), "Australian coal to US."),
TradeFlow("Russia", "United States", "Coal", ("Sea",), "Russian coal to US."),
TradeFlow("Canada", "United States", "Coal", ("Rail",), "Canadian coal to US."),
TradeFlow("Norway", "United States", "Coal", ("Sea",), "Norwegian coal to US."),
# More Grains routes
TradeFlow("United States", "Indonesia", "Grains", ("Sea",), "US grain to Indonesia."),
TradeFlow("Canada", "Indonesia", "Grains", ("Sea",), "Canadian grain to Indonesia."),
TradeFlow("Australia", "Egypt", "Grains", ("Sea",), "Australian grain to Egypt."),
TradeFlow("Ukraine", "Egypt", "Grains", ("Sea",), "Ukrainian grain to Egypt."),
TradeFlow("Russia", "Indonesia", "Grains", ("Sea",), "Russian grain to Indonesia."),
# More Semiconductors routes
TradeFlow("Taiwan", "Canada", "Semiconductors", ("Air", "Sea"), "Taiwanese chips to Canada."),
TradeFlow("South Korea", "Canada", "Semiconductors", ("Air", "Sea"), "Korean chips to Canada."),
TradeFlow("Japan", "Canada", "Semiconductors", ("Air", "Sea"), "Japanese chips to Canada."),
TradeFlow("Netherlands", "Canada", "Semiconductors", ("Air", "Sea"), "Dutch equipment to Canada."),
TradeFlow("Germany", "Canada", "Semiconductors", ("Air", "Sea"), "German equipment to Canada."),
# More Fertilizer routes
TradeFlow("Qatar", "Brazil", "Fertilizer", ("Sea",), "Qatari fertilizer to Brazil."),
TradeFlow("Saudi Arabia", "Brazil", "Fertilizer", ("Sea",), "Saudi fertilizer to Brazil."),
TradeFlow("Egypt", "Brazil", "Fertilizer", ("Sea",), "Egyptian fertilizer to Brazil."),
TradeFlow("Tunisia", "Brazil", "Fertilizer", ("Sea",), "Tunisian fertilizer to Brazil."),
TradeFlow("Jordan", "Brazil", "Fertilizer", ("Sea",), "Jordanian fertilizer to Brazil."),
# Semiconductors and High-Tech
TradeFlow("Taiwan", "United States", "Semiconductors", ("Air", "Sea"), "Advanced microchips to US tech sector."),
TradeFlow("Taiwan", "China", "Semiconductors", ("Air", "Sea"), "Microchips for Chinese manufacturing."),
TradeFlow("South Korea", "United States", "Semiconductors", ("Air", "Sea"), "Memory chips to US."),
TradeFlow("South Korea", "China", "Semiconductors", ("Air", "Sea"), "Memory chips to China."),
TradeFlow("Japan", "China", "Semiconductors", ("Air", "Sea"), "Chip manufacturing equipment and components."),
TradeFlow("Netherlands", "China", "Semiconductors", ("Air", "Sea"), "ASML lithography equipment (restricted)."),
# Critical Minerals & Metals
TradeFlow("Democratic Republic of the Congo", "China", "Critical Minerals", ("Sea",), "Cobalt for battery manufacturing."),
TradeFlow("Australia", "China", "Critical Minerals", ("Sea",), "Lithium and iron ore to China."),
TradeFlow("Chile", "United States", "Critical Minerals", ("Sea",), "Copper and Lithium to US."),
TradeFlow("Chile", "China", "Critical Minerals", ("Sea",), "Copper and Lithium to China."),
TradeFlow("Indonesia", "China", "Critical Minerals", ("Sea",), "Nickel exports for EV batteries."),
TradeFlow("Argentina", "United States", "Critical Minerals", ("Sea",), "Lithium exports."),
# Agriculture (Grain, Soy, etc.)
TradeFlow("Ukraine", "Egypt", "Agriculture", ("Sea",), "Black Sea wheat exports."),
TradeFlow("Ukraine", "Turkey", "Agriculture", ("Sea",), "Black Sea grain exports."),
TradeFlow("Ukraine", "Spain", "Agriculture", ("Sea",), "Black Sea grain exports."),
TradeFlow("United States", "China", "Agriculture", ("Sea",), "Soybeans and corn to China."),
TradeFlow("Brazil", "China", "Agriculture", ("Sea",), "Major soybean exports to China."),
TradeFlow("Australia", "China", "Agriculture", ("Sea",), "Wheat and barley to China."),
TradeFlow("India", "United Arab Emirates", "Agriculture", ("Sea",), "Rice and food exports."),
TradeFlow("Canada", "Japan", "Agriculture", ("Sea",), "Wheat and canola to Japan."),
# LNG (Natural Gas) - replacing pipeline flows
TradeFlow("United States", "Germany", "LNG", ("Sea",), "US LNG replacing Russian gas."),
TradeFlow("United States", "United Kingdom", "LNG", ("Sea",), "US LNG exports to UK."),
TradeFlow("United States", "France", "LNG", ("Sea",), "US LNG exports to France."),
TradeFlow("Qatar", "Japan", "LNG", ("Sea",), "Qatari LNG to Japan."),
TradeFlow("Qatar", "China", "LNG", ("Sea",), "Qatari LNG to China."),
TradeFlow("Qatar", "South Korea", "LNG", ("Sea",), "Qatari LNG to South Korea."),
TradeFlow("Australia", "Japan", "LNG", ("Sea",), "Australian LNG to Japan."),
TradeFlow("Australia", "China", "LNG", ("Sea",), "Australian LNG to China."),
]
MANUAL_COORDS = {
"Cabo Verde": (16.5388, -23.0418),
"Cote d'Ivoire": (7.5400, -5.5471),
"Czechia": (49.8175, 15.4730),
"Democratic Republic of the Congo": (-4.0383, 21.7587),
"Eswatini": (-26.5225, 31.4659),
"Hong Kong": (22.3193, 114.1694),
"Kosovo": (42.6026, 20.9030),
"Macau": (22.1987, 113.5439),
"Micronesia": (7.4256, 150.5508),
"North Korea": (40.3399, 127.5101),
"Palestine": (31.9522, 35.2332),
"Puerto Rico": (18.2208, -66.5901),
"Saint Kitts and Nevis": (17.3578, -62.7830),
"Saint Lucia": (13.9094, -60.9789),
"Saint Vincent and the Grenadines": (12.9843, -61.2872),
"Sao Tome and Principe": (0.1864, 6.6131),
"South Korea": (35.9078, 127.7669),
"Taiwan": (23.6978, 120.9605),
"Timor-Leste": (-8.8742, 125.7275),
"United Kingdom": (55.3781, -3.4360),
"United States": (37.0902, -95.7129),
"Vatican City": (41.9029, 12.4534),
"Western Sahara": (24.2155, -12.8858),
}
API_NAME_ALIASES = {
"Bahamas": "The Bahamas",
"Bolivia": "Bolivia (Plurinational State of)",
"Brunei": "Brunei Darussalam",
"Iran": "Iran (Islamic Republic of)",
"Laos": "Lao People's Democratic Republic",
"Moldova": "Moldova, Republic of",
"Russia": "Russian Federation",
"Syria": "Syrian Arab Republic",
"Tanzania": "Tanzania, United Republic of",
"Turkey": "Turkiye",
"Venezuela": "Venezuela (Bolivarian Republic of)",
"Vietnam": "Viet Nam",
}
def country_index() -> dict[str, int]:
return {country: index for index, country in enumerate(COUNTRIES)}
def empty_matrix() -> np.ndarray:
return np.zeros((len(COUNTRIES), len(COUNTRIES)), dtype=np.uint8)
def build_war_matrix() -> np.ndarray:
matrix = empty_matrix()
lookup = country_index()
for edge in SEED_TENSIONS:
i = lookup[edge.source]
j = lookup[edge.target]
matrix[i, j] = 1
matrix[j, i] = 1
return matrix
def build_seed_trade_catalog() -> pd.DataFrame:
rows = []
for flow in SEED_TRADE_FLOWS:
for mode in flow.modes:
rows.append(
{
"exporter": flow.exporter,
"importer": flow.importer,
"commodity": flow.commodity,
"mode": mode,
"source": "Illustrative fallback",
"note": flow.note,
}
)
return pd.DataFrame(rows)
@st.cache_data(ttl=60 * 60 * 24)
def load_trade_catalog() -> pd.DataFrame:
return build_seed_trade_catalog()
def build_trade_tensors(trade_catalog: pd.DataFrame) -> tuple[np.ndarray, np.ndarray]:
n = len(COUNTRIES)
commodity_tensor = np.zeros((n, n, len(COMMODITIES)), dtype=np.uint8)
transport_tensor = np.zeros((n, n, len(TRANSPORT_MODES)), dtype=np.uint8)
lookup = country_index()
commodity_lookup = {commodity: index for index, commodity in enumerate(COMMODITIES)}
mode_lookup = {mode: index for index, mode in enumerate(TRANSPORT_MODES)}
for row in trade_catalog.itertuples(index=False):
if row.exporter not in lookup or row.importer not in lookup:
continue
if row.commodity not in commodity_lookup or row.mode not in mode_lookup:
continue
i = lookup[row.exporter]
j = lookup[row.importer]
commodity_tensor[i, j, commodity_lookup[row.commodity]] = 1
transport_tensor[i, j, mode_lookup[row.mode]] = 1
return commodity_tensor, transport_tensor
def trade_edges_base_frame(trade_catalog: pd.DataFrame, war_matrix: np.ndarray) -> pd.DataFrame:
war_degree = war_matrix.sum(axis=1)
lookup = country_index()
frame = trade_catalog.copy()
frame["war_exposed"] = frame.apply(
lambda row: bool(
war_degree[lookup.get(row["exporter"], 0)] > 0
or war_degree[lookup.get(row["importer"], 0)] > 0
or war_matrix[lookup.get(row["exporter"], 0), lookup.get(row["importer"], 0)] == 1
),
axis=1,
)
frame["direct_conflict"] = frame.apply(
lambda row: bool(war_matrix[lookup.get(row["exporter"], 0), lookup.get(row["importer"], 0)] == 1),
axis=1,
)
frame["impact_score"] = frame["war_exposed"].astype(int) + frame["direct_conflict"].astype(int)
return frame
@st.cache_data(ttl=60 * 60 * 24)
def load_country_coords() -> dict[str, tuple[float, float]]:
coords = dict(MANUAL_COORDS)
try:
response = requests.get(
"https://restcountries.com/v3.1/all?fields=name,latlng",
timeout=8,
)
response.raise_for_status()
data = response.json()
if isinstance(data, list):
for item in data:
latlng = item.get("latlng") or []
names = item.get("name") or {}
if len(latlng) < 2:
continue
for name in (names.get("official"), names.get("common")):
if name:
coords[name] = (float(latlng[0]), float(latlng[1]))
for local_name, api_name in API_NAME_ALIASES.items():
if api_name in coords:
coords[local_name] = coords[api_name]
except Exception:
pass
return coords
def war_edges_frame(war_matrix: np.ndarray) -> pd.DataFrame:
seeded_notes = {tuple(sorted((edge.source, edge.target))): edge.note for edge in SEED_TENSIONS}
seeded_intensity = {tuple(sorted((edge.source, edge.target))): edge.intensity for edge in SEED_TENSIONS}
rows = []
for i in range(len(COUNTRIES)):
for j in range(i + 1, len(COUNTRIES)):
if war_matrix[i, j] == 1:
source = COUNTRIES[i]
target = COUNTRIES[j]
key = tuple(sorted((source, target)))
rows.append(
{
"source": source,
"target": target,
"intensity": seeded_intensity.get(key, 1),
"note": seeded_notes.get(key, "Seeded tension link."),
}
)
return pd.DataFrame(rows, columns=["source", "target", "intensity", "note"])
def trade_edges_frame(
trade_catalog: pd.DataFrame,
war_matrix: np.ndarray,
selected_commodity: str,
selected_mode: str,
) -> pd.DataFrame:
frame = trade_edges_base_frame(trade_catalog, war_matrix)
frame = frame[frame["commodity"] == selected_commodity].copy()
if selected_mode != "All modes":
frame = frame[frame["mode"] == selected_mode].copy()
return frame.sort_values(["exporter"], ascending=True).reset_index(drop=True)
grouped = (
frame.groupby(["exporter", "importer", "commodity"], as_index=False)
.agg(
mode=("mode", lambda values: ", ".join(sorted(set(values)))),
war_exposed=("war_exposed", "max"),
direct_conflict=("direct_conflict", "max"),
impact_score=("impact_score", "max"),
source=("source", lambda values: " + ".join(sorted(set(values)))),
note=("note", lambda values: next((value for value in values if pd.notna(value) and value), "")),
)
)
return grouped.sort_values(["exporter"], ascending=True).reset_index(drop=True)
def all_trade_edges_frame(
trade_catalog: pd.DataFrame,
war_matrix: np.ndarray,
) -> pd.DataFrame:
frame = trade_edges_base_frame(trade_catalog, war_matrix)
return frame.sort_values(["commodity", "exporter"], ascending=[True, True]).reset_index(drop=True)
def countries_for_edges(edges: pd.DataFrame, source_col: str, target_col: str) -> set[str]:
if edges.empty:
return set()
return set(edges[source_col]).union(set(edges[target_col]))
def add_route_trace(
fig: go.Figure,
coords: dict[str, tuple[float, float]],
source: str,
target: str,
color: str,
width: float,
text: str,
) -> None:
if source not in coords or target not in coords:
return
src_lat, src_lon = coords[source]
dst_lat, dst_lon = coords[target]
fig.add_trace(
go.Scattergeo(
lon=[src_lon, dst_lon],
lat=[src_lat, dst_lat],
mode="lines",
line=dict(width=width, color=color),
hoverinfo="text",
text=text,
showlegend=False,
)
)
def add_node_trace(
fig: go.Figure,
coords: dict[str, tuple[float, float]],
countries: set[str],
label: str,
color: str,
symbol: str,
) -> None:
lats = []
lons = []
names = []
for country in sorted(countries):
if country in coords:
lat, lon = coords[country]
lats.append(lat)
lons.append(lon)
names.append(country)
fig.add_trace(
go.Scattergeo(
lon=lons,