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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8"/>
|
| 5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
| 7 |
+
<title>BTI Data Exporter - ARAC International</title>
|
| 8 |
+
|
| 9 |
+
<link rel="icon" type="image/png" href="https://quanta-analytica.mnshakoor.com/logo-mns120.png">
|
| 10 |
+
<meta name="title" content="BTI Data Exporter - ARAC International">
|
| 11 |
+
<meta name="description" content="Stream the BTI Parquet dataset, filter by region, country, and year, select indicators, and export curated CSV. Powered by DuckDB-WASM.">
|
| 12 |
+
|
| 13 |
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
|
| 14 |
+
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
| 15 |
+
|
| 16 |
+
<style>
|
| 17 |
+
:root{ --bg:#fff; --fg:#222; --panel:#f6f6f6; --line:#e5e5e5; --accent:#0a84ff; --danger:#d9534f; }
|
| 18 |
+
.dark-mode{ --bg:#1e1e1e; --fg:#f2f2f2; --panel:#2b2b2b; --line:#444; --accent:#3399ff; --danger:#e06666; }
|
| 19 |
+
html,body{height:100%;}
|
| 20 |
+
body{margin:0; font-family: Inter, system-ui, Segoe UI, Roboto, Arial, sans-serif; background:var(--bg); color:var(--fg); display:flex; flex-direction:column; overflow:hidden;}
|
| 21 |
+
#navbar{display:flex; align-items:center; gap:.5rem; padding:.6rem 1rem; background:var(--panel); border-bottom:1px solid var(--line);}
|
| 22 |
+
#navbar h1{font-size:1.05rem; margin:0; flex:1;}
|
| 23 |
+
.nav-button, button{ padding:.4rem .7rem; background:var(--panel); border:1px solid var(--line); border-radius:6px; cursor:pointer; color:var(--fg);}
|
| 24 |
+
.primary{ background:var(--accent); color:#fff; border-color:var(--accent); }
|
| 25 |
+
#content{flex:1; display:flex; overflow:hidden;}
|
| 26 |
+
#control{width:270px; background:var(--panel); border-right:1px solid var(--line); overflow:auto; padding:1rem;}
|
| 27 |
+
#main{flex:1; display:flex; flex-direction:column; overflow:hidden; min-width:0;}
|
| 28 |
+
#map{height:280px; border-bottom:1px solid var(--line); z-index:0;}
|
| 29 |
+
#grid{flex:1; overflow:auto; padding:1rem;}
|
| 30 |
+
h3{margin:.8rem 0 .4rem 0; font-size:1rem;}
|
| 31 |
+
select{width:100%; padding:.35rem .4rem; border:1px solid var(--line); border-radius:6px; background:var(--bg); color:var(--fg);}
|
| 32 |
+
.row{display:flex; gap:.5rem;} .row > *{flex:1;}
|
| 33 |
+
table{width:100%; border-collapse:collapse; font-size:.9rem;}
|
| 34 |
+
th,td{border:1px solid var(--line); padding:.45rem .5rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
|
| 35 |
+
th{position:sticky; top:0; background:var(--panel); z-index:1;}
|
| 36 |
+
.spinner{ display:none; position:absolute; inset:0; background:rgba(0,0,0,.12); align-items:center; justify-content:center; z-index:9; }
|
| 37 |
+
.spinner::after{ content:""; width:56px; height:56px; border:8px solid var(--panel); border-top:8px solid var(--accent); border-radius:50%; animation:spin 1s linear infinite; }
|
| 38 |
+
@keyframes spin{to{transform:rotate(360deg)}}
|
| 39 |
+
.note{font-size:.85rem; opacity:.85;}
|
| 40 |
+
.foot{font-size:.8rem; opacity:.8; margin-top:.8rem;}
|
| 41 |
+
.stack{display:flex; flex-direction:column; gap:.4rem;}
|
| 42 |
+
</style>
|
| 43 |
+
</head>
|
| 44 |
+
<body>
|
| 45 |
+
<div id="overlay" class="spinner" aria-hidden="true"></div>
|
| 46 |
+
|
| 47 |
+
<div id="navbar">
|
| 48 |
+
<h1>BTI Data Exporter - ARAC International</h1>
|
| 49 |
+
<button id="btnTheme" class="nav-button">Toggle Theme</button>
|
| 50 |
+
<button id="btnAbout" class="nav-button">About</button>
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
<div id="content">
|
| 54 |
+
<aside id="control">
|
| 55 |
+
<div class="stack">
|
| 56 |
+
<div>
|
| 57 |
+
<h3>Indicators</h3>
|
| 58 |
+
<select id="selIndicators" multiple size="10" title="Select one or more indicators"></select>
|
| 59 |
+
<div class="note">List is auto-built from BTI columns. Use Ctrl or Cmd to multi-select.</div>
|
| 60 |
+
</div>
|
| 61 |
+
<div>
|
| 62 |
+
<h3>Region</h3>
|
| 63 |
+
<select id="selRegions" multiple size="6"></select>
|
| 64 |
+
</div>
|
| 65 |
+
<div>
|
| 66 |
+
<h3>Country</h3>
|
| 67 |
+
<select id="selCountries" multiple size="10"></select>
|
| 68 |
+
</div>
|
| 69 |
+
<div>
|
| 70 |
+
<h3>Year Range</h3>
|
| 71 |
+
<div class="row">
|
| 72 |
+
<select id="selY1"></select>
|
| 73 |
+
<select id="selY2"></select>
|
| 74 |
+
</div>
|
| 75 |
+
</div>
|
| 76 |
+
<div>
|
| 77 |
+
<h3>Actions</h3>
|
| 78 |
+
<div class="row">
|
| 79 |
+
<button id="btnReset">Reset</button>
|
| 80 |
+
<button id="btnExport" class="primary">Export CSV</button>
|
| 81 |
+
</div>
|
| 82 |
+
</div>
|
| 83 |
+
<div class="foot">Data streams from Parquet via HTTP range requests.</div>
|
| 84 |
+
</div>
|
| 85 |
+
</aside>
|
| 86 |
+
|
| 87 |
+
<main id="main">
|
| 88 |
+
<div id="map"></div>
|
| 89 |
+
<div id="grid">
|
| 90 |
+
<p style="text-align:center;margin-top:2rem;">Choose filters and indicators to render the table below.</p>
|
| 91 |
+
<div id="tableWrap"></div>
|
| 92 |
+
</div>
|
| 93 |
+
</main>
|
| 94 |
+
</div>
|
| 95 |
+
|
| 96 |
+
<dialog id="aboutDlg" style="max-width:900px;width:90%;border:1px solid var(--line);border-radius:8px;background:var(--panel);color:var(--fg);">
|
| 97 |
+
<form method="dialog" style="margin:0;">
|
| 98 |
+
<div style="display:flex;justify-content:space-between;align-items:center;gap:.5rem;padding:.8rem 1rem;border-bottom:1px solid var(--line);">
|
| 99 |
+
<strong>About BTI</strong>
|
| 100 |
+
<button>OK</button>
|
| 101 |
+
</div>
|
| 102 |
+
<div style="padding:1rem;max-height:65vh;overflow:auto;">
|
| 103 |
+
<p class="note">
|
| 104 |
+
The Transformation Index BTI aggregates 17 criteria and 49 indicators into the Status Index and Governance Index using expert reports, peer review, and regional plus interregional calibration. See the PDFs in this repository for details.
|
| 105 |
+
</p>
|
| 106 |
+
<a href="https://huggingface.co/datasets/ARACInt/bti-data/tree/main"
|
| 107 |
+
target="_blank" rel="noopener noreferrer"
|
| 108 |
+
style="display:inline-block;padding:8px 12px;border:1px solid #0a84ff;border-radius:6px;text-decoration:none;color:#fff;background:#0a84ff;">
|
| 109 |
+
View the dataset on Hugging Face
|
| 110 |
+
</a>
|
| 111 |
+
|
| 112 |
+
</div>
|
| 113 |
+
<div id="bti-citation" style="line-height:1.45">
|
| 114 |
+
<p><strong>Recommended BTI citation</strong></p>
|
| 115 |
+
<p>
|
| 116 |
+
Bertelsmann Stiftung. <em>BTI 2024: Transformation Index</em>. Gütersloh: Bertelsmann Stiftung, 2024.
|
| 117 |
+
Available at
|
| 118 |
+
<a href="https://www.bti-project.org" target="_blank" rel="noopener noreferrer">https://www.bti-project.org</a>.
|
| 119 |
+
</p>
|
| 120 |
+
</div>
|
| 121 |
+
|
| 122 |
+
<div id="about-bti" style="line-height:1.45">
|
| 123 |
+
<h2>The Bertelsmann Transformation Index</h2>
|
| 124 |
+
|
| 125 |
+
<h3>What it is</h3>
|
| 126 |
+
<p>
|
| 127 |
+
The Transformation Index BTI is a comparative assessment of political and economic transformation and the quality of governance in 137 developing and transition countries. BTI publishes two composite rankings: the <strong>Status Index</strong> and the <strong>Governance Index</strong>. Scores are based on standardized expert assessments using a 10 to 1 scale anchored by descriptive benchmarks.
|
| 128 |
+
</p>
|
| 129 |
+
|
| 130 |
+
<h3>History and purpose</h3>
|
| 131 |
+
<ul>
|
| 132 |
+
<li><strong>Origins and cadence</strong> The BTI has been produced by Bertelsmann Stiftung since 2003 and appears biennially.</li>
|
| 133 |
+
<li><strong>Scope</strong> Focuses on transformation contexts by excluding long consolidated OECD democracies.</li>
|
| 134 |
+
<li><strong>Purpose</strong> Provide transparent, comparable evidence to guide policy, research, and practice toward democracy under the rule of law and a socially responsible market economy.</li>
|
| 135 |
+
</ul>
|
| 136 |
+
|
| 137 |
+
<h3>How the methodology works</h3>
|
| 138 |
+
<ul>
|
| 139 |
+
<li><strong>Framework</strong> 17 criteria and 49 indicators organized into Democracy, Market Economy, and Governance.</li>
|
| 140 |
+
<li><strong>Expert process</strong> One country author drafts a report and ratings. A second expert independently reviews. Scores undergo regional and interregional calibration and final board review to ensure cross country comparability.</li>
|
| 141 |
+
<li><strong>Scale</strong> Indicators are rated 10 to 1 with anchored descriptors so that like conditions receive like scores across countries and time.</li>
|
| 142 |
+
<li><strong>Indices</strong>
|
| 143 |
+
<ul>
|
| 144 |
+
<li><strong>Status Index</strong> Average of political transformation and economic transformation.</li>
|
| 145 |
+
<li><strong>Governance Index</strong> Average of governance criteria, interpreted in light of the Level of Difficulty.</li>
|
| 146 |
+
<li><strong>Level of Difficulty</strong> Captures structural constraints that shape feasible governance performance.</li>
|
| 147 |
+
</ul>
|
| 148 |
+
</li>
|
| 149 |
+
</ul>
|
| 150 |
+
|
| 151 |
+
<hr>
|
| 152 |
+
|
| 153 |
+
<h3>Complete indicator structure</h3>
|
| 154 |
+
<p class="note">Below are all 17 criteria and 49 indicators. Each entry includes what it measures and why it matters.</p>
|
| 155 |
+
|
| 156 |
+
<details open>
|
| 157 |
+
<summary><strong>Democracy</strong> 5 criteria, 18 indicators</summary>
|
| 158 |
+
<ol>
|
| 159 |
+
<li><strong>Stateness</strong>
|
| 160 |
+
<ol>
|
| 161 |
+
<li><strong>Monopoly on the use of force</strong> Measures state control of security across territory. <em>Why</em> Without it, rules cannot be enforced.</li>
|
| 162 |
+
<li><strong>State identity</strong> Measures acceptance of citizenship and the nation state. <em>Why</em> Disputed nationhood destabilizes institutions.</li>
|
| 163 |
+
<li><strong>No interference of religious dogmas</strong> Measures secular operation of law and institutions. <em>Why</em> Prevents non plural restrictions on rights.</li>
|
| 164 |
+
<li><strong>Basic administration</strong> Measures reach and functionality of core services. <em>Why</em> Administration is the operating system of democracy.</li>
|
| 165 |
+
</ol>
|
| 166 |
+
</li>
|
| 167 |
+
|
| 168 |
+
<li><strong>Political participation</strong>
|
| 169 |
+
<ol>
|
| 170 |
+
<li><strong>Free and fair elections</strong> Measures integrity and competitiveness of elections. <em>Why</em> Provides democratic mandate.</li>
|
| 171 |
+
<li><strong>Effective power to govern</strong> Measures freedom from veto actors. <em>Why</em> Ensures elected authority is real authority.</li>
|
| 172 |
+
<li><strong>Association and assembly rights</strong> Measures ability to form groups and assemble. <em>Why</em> Enables organized participation and oversight.</li>
|
| 173 |
+
<li><strong>Freedom of expression</strong> Measures protection of speech and media pluralism. <em>Why</em> Supports accountability and policy debate.</li>
|
| 174 |
+
</ol>
|
| 175 |
+
</li>
|
| 176 |
+
|
| 177 |
+
<li><strong>Rule of law</strong>
|
| 178 |
+
<ol>
|
| 179 |
+
<li><strong>Separation of powers</strong> Measures checks and balances in practice. <em>Why</em> Limits abuse and arbitrariness.</li>
|
| 180 |
+
<li><strong>Independent judiciary</strong> Measures autonomy, capacity, and integrity of courts. <em>Why</em> Safeguards rights and constrains executives.</li>
|
| 181 |
+
<li><strong>Prosecution of office abuse</strong> Measures investigation and sanction of corruption. <em>Why</em> Reduces impunity and restores trust.</li>
|
| 182 |
+
<li><strong>Civil rights</strong> Measures protection and equal access to justice. <em>Why</em> Constitutes substantive citizenship.</li>
|
| 183 |
+
</ol>
|
| 184 |
+
</li>
|
| 185 |
+
|
| 186 |
+
<li><strong>Stability of democratic institutions</strong>
|
| 187 |
+
<ol>
|
| 188 |
+
<li><strong>Performance of democratic institutions</strong> Measures effectiveness and reliability of bodies. <em>Why</em> Converts rules into results.</li>
|
| 189 |
+
<li><strong>Commitment to democratic institutions</strong> Measures acceptance by key actors. <em>Why</em> Legitimacy prevents disruptive vetoes.</li>
|
| 190 |
+
</ol>
|
| 191 |
+
</li>
|
| 192 |
+
|
| 193 |
+
<li><strong>Political and social integration</strong>
|
| 194 |
+
<ol>
|
| 195 |
+
<li><strong>Party system</strong> Measures rootedness, fragmentation, polarization, volatility. <em>Why</em> Stable competition aggregates interests.</li>
|
| 196 |
+
<li><strong>Interest groups</strong> Measures breadth and balance of organized interests. <em>Why</em> Inclusive intermediation limits capture.</li>
|
| 197 |
+
<li><strong>Approval of democracy</strong> Measures public support for norms and institutions. <em>Why</em> Mass legitimacy builds resilience.</li>
|
| 198 |
+
<li><strong>Social capital</strong> Measures trust and self organization. <em>Why</em> Enables cooperation beyond the state.</li>
|
| 199 |
+
</ol>
|
| 200 |
+
</li>
|
| 201 |
+
</ol>
|
| 202 |
+
</details>
|
| 203 |
+
|
| 204 |
+
<details>
|
| 205 |
+
<summary><strong>Market economy</strong> 7 criteria, 14 indicators</summary>
|
| 206 |
+
<ol start="6">
|
| 207 |
+
<li><strong>Level of socioeconomic development</strong>
|
| 208 |
+
<ol>
|
| 209 |
+
<li><strong>Socioeconomic barriers</strong> Measures poverty and inequality that exclude participation. <em>Why</em> Structural exclusion limits opportunity.</li>
|
| 210 |
+
</ol>
|
| 211 |
+
</li>
|
| 212 |
+
|
| 213 |
+
<li><strong>Organization of the market and competition</strong>
|
| 214 |
+
<ol>
|
| 215 |
+
<li><strong>Market organization</strong> Measures open entry, free pricing, non discrimination. <em>Why</em> Predictable rules enable competition.</li>
|
| 216 |
+
<li><strong>Competition policy</strong> Measures antitrust framework and enforcement. <em>Why</em> Prevents monopolistic distortions.</li>
|
| 217 |
+
<li><strong>Liberalization of foreign trade</strong> Measures tariff and non tariff openness. <em>Why</em> Integration improves efficiency and choice.</li>
|
| 218 |
+
<li><strong>Banking system</strong> Measures supervision and financial stability. <em>Why</em> Sound finance underpins investment.</li>
|
| 219 |
+
</ol>
|
| 220 |
+
</li>
|
| 221 |
+
|
| 222 |
+
<li><strong>Monetary and fiscal stability</strong>
|
| 223 |
+
<ol>
|
| 224 |
+
<li><strong>Monetary stability</strong> Measures credibility of anti inflation policy. <em>Why</em> Reduces uncertainty in transactions.</li>
|
| 225 |
+
<li><strong>Fiscal stability</strong> Measures sustainability of public finances. <em>Why</em> Preserves policy space and confidence.</li>
|
| 226 |
+
</ol>
|
| 227 |
+
</li>
|
| 228 |
+
|
| 229 |
+
<li><strong>Private property</strong>
|
| 230 |
+
<ol>
|
| 231 |
+
<li><strong>Property rights</strong> Measures clarity and enforcement of rights. <em>Why</em> Security of ownership motivates investment.</li>
|
| 232 |
+
<li><strong>Private enterprise</strong> Measures fair treatment of private firms and hard budget constraints. <em>Why</em> Encourages entrepreneurship and discipline.</li>
|
| 233 |
+
</ol>
|
| 234 |
+
</li>
|
| 235 |
+
|
| 236 |
+
<li><strong>Welfare regime</strong>
|
| 237 |
+
<ol>
|
| 238 |
+
<li><strong>Social safety nets</strong> Measures coverage and effectiveness of protection. <em>Why</em> Shields vulnerable groups against shocks.</li>
|
| 239 |
+
<li><strong>Equal opportunity</strong> Measures access to education, jobs, and services without discrimination. <em>Why</em> Inclusion supports sustainable growth.</li>
|
| 240 |
+
</ol>
|
| 241 |
+
</li>
|
| 242 |
+
|
| 243 |
+
<li><strong>Economic performance</strong>
|
| 244 |
+
<ol>
|
| 245 |
+
<li><strong>Output strength</strong> Measures growth, employment, investment, and external balance. <em>Why</em> Summarizes macro outcomes.</li>
|
| 246 |
+
</ol>
|
| 247 |
+
</li>
|
| 248 |
+
|
| 249 |
+
<li><strong>Sustainability</strong>
|
| 250 |
+
<ol>
|
| 251 |
+
<li><strong>Environmental policy</strong> Measures conservation, climate action, and resource management. <em>Why</em> Protects long run prosperity.</li>
|
| 252 |
+
<li><strong>Education and R&D policy</strong> Measures human capital and innovation policy. <em>Why</em> Drives productivity and competitiveness.</li>
|
| 253 |
+
</ol>
|
| 254 |
+
</li>
|
| 255 |
+
</ol>
|
| 256 |
+
</details>
|
| 257 |
+
|
| 258 |
+
<details>
|
| 259 |
+
<summary><strong>Governance</strong> 5 criteria, 17 indicators plus Level of Difficulty context</summary>
|
| 260 |
+
<ol start="13">
|
| 261 |
+
<li><strong>Level of difficulty</strong>
|
| 262 |
+
<ol>
|
| 263 |
+
<li><strong>Structural constraints</strong> Measures geography, infrastructure, disasters, resource limits. <em>Why</em> Sets baseline difficulty for governing.</li>
|
| 264 |
+
<li><strong>Civil society traditions</strong> Measures associational density and engagement legacies. <em>Why</em> Affects participation capacity.</li>
|
| 265 |
+
<li><strong>Conflict intensity</strong> Measures incidence and severity of violent conflict. <em>Why</em> Violence impedes governance and reform.</li>
|
| 266 |
+
</ol>
|
| 267 |
+
</li>
|
| 268 |
+
|
| 269 |
+
<li><strong>Steering capability</strong>
|
| 270 |
+
<ol>
|
| 271 |
+
<li><strong>Prioritization</strong> Measures clarity and consistency of strategic goals. <em>Why</em> Guides action under constraints.</li>
|
| 272 |
+
<li><strong>Implementation</strong> Measures execution of policy and reform. <em>Why</em> Delivers outcomes, not just plans.</li>
|
| 273 |
+
<li><strong>Policy learning</strong> Measures adaptation, evaluation, and evidence use. <em>Why</em> Improves fit to changing conditions.</li>
|
| 274 |
+
</ol>
|
| 275 |
+
</li>
|
| 276 |
+
|
| 277 |
+
<li><strong>Resource efficiency</strong>
|
| 278 |
+
<ol>
|
| 279 |
+
<li><strong>Efficient use of assets</strong> Measures fiscal, administrative, and human resource efficiency. <em>Why</em> Maximizes scarce capacity.</li>
|
| 280 |
+
<li><strong>Policy coordination</strong> Measures coherence across ministries and levels. <em>Why</em> Reduces duplication and contradictions.</li>
|
| 281 |
+
<li><strong>Anti corruption policy</strong> Measures prevention, enforcement, and integrity systems. <em>Why</em> Protects resources and trust.</li>
|
| 282 |
+
</ol>
|
| 283 |
+
</li>
|
| 284 |
+
|
| 285 |
+
<li><strong>Consensus building</strong>
|
| 286 |
+
<ol>
|
| 287 |
+
<li><strong>Consensus on goals</strong> Measures elite commitment to democracy and market economy. <em>Why</em> Aligns reform direction.</li>
|
| 288 |
+
<li><strong>Anti democratic actors</strong> Measures how leadership addresses spoilers. <em>Why</em> Limits rollback risks.</li>
|
| 289 |
+
<li><strong>Cleavage and conflict management</strong> Measures mediation of ethnic, religious, regional divides. <em>Why</em> Prevents polarization and violence.</li>
|
| 290 |
+
<li><strong>Civil society participation</strong> Measures inclusion of CSOs in policy making. <em>Why</em> Improves legitimacy and information.</li>
|
| 291 |
+
<li><strong>Reconciliation</strong> Measures acknowledgement of past injustice and healing steps. <em>Why</em> Builds social cohesion.</li>
|
| 292 |
+
</ol>
|
| 293 |
+
</li>
|
| 294 |
+
|
| 295 |
+
<li><strong>International cooperation</strong>
|
| 296 |
+
<ol>
|
| 297 |
+
<li><strong>Effective use of support</strong> Measures alignment with and absorption of external assistance. <em>Why</em> Multiplies domestic capacity.</li>
|
| 298 |
+
<li><strong>Credibility</strong> Measures reliability and rule consistent behavior with partners. <em>Why</em> Sustains cooperation and investment.</li>
|
| 299 |
+
<li><strong>Regional cooperation</strong> Measures constructive engagement with neighbors and regional bodies. <em>Why</em> Addresses cross border challenges.</li>
|
| 300 |
+
</ol>
|
| 301 |
+
</li>
|
| 302 |
+
</ol>
|
| 303 |
+
</details>
|
| 304 |
+
|
| 305 |
+
<hr>
|
| 306 |
+
|
| 307 |
+
<h3>How to read BTI scores in this app</h3>
|
| 308 |
+
<ul>
|
| 309 |
+
<li>Scores run from 10 high to 1 low and are comparable across countries and time.</li>
|
| 310 |
+
<li>Status Index reflects the average of political and economic transformation blocks. Governance Index reflects leadership performance in context.</li>
|
| 311 |
+
<li>Use filters to select regions, countries, and years then export a curated CSV for analysis.</li>
|
| 312 |
+
</ul>
|
| 313 |
+
</div>
|
| 314 |
+
|
| 315 |
+
</form>
|
| 316 |
+
</dialog>
|
| 317 |
+
|
| 318 |
+
<script type="module">
|
| 319 |
+
import * as duckdb from 'https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/+esm';
|
| 320 |
+
|
| 321 |
+
// Config
|
| 322 |
+
const AppConfig = {
|
| 323 |
+
DATA_URL: 'https://huggingface.co/datasets/ARACInt/bti-data/resolve/main/2024-2006-bti-data.parquet',
|
| 324 |
+
patterns: { country:/^country$/i, region:/^region$/i, year:/^year$/i },
|
| 325 |
+
indicatorTokens: [
|
| 326 |
+
'status index','democracy status','economy status','governance index','governance performance',
|
| 327 |
+
'stateness','political participation','rule of law','stability of democratic institutions',
|
| 328 |
+
'political and social integration','level of socioeconomic development','organization of the market','competition',
|
| 329 |
+
'monetary','private property','welfare regime','economic performance','sustainability',
|
| 330 |
+
'level of difficulty','steering capability','resource efficiency','consensus','international cooperation',
|
| 331 |
+
'q1','q2','q3','q4','q5','q6','q7','q8','q9','q10','q11','q12','q13','q14','q15','q16','q17'
|
| 332 |
+
],
|
| 333 |
+
previewRows: 500
|
| 334 |
+
};
|
| 335 |
+
|
| 336 |
+
// State
|
| 337 |
+
const State = {
|
| 338 |
+
db:null, conn:null, schema:[], mapping:{},
|
| 339 |
+
keyCols:{country:null, region:null, year:null},
|
| 340 |
+
indicatorList:[], years:[],
|
| 341 |
+
geojson:null, map:null, mapLayer:null, name2iso:{}
|
| 342 |
+
};
|
| 343 |
+
|
| 344 |
+
// Utils
|
| 345 |
+
const showOverlay = (on=true)=>{ document.getElementById('overlay').style.display = on ? 'flex' : 'none'; };
|
| 346 |
+
const norm = (s)=> s.replace(/\s+/g,' ').trim().replace(/[|/()\u2013\u2014\-]+/g,' ').replace(/\s+/g,' ').toLowerCase();
|
| 347 |
+
const safe = (s)=> norm(s).replace(/[^a-z0-9]+/g,'_').replace(/^_+|_+$/g,'');
|
| 348 |
+
const asNum = v => (typeof v === 'bigint' ? Number(v) : (typeof v === 'string' ? Number(v) : v));
|
| 349 |
+
const asStr = v => (v == null ? '' : (typeof v === 'bigint' ? v.toString() : String(v)));
|
| 350 |
+
const normalizeName = s => (s ?? '')
|
| 351 |
+
.normalize('NFD').replace(/[\u0300-\u036f]/g,'')
|
| 352 |
+
.replace(/’/g,"'").toLowerCase()
|
| 353 |
+
.replace(/[^a-z'& ]+/g,' ').replace(/\s+/g,' ').trim();
|
| 354 |
+
|
| 355 |
+
const BTI_ALIASES = {
|
| 356 |
+
"drc": "democratic republic of the congo",
|
| 357 |
+
"dr congo": "democratic republic of the congo",
|
| 358 |
+
"congo, dem. rep.": "democratic republic of the congo",
|
| 359 |
+
"republic of congo": "republic of the congo",
|
| 360 |
+
"cote d'ivoire": "cote d'ivoire",
|
| 361 |
+
"cote d ivoire": "cote d'ivoire",
|
| 362 |
+
"czech republic": "czechia",
|
| 363 |
+
"türkiye": "turkey",
|
| 364 |
+
"turkiye": "turkey",
|
| 365 |
+
"serbia": "serbia",
|
| 366 |
+
"tanzania": "tanzania",
|
| 367 |
+
"united republic of tanzania": "tanzania"
|
| 368 |
+
};
|
| 369 |
+
|
| 370 |
+
const yearExpr = (col) => `
|
| 371 |
+
CASE
|
| 372 |
+
WHEN TRY_CAST(${col} AS INT) IS NOT NULL THEN CAST(${col} AS INT)
|
| 373 |
+
WHEN ${col} ~ '^[0-9]{4}$' THEN CAST(${col} AS INT)
|
| 374 |
+
WHEN ${col} LIKE '%/%/%' THEN EXTRACT(YEAR FROM STRPTIME(${col}, '%m/%d/%Y'))
|
| 375 |
+
WHEN ${col} LIKE '____-__-__' THEN EXTRACT(YEAR FROM STRPTIME(${col}, '%Y-%m-%d'))
|
| 376 |
+
ELSE NULL
|
| 377 |
+
END
|
| 378 |
+
`;
|
| 379 |
+
|
| 380 |
+
async function initDuckDB(){
|
| 381 |
+
showOverlay(true);
|
| 382 |
+
try{
|
| 383 |
+
const bundles = duckdb.getJsDelivrBundles();
|
| 384 |
+
const bundle = await duckdb.selectBundle(bundles);
|
| 385 |
+
const worker = await duckdb.createWorker(bundle.mainWorker);
|
| 386 |
+
const db = new duckdb.AsyncDuckDB(new duckdb.ConsoleLogger(), worker);
|
| 387 |
+
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
|
| 388 |
+
const conn = await db.connect();
|
| 389 |
+
await conn.query(`INSTALL httpfs; LOAD httpfs; SET enable_http_metadata_cache=true;`);
|
| 390 |
+
State.db = db; State.conn = conn;
|
| 391 |
+
}finally{ showOverlay(false); }
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
async function buildView(){
|
| 395 |
+
showOverlay(true);
|
| 396 |
+
try{
|
| 397 |
+
await State.conn.query(`CREATE OR REPLACE VIEW raw_bti AS SELECT * FROM read_parquet('${AppConfig.DATA_URL}')`);
|
| 398 |
+
const info = await State.conn.query(`PRAGMA table_info('raw_bti')`);
|
| 399 |
+
const cols = info.toArray().map(r => r.name);
|
| 400 |
+
State.schema = cols;
|
| 401 |
+
State.mapping = cols.reduce((acc,c)=>{ acc[c]=safe(c); return acc; },{});
|
| 402 |
+
|
| 403 |
+
function findKey(pattern){ for(const raw of cols){ if(pattern.test(raw)) return {raw, as: State.mapping[raw]}; } return null; }
|
| 404 |
+
State.keyCols = {
|
| 405 |
+
country: findKey(AppConfig.patterns.country),
|
| 406 |
+
region: findKey(AppConfig.patterns.region),
|
| 407 |
+
year: findKey(AppConfig.patterns.year)
|
| 408 |
+
};
|
| 409 |
+
|
| 410 |
+
const selectList = cols.map(raw => `"${raw}" AS ${State.mapping[raw]}`).join(', ');
|
| 411 |
+
await State.conn.query(`CREATE OR REPLACE VIEW bti AS SELECT ${selectList} FROM raw_bti`);
|
| 412 |
+
|
| 413 |
+
if(State.keyCols.year){
|
| 414 |
+
const yrs = await State.conn.query(`
|
| 415 |
+
SELECT DISTINCT ${yearExpr(State.keyCols.year.as)} AS y
|
| 416 |
+
FROM bti WHERE ${State.keyCols.year.as} IS NOT NULL
|
| 417 |
+
ORDER BY 1
|
| 418 |
+
`);
|
| 419 |
+
State.years = yrs.toArray().map(r => asNum(r.y)).filter(n => Number.isFinite(n));
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
const indicatorCandidates = cols
|
| 423 |
+
.map(raw => ({ raw, as: State.mapping[raw], label: raw }))
|
| 424 |
+
.filter(c=>{
|
| 425 |
+
const L = norm(c.label);
|
| 426 |
+
if(Object.values(State.keyCols).some(k => k && k.as === c.as)) return false;
|
| 427 |
+
const tokenHit = AppConfig.indicatorTokens.some(tok => L.includes(tok));
|
| 428 |
+
const qHit = /^q\d+(\.\d+)?/.test(L);
|
| 429 |
+
return tokenHit || qHit;
|
| 430 |
+
});
|
| 431 |
+
|
| 432 |
+
const seen = new Set();
|
| 433 |
+
const finalIndicators = [];
|
| 434 |
+
for(const c of indicatorCandidates){
|
| 435 |
+
if(seen.has(c.as)) continue;
|
| 436 |
+
seen.add(c.as);
|
| 437 |
+
finalIndicators.push({ key:c.as, raw:c.raw, as:c.as });
|
| 438 |
+
}
|
| 439 |
+
finalIndicators.sort((a,b)=> a.raw.localeCompare(b.raw));
|
| 440 |
+
State.indicatorList = finalIndicators;
|
| 441 |
+
|
| 442 |
+
}catch(e){
|
| 443 |
+
console.error('Error building the data view:', e);
|
| 444 |
+
alert('Failed to read the Parquet schema. See console for details.');
|
| 445 |
+
}finally{ showOverlay(false); }
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
async function loadWorld(){
|
| 449 |
+
if(State.geojson) return State.geojson;
|
| 450 |
+
const resp = await fetch('https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/world.geojson');
|
| 451 |
+
State.geojson = await resp.json();
|
| 452 |
+
|
| 453 |
+
const m = {};
|
| 454 |
+
for(const f of State.geojson.features){
|
| 455 |
+
const base = normalizeName(f.properties.name);
|
| 456 |
+
m[base] = f.id;
|
| 457 |
+
if(base === 'democratic republic of the congo'){ m['drc']=f.id; m['dr congo']=f.id; m["congo, dem. rep."]=f.id; }
|
| 458 |
+
if(base === 'republic of the congo'){ m['republic of congo']=f.id; }
|
| 459 |
+
if(base === 'cote d\'ivoire'){ m["cote d ivoire"]=f.id; }
|
| 460 |
+
if(base === 'czechia'){ m['czech republic']=f.id; }
|
| 461 |
+
if(base === 'turkey'){ m['turkiye']=f.id; m['türkiye']=f.id; }
|
| 462 |
+
if(base === 'tanzania'){ m['united republic of tanzania']=f.id; }
|
| 463 |
+
}
|
| 464 |
+
State.name2iso = m;
|
| 465 |
+
return State.geojson;
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
function isoForCountryName(name){
|
| 469 |
+
const n = normalizeName(name);
|
| 470 |
+
if(State.name2iso[n]) return State.name2iso[n];
|
| 471 |
+
const alias = BTI_ALIASES[n];
|
| 472 |
+
if(alias && State.name2iso[alias]) return State.name2iso[alias];
|
| 473 |
+
return null;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
function initMap(){
|
| 477 |
+
State.map = L.map('map',{zoomControl:true}).setView([20,0],2);
|
| 478 |
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{ attribution:'© OpenStreetMap' }).addTo(State.map);
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
function fillSelect(sel, arr, value='value', label='label'){ sel.innerHTML=''; arr.forEach(r=> sel.add(new Option(r[label], r[value]))); }
|
| 482 |
+
function getMulti(sel){ return Array.from(sel.selectedOptions).map(o=>o.value); }
|
| 483 |
+
|
| 484 |
+
async function populateFilters(){
|
| 485 |
+
fillSelect(document.getElementById('selIndicators'), State.indicatorList.map(x=>({value:x.key, label:x.raw})));
|
| 486 |
+
const r = await State.conn.query(`SELECT DISTINCT ${State.keyCols.region.as} AS v FROM bti WHERE ${State.keyCols.region.as} IS NOT NULL ORDER BY 1`);
|
| 487 |
+
fillSelect(document.getElementById('selRegions'), r.toArray().map(x=>({value:x.v, label:x.v})));
|
| 488 |
+
const c = await State.conn.query(`SELECT DISTINCT ${State.keyCols.country.as} AS v FROM bti WHERE ${State.keyCols.country.as} IS NOT NULL ORDER BY 1`);
|
| 489 |
+
fillSelect(document.getElementById('selCountries'), c.toArray().map(x=>({value:x.v, label:x.v})));
|
| 490 |
+
const y1 = document.getElementById('selY1'), y2 = document.getElementById('selY2'); y1.innerHTML=''; y2.innerHTML='';
|
| 491 |
+
State.years.forEach(y=>{ y1.add(new Option(y,y)); y2.add(new Option(y,y)); });
|
| 492 |
+
if(State.years.length){ y1.value = Math.min(...State.years); y2.value = Math.max(...State.years); }
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
function buildQuery({regions,countries,y1,y2,indicators}){
|
| 496 |
+
const cols = [];
|
| 497 |
+
if(State.keyCols.region) cols.push(`${State.keyCols.region.as} AS "Region"`);
|
| 498 |
+
if(State.keyCols.country) cols.push(`${State.keyCols.country.as} AS "Country"`);
|
| 499 |
+
if(State.keyCols.year) cols.push(`${yearExpr(State.keyCols.year.as)} AS "Year"`);
|
| 500 |
+
|
| 501 |
+
for(const k of indicators){
|
| 502 |
+
const found = State.indicatorList.find(x => x.key === k);
|
| 503 |
+
if(found) cols.push(`${found.as} AS "${found.raw}"`);
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
const where = [];
|
| 507 |
+
if(regions.length && State.keyCols.region) where.push(`${State.keyCols.region.as} IN (${regions.map(v=>`'${v.replace(/'/g,"''")}'`).join(',')})`);
|
| 508 |
+
if(countries.length && State.keyCols.country) where.push(`${State.keyCols.country.as} IN (${countries.map(v=>`'${v.replace(/'/g,"''")}'`).join(',')})`);
|
| 509 |
+
if(State.keyCols.year && y1 && y2) where.push(`${yearExpr(State.keyCols.year.as)} BETWEEN ${asNum(y1)} AND ${asNum(y2)}`);
|
| 510 |
+
|
| 511 |
+
return `SELECT ${cols.join(', ')} FROM bti ${where.length?'WHERE '+where.join(' AND '):''} ORDER BY "Region","Country","Year"`;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
async function renderTable(){
|
| 515 |
+
const indicators = getMulti(document.getElementById('selIndicators'));
|
| 516 |
+
const tableWrap = document.getElementById('tableWrap');
|
| 517 |
+
if(!indicators.length){
|
| 518 |
+
tableWrap.innerHTML = '<p class="note" style="text-align:center;">Select one or more indicators.</p>';
|
| 519 |
+
if(State.mapLayer) State.map.removeLayer(State.mapLayer); State.map.setView([20,0],2);
|
| 520 |
+
return;
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
showOverlay(true);
|
| 524 |
+
try{
|
| 525 |
+
const sql = buildQuery({
|
| 526 |
+
regions:getMulti(document.getElementById('selRegions')),
|
| 527 |
+
countries:getMulti(document.getElementById('selCountries')),
|
| 528 |
+
y1:document.getElementById('selY1').value,
|
| 529 |
+
y2:document.getElementById('selY2').value,
|
| 530 |
+
indicators
|
| 531 |
+
});
|
| 532 |
+
const rs = await State.conn.query(sql);
|
| 533 |
+
const all = rs.toArray();
|
| 534 |
+
const rows = all.slice(0, AppConfig.previewRows);
|
| 535 |
+
|
| 536 |
+
if(!rows.length){
|
| 537 |
+
tableWrap.innerHTML = '<p class="note" style="text-align:center;">No rows match the current filters.</p>';
|
| 538 |
+
if(State.mapLayer) State.map.removeLayer(State.mapLayer); State.map.setView([20,0],2);
|
| 539 |
+
return;
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
const cols = Object.keys(rows[0]);
|
| 543 |
+
let html = '<table><thead><tr>'; cols.forEach(c=> html += `<th>${c}</th>`); html += '</tr></thead><tbody>';
|
| 544 |
+
rows.forEach(r=>{ html += '<tr>'; cols.forEach(c=> html += `<td>${asStr(r[c])}</td>`); html += '</tr>'; }); html += '</tbody></table>';
|
| 545 |
+
if(all.length>rows.length){ html += `<div class="foot">Showing ${rows.length} of ${all.length} rows.</div>`; }
|
| 546 |
+
tableWrap.innerHTML = html;
|
| 547 |
+
|
| 548 |
+
const endYear = document.getElementById('selY2').value;
|
| 549 |
+
const metric = cols.find(c => !['Region','Country','Year'].includes(c));
|
| 550 |
+
if(metric){ await renderChoropleth(all.filter(r=>String(r.Year)===String(endYear)), metric); }
|
| 551 |
+
}catch(e){
|
| 552 |
+
console.error('Error rendering table:', e);
|
| 553 |
+
tableWrap.innerHTML = `<p class="note" style="text-align:center;color:#d9534f;">Error while fetching data. See console.</p>`;
|
| 554 |
+
}finally{ showOverlay(false); }
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
async function renderChoropleth(dataForYear, metric){
|
| 558 |
+
if(State.mapLayer) State.map.removeLayer(State.mapLayer);
|
| 559 |
+
await loadWorld();
|
| 560 |
+
|
| 561 |
+
const valueByIso = {};
|
| 562 |
+
for(const row of dataForYear){
|
| 563 |
+
const iso = isoForCountryName(row.Country);
|
| 564 |
+
if(iso != null){
|
| 565 |
+
const v = Number(row[metric]);
|
| 566 |
+
if(Number.isFinite(v)) valueByIso[iso] = v;
|
| 567 |
+
}
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
const values = Object.values(valueByIso).filter(v=>Number.isFinite(v));
|
| 571 |
+
if(!values.length){ State.map.setView([20,0],2); return; }
|
| 572 |
+
const min = Math.min(...values), max = Math.max(...values);
|
| 573 |
+
const getColor = d => { if(!Number.isFinite(d)) return '#ccc'; const t=(d-min)/(max-min||1); if(t>0.66) return '#228B22'; if(t>0.33) return '#FFD700'; return '#DC143C'; };
|
| 574 |
+
|
| 575 |
+
State.mapLayer = L.geoJSON(State.geojson,{
|
| 576 |
+
style:f=>({weight:.5,color:'#666',fillOpacity:.7,fillColor:getColor(valueByIso[f.id])}),
|
| 577 |
+
onEachFeature:(f,layer)=>{ const v=valueByIso[f.id]; layer.bindTooltip(`${f.properties.name}: ${Number.isFinite(v)?v.toFixed(2):'N/A'}`); }
|
| 578 |
+
}).addTo(State.map);
|
| 579 |
+
|
| 580 |
+
const selected = new Set(getMulti(document.getElementById('selCountries')).map(n=>isoForCountryName(n)));
|
| 581 |
+
const fit = State.geojson.features.filter(f=>selected.has(f.id));
|
| 582 |
+
if(fit.length){ const b=L.geoJSON({type:'FeatureCollection',features:fit}).getBounds(); if(b.isValid()) State.map.fitBounds(b,{padding:[20,20]}); }
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
async function exportCSV(){
|
| 586 |
+
const indicators = getMulti(document.getElementById('selIndicators'));
|
| 587 |
+
if(!indicators.length){ alert('Select one or more indicators to export.'); return; }
|
| 588 |
+
showOverlay(true);
|
| 589 |
+
try{
|
| 590 |
+
const sql = buildQuery({
|
| 591 |
+
regions:getMulti(document.getElementById('selRegions')),
|
| 592 |
+
countries:getMulti(document.getElementById('selCountries')),
|
| 593 |
+
y1:document.getElementById('selY1').value,
|
| 594 |
+
y2:document.getElementById('selY2').value,
|
| 595 |
+
indicators
|
| 596 |
+
});
|
| 597 |
+
const rs = await State.conn.query(sql);
|
| 598 |
+
const rows = rs.toArray();
|
| 599 |
+
if(!rows.length){ alert('No rows to export for current filters.'); return; }
|
| 600 |
+
|
| 601 |
+
const cols = Object.keys(rows[0]);
|
| 602 |
+
const esc = s => { const v = asStr(s); return /[",\n]/.test(v) ? `"${v.replace(/"/g,'""')}"` : v; };
|
| 603 |
+
const csv = [cols.join(','), ...rows.map(r => cols.map(c => esc(r[c])).join(','))].join('\n');
|
| 604 |
+
const blob = new Blob([csv], {type:'text/csv;charset=utf-8;'});
|
| 605 |
+
const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href=url; a.download=`bti_export_${Date.now()}.csv`; document.body.appendChild(a); a.click(); a.remove(); URL.revokeObjectURL(url);
|
| 606 |
+
}catch(e){ console.error('Error exporting CSV:', e); alert('Export failed. See console.'); }
|
| 607 |
+
finally{ showOverlay(false); }
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
document.getElementById('btnTheme').addEventListener('click', ()=> document.body.classList.toggle('dark-mode'));
|
| 611 |
+
document.getElementById('btnAbout').addEventListener('click', ()=> document.getElementById('aboutDlg').showModal());
|
| 612 |
+
document.getElementById('btnReset').addEventListener('click', ()=>{
|
| 613 |
+
['selIndicators','selRegions','selCountries'].forEach(id=>{ const sel=document.getElementById(id); Array.from(sel.options).forEach(o=>o.selected=false); });
|
| 614 |
+
if(State.years.length){ document.getElementById('selY1').value=Math.min(...State.years); document.getElementById('selY2').value=Math.max(...State.years); }
|
| 615 |
+
renderTable();
|
| 616 |
+
});
|
| 617 |
+
document.getElementById('btnExport').addEventListener('click', exportCSV);
|
| 618 |
+
['selIndicators','selRegions','selCountries','selY1','selY2'].forEach(id=> document.getElementById(id).addEventListener('change', renderTable));
|
| 619 |
+
|
| 620 |
+
(async function boot(){
|
| 621 |
+
await initDuckDB();
|
| 622 |
+
await buildView();
|
| 623 |
+
await populateFilters();
|
| 624 |
+
initMap();
|
| 625 |
+
renderTable();
|
| 626 |
+
})();
|
| 627 |
+
</script>
|
| 628 |
+
</body>
|
| 629 |
+
</html>
|