@@ -65,8 +65,8 @@ <h2>SadiCoin Tech Debt Projection (multi-year)</h2>
6565
6666 < div class ="grid ">
6767 < div >
68- < label > Select Country</ label >
69- < select id ="countrySelect " onchange ="fetchSDGDataForCountry () ">
68+ < label > Select Country for Debt Projection </ label >
69+ < select id ="countrySelect " onchange ="showDebtProjectionForm () ">
7070 < option value ="South Africa "> South Africa</ option >
7171 < option value ="India "> India</ option >
7272 < option value ="Brazil "> Brazil</ option >
@@ -77,9 +77,6 @@ <h2>SadiCoin Tech Debt Projection (multi-year)</h2>
7777 < option value ="Mexico "> Mexico</ option >
7878 < option value ="Egypt "> Egypt</ option >
7979 < option value ="Vietnam "> Vietnam</ option >
80- < option value ="Zimbabwe "> Zimbabwe</ option >
81- < option value ="Zambia "> Zambia</ option >
82- < option value ="Mozambique "> Mozambique</ option >
8380 </ select >
8481 < label > Starting Debt (t=0)</ label >
8582 < input id ="debt0 " type ="number " step ="0.01 " value ="1000000000 ">
@@ -121,45 +118,55 @@ <h2>SadiCoin Tech Debt Projection (multi-year)</h2>
121118 < div id ="tableWrapper " style ="margin-top:12px; overflow:auto; "> </ div >
122119 </ div >
123120
121+ <!-- UNDP Data Section -->
122+ < div class ="form-container ">
123+ < h2 > UNDP Data (SDG Index)</ h2 >
124+
125+ < div >
126+ < label > Select Country for SDG Data</ label >
127+ < select id ="countrySelectSDG " onchange ="fetchSDGDataForCountry() ">
128+ < option value ="South Africa "> South Africa</ option >
129+ < option value ="India "> India</ option >
130+ < option value ="Brazil "> Brazil</ option >
131+ < option value ="Kenya "> Kenya</ option >
132+ < option value ="Pakistan "> Pakistan</ option >
133+ < option value ="Nigeria "> Nigeria</ option >
134+ < option value ="Indonesia "> Indonesia</ option >
135+ < option value ="Mexico "> Mexico</ option >
136+ < option value ="Egypt "> Egypt</ option >
137+ < option value ="Vietnam "> Vietnam</ option >
138+ </ select >
139+ </ div >
140+
141+ < div id ="sdgDataReport " class ="out " style ="margin-top:12px; "> </ div >
142+ </ div >
143+
124144 < script >
145+ // Show or hide debt projection form based on selected country
146+ function showDebtProjectionForm ( ) {
147+ document . getElementById ( 'debtPanel' ) . style . display = 'block' ; // Show debt projection section
148+ }
149+
125150 // Fetch SDG Data from UNDP API
126151 async function fetchSDGData ( country ) {
127152 const apiUrl = `https://api.open.undp.org/api/sdg-index.json` ; // SDG Index API
128153
129154 try {
130155 const response = await fetch ( apiUrl ) ;
131156 const data = await response . json ( ) ;
132-
133- // Filtering the data by the selected country (if country name exists in the response)
134- const countryData = data . find ( item => item . sdg_name === country ) ; // You might need to adjust this part
157+
158+ const countryData = data . find ( item => item . sdg_name === country ) ; // Fetch country-specific data
135159
136160 if ( countryData ) {
137- return countryData ; // Return country data with SDG progress and other metrics
161+ displaySDGData ( countryData ) ; // Display SDG data in the report section
138162 } else {
139163 alert ( 'No SDG data found for this country' ) ;
140- return null ;
141164 }
142165 } catch ( error ) {
143166 console . error ( 'Error fetching SDG data:' , error ) ;
144167 }
145168 }
146169
147- // Format numbers with commas
148- function fmt ( num ) {
149- return ( typeof num === 'number' && isFinite ( num ) ) ? num . toLocaleString ( undefined , { minimumFractionDigits : 2 } ) : num ;
150- }
151-
152- // Fetch SDG Data for Selected Country
153- async function fetchSDGDataForCountry ( ) {
154- const country = document . getElementById ( 'countrySelect' ) . value ;
155-
156- const countryData = await fetchSDGData ( country ) ;
157- if ( countryData ) {
158- console . log ( 'SDG Data:' , countryData ) ; // Display the SDG data in the UI
159- displaySDGData ( countryData ) ;
160- }
161- }
162-
163170 // Display SDG Data
164171 function displaySDGData ( countryData ) {
165172 let detailsHTML = `
@@ -186,16 +193,18 @@ <h4>Target Details:</h4>
186193 } ) ;
187194
188195 detailsHTML += '</ul>' ;
189- document . getElementById ( 'summary' ) . innerHTML = detailsHTML ;
196+ document . getElementById ( 'sdgDataReport' ) . innerHTML = detailsHTML ;
197+ }
198+
199+ // Format numbers with commas
200+ function fmt ( num ) {
201+ return ( typeof num === 'number' && isFinite ( num ) ) ? num . toLocaleString ( undefined , { minimumFractionDigits : 2 } ) : num ;
190202 }
191203
192204 // Run IMF Debt Projection
193205 document . getElementById ( 'btnProject' ) . addEventListener ( 'click' , async function ( ) {
194206 const country = document . getElementById ( 'countrySelect' ) . value ;
195-
196- const countryData = await fetchSDGData ( country ) ;
197- if ( ! countryData ) return ;
198-
207+
199208 const debt0 = parseFloat ( document . getElementById ( 'debt0' ) . value ) ;
200209 const gdp0 = parseFloat ( document . getElementById ( 'gdp0' ) . value ) ;
201210 const i_nom = parseFloat ( document . getElementById ( 'i_nom' ) . value ) / 100 ;
0 commit comments