Spaces:
Running
Running
Download index.html from servicedelivery/projecthub: direct link, hf CLI and curl.
- Browser
- Download file 26.1 kB
-
https://huggingface.co/spaces/servicedelivery/projecthub/resolve/main/index.html
- Command line
-
hf download hf://spaces/servicedelivery/projecthub/index.html
-
curl -L -o index.html https://huggingface.co/spaces/servicedelivery/projecthub/resolve/main/index.html
26.1 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Service Delivery</title> | |
| <style> | |
| * { | |
| box-sizing: border-box; | |
| margin: 0; | |
| padding: 0; | |
| font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif; | |
| } | |
| body { | |
| background-color: #e9ecef; | |
| min-height: 100vh; | |
| color: #333; | |
| position: relative; | |
| overflow-x: hidden; | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| /* --- TRANSPARENT WATERMARKS --- */ | |
| body::before { | |
| content: ""; | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| width: 100vw; | |
| height: 100vh; | |
| background-image: url('comclark-logo.png'), url('comclark-logo.png'); | |
| background-position: right -50px top 20px, center bottom -40px; | |
| background-size: 550px auto, 450px auto; | |
| background-repeat: no-repeat; | |
| opacity: 0.08; | |
| z-index: 0; | |
| pointer-events: none; | |
| transform: rotate(-8deg); | |
| } | |
| body::after { | |
| content: ""; | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| width: 100vw; | |
| height: 100vh; | |
| background-image: url('starlink-dish.png'), url('starlink-dish.png'); | |
| background-position: left -30px top 180px, right 40px bottom -20px; | |
| background-size: 380px auto, 420px auto; | |
| background-repeat: no-repeat; | |
| opacity: 0.10; | |
| z-index: 0; | |
| pointer-events: none; | |
| } | |
| /* --- HEADER BAR --- */ | |
| .header-bar { | |
| background-color: #ffffff; | |
| border-bottom: 1px solid #dcdfe3; | |
| padding: 14px 20px; | |
| display: flex; | |
| align-items: center; | |
| gap: 15px; | |
| box-shadow: 0 2px 6px rgba(0,0,0,0.03); | |
| position: relative; | |
| z-index: 20; | |
| } | |
| .brand-logo { | |
| height: 36px; | |
| width: auto; | |
| object-fit: contain; | |
| } | |
| .header-divider { | |
| height: 22px; | |
| width: 2px; | |
| background-color: #cbd5e1; | |
| } | |
| .header-title { | |
| font-size: 18px; | |
| font-weight: 700; | |
| color: #1b2a47; | |
| } | |
| /* DARK GRAY NAVIGATION BAR (Responsive Scroll on Mobile) */ | |
| .nav-bar-container { | |
| background-color: #2d3748; | |
| padding: 0 10px; | |
| display: flex; | |
| align-items: center; | |
| box-shadow: inset 0 2px 4px rgba(0,0,0,0.1); | |
| position: relative; | |
| z-index: 20; | |
| overflow-x: auto; | |
| white-space: nowrap; | |
| -webkit-overflow-scrolling: touch; | |
| } | |
| .top-nav-item { | |
| display: inline-flex; | |
| align-items: center; | |
| gap: 8px; | |
| padding: 12px 18px; | |
| font-size: 14px; | |
| font-weight: 600; | |
| color: #cbd5e1; | |
| cursor: pointer; | |
| transition: all 0.2s ease; | |
| border-bottom: 3px solid transparent; | |
| flex-shrink: 0; | |
| } | |
| .top-nav-item:hover { | |
| background-color: #3a475d; | |
| color: #ffffff; | |
| } | |
| .top-nav-item.active { | |
| color: #ffffff; | |
| background-color: #1a202c; | |
| border-bottom: 3px solid #38bdf8; | |
| } | |
| /* --- MAIN CONTENT AREA --- */ | |
| .main-wrapper { | |
| flex: 1; | |
| padding: 20px; | |
| position: relative; | |
| z-index: 10; | |
| } | |
| .view-section { | |
| display: none; | |
| } | |
| .view-section.active { | |
| display: block; | |
| } | |
| .container { | |
| max-width: 1100px; | |
| margin: 0 auto; | |
| width: 100%; | |
| } | |
| .section-label { | |
| font-size: 14px; | |
| font-weight: 700; | |
| color: #64748b; | |
| text-transform: uppercase; | |
| letter-spacing: 1px; | |
| margin-bottom: 12px; | |
| } | |
| /* Sub-Tabs Mobile Responsive */ | |
| .tabs-wrapper { | |
| display: flex; | |
| gap: 6px; | |
| border-bottom: 2px solid #cbd5e1; | |
| margin-bottom: 20px; | |
| overflow-x: auto; | |
| white-space: nowrap; | |
| padding-bottom: 2px; | |
| -webkit-overflow-scrolling: touch; | |
| } | |
| .tab-btn { | |
| padding: 10px 18px; | |
| border: none; | |
| background-color: #cbd5e1; | |
| color: #334155; | |
| font-size: 13px; | |
| font-weight: 600; | |
| border-top-left-radius: 6px; | |
| border-top-right-radius: 6px; | |
| cursor: pointer; | |
| transition: all 0.2s ease; | |
| flex-shrink: 0; | |
| } | |
| .tab-btn:hover { | |
| background-color: #94a3b8; | |
| color: #ffffff; | |
| } | |
| .tab-btn.active { | |
| background-color: #1b2a47; | |
| color: #ffffff; | |
| } | |
| /* Tool Panels */ | |
| .tool-panel { | |
| display: none; | |
| background: #ffffff; | |
| padding: 20px; | |
| border-radius: 8px; | |
| border: 1px solid #cbd5e1; | |
| box-shadow: 0 4px 12px rgba(0,0,0,0.04); | |
| } | |
| .tool-panel.active { | |
| display: block; | |
| } | |
| .tool-heading { | |
| font-size: 16px; | |
| color: #0f172a; | |
| margin-bottom: 15px; | |
| padding-bottom: 10px; | |
| border-bottom: 1px solid #f1f5f9; | |
| } | |
| /* Form Elements */ | |
| .form-group { | |
| margin-bottom: 15px; | |
| } | |
| .form-group label { | |
| display: block; | |
| font-size: 13px; | |
| font-weight: 600; | |
| color: #334155; | |
| margin-bottom: 5px; | |
| } | |
| .form-control { | |
| width: 100%; | |
| padding: 10px; | |
| font-size: 14px; | |
| border: 1px solid #cbd5e1; | |
| border-radius: 5px; | |
| } | |
| select.form-control { | |
| background-color: #f8fafc; | |
| font-weight: 600; | |
| color: #1e293b; | |
| } | |
| textarea.form-control { | |
| font-family: monospace; | |
| font-size: 13px; | |
| height: 140px; | |
| resize: vertical; | |
| } | |
| .btn-submit { | |
| background-color: #1b2a47; | |
| color: #ffffff; | |
| border: none; | |
| padding: 10px 20px; | |
| font-size: 14px; | |
| font-weight: 600; | |
| border-radius: 6px; | |
| cursor: pointer; | |
| margin-top: 10px; | |
| } | |
| .btn-submit:hover { | |
| background-color: #2b3d63; | |
| } | |
| .btn-secondary { | |
| background-color: #475569; | |
| } | |
| .btn-secondary:hover { | |
| background-color: #334155; | |
| } | |
| .status-msg { | |
| margin-top: 15px; | |
| font-weight: 600; | |
| font-size: 13px; | |
| } | |
| /* Projects Section */ | |
| .project-card { | |
| background: #ffffff; | |
| border-radius: 8px; | |
| border: 1px solid #cbd5e1; | |
| padding: 20px; | |
| margin-top: 15px; | |
| box-shadow: 0 4px 12px rgba(0,0,0,0.04); | |
| } | |
| .project-title { | |
| font-size: 15px; | |
| font-weight: 700; | |
| color: #1b2a47; | |
| margin-bottom: 12px; | |
| } | |
| .project-link { | |
| display: inline-flex; | |
| align-items: center; | |
| gap: 8px; | |
| background-color: #1b2a47; | |
| color: #ffffff; | |
| text-decoration: none; | |
| padding: 10px 16px; | |
| border-radius: 6px; | |
| font-size: 13px; | |
| font-weight: 600; | |
| cursor: pointer; | |
| border: none; | |
| transition: background 0.2s ease; | |
| } | |
| .project-link:hover { | |
| background-color: #2b3d63; | |
| } | |
| /* EMBEDDED IFRAME MOBILE-OPTIMIZED STYLES */ | |
| .iframe-wrapper { | |
| width: 100%; | |
| background: #ffffff; | |
| border-radius: 8px; | |
| border: 1px solid #cbd5e1; | |
| box-shadow: 0 4px 12px rgba(0,0,0,0.04); | |
| overflow: hidden; | |
| } | |
| .app-frame { | |
| width: 100%; | |
| height: calc(100vh - 200px); | |
| min-height: 650px; | |
| border: none; | |
| display: block; | |
| } | |
| /* MOBILE SPECIFIC ADJUSTMENTS */ | |
| @media (max-width: 768px) { | |
| .header-bar { | |
| padding: 10px 15px; | |
| } | |
| .brand-logo { | |
| height: 28px; | |
| } | |
| .header-title { | |
| font-size: 16px; | |
| } | |
| .main-wrapper { | |
| padding: 15px 10px; | |
| } | |
| .app-frame { | |
| height: calc(100vh - 170px); | |
| min-height: 550px; | |
| } | |
| .tool-panel { | |
| padding: 15px; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <!-- Top Header --> | |
| <header class="header-bar"> | |
| <img src="comclark-logo.png" alt="Comclark Logo" class="brand-logo" onerror="this.style.display='none'"> | |
| <div class="header-divider"></div> | |
| <h1 class="header-title">Service Delivery</h1> | |
| </header> | |
| <!-- DARK GRAY NAVIGATION BAR --> | |
| <nav class="nav-bar-container"> | |
| <div class="top-nav-item active" onclick="switchMainView(event, 'view-tools')"> | |
| <span>🛠️</span> Tools | |
| </div> | |
| <div class="top-nav-item" onclick="switchMainView(event, 'view-projects')"> | |
| <span>📁</span> Projects | |
| </div> | |
| <div class="top-nav-item" onclick="switchMainView(event, 'view-survey-form')"> | |
| <span>📋</span> Site Survey Form | |
| </div> | |
| <div class="top-nav-item" onclick="switchMainView(event, 'view-uat-forms')"> | |
| <span>📄</span> UAT Forms | |
| </div> | |
| </nav> | |
| <!-- Main Content Area --> | |
| <main class="main-wrapper"> | |
| <!-- TOOLS VIEW --> | |
| <div id="view-tools" class="view-section active"> | |
| <div class="container"> | |
| <div class="section-label">Internal Tools Workspace</div> | |
| <!-- Sub-Tabs --> | |
| <div class="tabs-wrapper"> | |
| <button class="tab-btn active" onclick="openTool(event, 'tool-direct-nap')">Nearest NAP Generator</button> | |
| <button class="tab-btn" onclick="openTool(event, 'tool-json')">JSON to CSV</button> | |
| <button class="tab-btn" onclick="openTool(event, 'tool-mac-report')">Daily Client MAC Address Report</button> | |
| <button class="tab-btn" onclick="openTool(event, 'tool-ruijie-reports')">Ruijie Reports</button> | |
| </div> | |
| <!-- Tool 1: Auto-Loaded Nearest NAP Generator --> | |
| <section id="tool-direct-nap" class="tool-panel active"> | |
| <h2 class="tool-heading">Nearest NAP Generator (Auto-Loaded Database)</h2> | |
| <!-- Step 1: Region Filter --> | |
| <div class="form-group"> | |
| <label for="regionSelect">1. Filter by Region:</label> | |
| <select id="regionSelect" class="form-control" disabled> | |
| <option value="ALL">Loading 500k NAPs database... Please wait...</option> | |
| </select> | |
| </div> | |
| <!-- Step 2: Input Coordinates --> | |
| <div class="form-group"> | |
| <label for="coordInput">2. Paste Target Coordinates (Latitude, Longitude per line):</label> | |
| <textarea id="coordInput" class="form-control" placeholder="Example: 16.158089, 120.561527 16.121613, 119.778559 16.106664 119.806556"></textarea> | |
| </div> | |
| <div style="display: flex; gap: 10px; flex-wrap: wrap;"> | |
| <button class="btn-submit" onclick="processLocalCoordinates()">⚡ Calculate & Download CSV</button> | |
| <button class="btn-submit btn-secondary" onclick="clearCoordInput()">Clear Input</button> | |
| </div> | |
| <div id="direct-nap-status" class="status-msg"></div> | |
| </section> | |
| <!-- Tool 2: JSON to CSV --> | |
| <section id="tool-json" class="tool-panel"> | |
| <h2 class="tool-heading">JSON to CSV Converter</h2> | |
| <div class="form-group"> | |
| <label>Select JSON File:</label> | |
| <input type="file" id="jsonInput" accept=".json" class="form-control" style="width: auto;"> | |
| </div> | |
| <button class="btn-submit" onclick="convertJSON()">Convert & Download CSV</button> | |
| <div id="status" class="status-msg"></div> | |
| </section> | |
| <!-- Tool 3: Daily Client MAC Address Report --> | |
| <section id="tool-mac-report" class="tool-panel iframe-wrapper" style="padding: 0;"> | |
| <iframe src="https://servicedelivery-dailyclientmacaddressreport.static.hf.space/index.html" class="app-frame" title="Daily Client MAC Address Report"></iframe> | |
| </section> | |
| <!-- Tool 4: Ruijie Reports Embedded Viewer --> | |
| <section id="tool-ruijie-reports" class="tool-panel iframe-wrapper" style="padding: 0;"> | |
| <iframe src="https://ruijie-reports.comclark.com/" class="app-frame" title="Ruijie Reports"></iframe> | |
| </section> | |
| </div> | |
| </div> | |
| <!-- PROJECTS VIEW --> | |
| <div id="view-projects" class="view-section"> | |
| <div class="container"> | |
| <div class="section-label">Projects Overview</div> | |
| <div class="project-card"> | |
| <h2 class="project-title">CONNECTIVITY ENHANCEMENT PROGRAM FOR E-LEARNING IN PUBLIC SCHOOLS</h2> | |
| <a href="https://docs.google.com/spreadsheets/d/1L67l67hAqpHg3raT370EeNPjHuTZjuysG3hchll4Rk0/edit?gid=510222528#gid=510222528" target="_blank" rel="noopener noreferrer" class="project-link"> | |
| 📊 Open Project Tracker (External) | |
| </a> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- SITE SURVEY FORM VIEW --> | |
| <div id="view-survey-form" class="view-section"> | |
| <div class="container"> | |
| <div class="section-label">Site Survey Workspace</div> | |
| <!-- Sub-Tabs para sa Site Survey Forms --> | |
| <div class="tabs-wrapper"> | |
| <button class="tab-btn active" onclick="openSurveyForm(event, 'survey-picsmuni')">PICS MUNI Site Survey</button> | |
| <button class="tab-btn" onclick="openSurveyForm(event, 'survey-sss')">SSS Site Survey Form</button> | |
| </div> | |
| <!-- Embedded Frame 1: PICS MUNI Site Survey --> | |
| <div id="survey-picsmuni" class="survey-panel iframe-wrapper" style="display: block;"> | |
| <iframe src="https://servicedelivery-picsmuni.static.hf.space/index.html" class="app-frame" title="PICS MUNI Site Survey"></iframe> | |
| </div> | |
| <!-- Embedded Frame 2: SSS Site Survey Form --> | |
| <div id="survey-sss" class="survey-panel iframe-wrapper" style="display: none;"> | |
| <iframe src="https://servicedelivery-ssssitesurveyreport.static.hf.space/index.html" class="app-frame" title="SSS Site Survey Form"></iframe> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- UAT FORMS VIEW --> | |
| <div id="view-uat-forms" class="view-section"> | |
| <div class="container"> | |
| <div class="section-label">UAT Forms Workspace</div> | |
| <!-- Sub-Tabs para sa UAT Forms --> | |
| <div class="tabs-wrapper"> | |
| <button class="tab-btn active" onclick="openUATForm(event, 'uat-naia')">NAIA UAT Form</button> | |
| <button class="tab-btn" onclick="openUATForm(event, 'uat-picsmuni')">PICS MUNI UAT Form</button> | |
| </div> | |
| <!-- Embedded Frame 1: NAIA UAT Form --> | |
| <div id="uat-naia" class="uat-panel iframe-wrapper" style="display: block;"> | |
| <iframe src="https://servicedelivery-naia-uat.static.hf.space/index.html" class="app-frame" title="NAIA UAT Form"></iframe> | |
| </div> | |
| <!-- Embedded Frame 2: PICS MUNI UAT Form --> | |
| <div id="uat-picsmuni" class="uat-panel iframe-wrapper" style="display: none;"> | |
| <iframe src="https://servicedelivery-picsmuniuat.static.hf.space/index.html" class="app-frame" title="PICS MUNI UAT Form"></iframe> | |
| </div> | |
| </div> | |
| </div> | |
| </main> | |
| <script> | |
| let rawNapDataset = []; | |
| const R = 6371; // Earth radius in km | |
| // AUTO-LOAD JSON DATABASE ON PAGE LOAD | |
| window.addEventListener('DOMContentLoaded', () => { | |
| const status = document.getElementById('direct-nap-status'); | |
| const regionDropdown = document.getElementById('regionSelect'); | |
| status.style.color = '#0284c7'; | |
| status.textContent = 'Auto-loading 500k NAPs database into memory... Please wait...'; | |
| fetch('naps_data.json') | |
| .then(response => { | |
| if (!response.ok) throw new Error("naps_data.json file not found."); | |
| return response.json(); | |
| }) | |
| .then(data => { | |
| rawNapDataset = []; | |
| const detectedRegions = new Set(); | |
| for (let i = 0; i < data.length; i++) { | |
| let row = data[i]; | |
| let region = row['Region'] || row['REGION'] || Object.values(row)[0] || 'Unassigned'; | |
| let name = row['NAP Name'] || row['NAP'] || row['Name'] || Object.values(row)[1] || `NAP_${i+1}`; | |
| let lat = parseFloat(row['Latitude'] || row['Lat'] || row['NAP Latitude'] || Object.values(row)[2]); | |
| let lng = parseFloat(row['Longitude'] || row['Lng'] || row['NAP Longitude'] || Object.values(row)[3]); | |
| if (!isNaN(lat) && !isNaN(lng) && lat !== 0 && lng !== 0) { | |
| region = String(region).trim(); | |
| rawNapDataset.push({ region, name, lat, lng }); | |
| if (region) detectedRegions.add(region); | |
| } | |
| } | |
| // Build Dropdown Options | |
| regionDropdown.innerHTML = '<option value="ALL">-- ALL REGIONS (Search Entire Dataset) --</option>'; | |
| const sortedRegions = Array.from(detectedRegions).sort(); | |
| sortedRegions.forEach(reg => { | |
| let opt = document.createElement('option'); | |
| opt.value = reg; | |
| opt.textContent = `Region: ${reg}`; | |
| regionDropdown.appendChild(opt); | |
| }); | |
| regionDropdown.disabled = false; | |
| status.style.color = 'green'; | |
| status.textContent = `✔ Database ready! Loaded ${rawNapDataset.length.toLocaleString()} NAPs across ${sortedRegions.length} regions.`; | |
| }) | |
| .catch(err => { | |
| status.style.color = 'red'; | |
| status.textContent = 'Error loading database: Make sure naps_data.json is in the same folder as Index.html.'; | |
| }); | |
| }); | |
| // Navigation Views | |
| function switchMainView(event, viewId) { | |
| document.querySelectorAll('.view-section').forEach(view => view.classList.remove('active')); | |
| document.querySelectorAll('.top-nav-item').forEach(item => item.classList.remove('active')); | |
| document.getElementById(viewId).classList.add('active'); | |
| event.currentTarget.classList.add('active'); | |
| } | |
| // Tool Sub-Tabs | |
| function openTool(event, toolId) { | |
| document.querySelectorAll('.tool-panel').forEach(panel => panel.classList.remove('active')); | |
| document.querySelectorAll('#view-tools .tab-btn').forEach(btn => btn.classList.remove('active')); | |
| document.getElementById(toolId).classList.add('active'); | |
| event.currentTarget.classList.add('active'); | |
| } | |
| // Site Survey Sub-Tabs | |
| function openSurveyForm(event, surveyId) { | |
| document.querySelectorAll('.survey-panel').forEach(panel => panel.style.display = 'none'); | |
| document.querySelectorAll('#view-survey-form .tab-btn').forEach(btn => btn.classList.remove('active')); | |
| document.getElementById(surveyId).style.display = 'block'; | |
| event.currentTarget.classList.add('active'); | |
| } | |
| // UAT Forms Sub-Tabs | |
| function openUATForm(event, uatId) { | |
| document.querySelectorAll('.uat-panel').forEach(panel => panel.style.display = 'none'); | |
| document.querySelectorAll('#view-uat-forms .tab-btn').forEach(btn => btn.classList.remove('active')); | |
| document.getElementById(uatId).style.display = 'block'; | |
| event.currentTarget.classList.add('active'); | |
| } | |
| function clearCoordInput() { | |
| document.getElementById('coordInput').value = ''; | |
| document.getElementById('direct-nap-status').textContent = ''; | |
| } | |
| // PROCESS COORDINATES & DOWNLOAD CSV | |
| function processLocalCoordinates() { | |
| const rawText = document.getElementById('coordInput').value.trim(); | |
| const status = document.getElementById('direct-nap-status'); | |
| const selectedRegion = document.getElementById('regionSelect').value; | |
| if (rawNapDataset.length === 0) { | |
| status.style.color = 'red'; | |
| status.textContent = 'NAP dataset is still loading...'; | |
| return; | |
| } | |
| if (!rawText) { | |
| status.style.color = 'red'; | |
| status.textContent = 'Please paste at least one pair of coordinates.'; | |
| return; | |
| } | |
| let filteredDataset = rawNapDataset; | |
| if (selectedRegion !== 'ALL') { | |
| filteredDataset = rawNapDataset.filter(item => item.region === selectedRegion); | |
| } | |
| if (filteredDataset.length === 0) { | |
| status.style.color = 'red'; | |
| status.textContent = `No NAPs found for region: ${selectedRegion}`; | |
| return; | |
| } | |
| // Build 1-degree spatial grid index | |
| const grid = {}; | |
| for (let i = 0; i < filteredDataset.length; i++) { | |
| let item = filteredDataset[i]; | |
| let key = Math.floor(item.lat) + "," + Math.floor(item.lng); | |
| if (!grid[key]) grid[key] = []; | |
| grid[key].push(i); | |
| } | |
| const lines = rawText.split(/\r?\n/); | |
| const csvRows = []; | |
| csvRows.push(['Row', 'Input Latitude', 'Input Longitude', 'Nearest NAP', 'NAP Region', 'NAP Latitude', 'NAP Longitude', 'Distance (km)', 'Within 300m'].join(',')); | |
| let count = 0; | |
| for (let i = 0; i < lines.length; i++) { | |
| let line = lines[i].trim(); | |
| if (!line) continue; | |
| let parts = line.split(/[\t,]+/); | |
| if (parts.length >= 2) { | |
| let schoolLat = parseFloat(parts[0].trim()); | |
| let schoolLon = parseFloat(parts[1].trim()); | |
| // Automatic Lat/Lng Swap Fix if Latitude > 50 | |
| if (schoolLat > 50 && schoolLon < 50) { | |
| let temp = schoolLat; | |
| schoolLat = schoolLon; | |
| schoolLon = temp; | |
| } | |
| if (!isNaN(schoolLat) && !isNaN(schoolLon)) { | |
| count++; | |
| let baseLatKey = Math.floor(schoolLat); | |
| let baseLonKey = Math.floor(schoolLon); | |
| let minDist = 1e99; | |
| let nearestObj = null; | |
| // Search 3x3 grid neighborhood | |
| for (let dLat = -1; dLat <= 1; dLat++) { | |
| for (let dLon = -1; dLon <= 1; dLon++) { | |
| let key = (baseLatKey + dLat) + "," + (baseLonKey + dLon); | |
| if (grid[key]) { | |
| let indices = grid[key]; | |
| for (let k = 0; k < indices.length; k++) { | |
| let nap = filteredDataset[indices[k]]; | |
| let radSchoolLat = (schoolLat * Math.PI) / 180; | |
| let radNapLat = (nap.lat * Math.PI) / 180; | |
| let radLonDiff = ((nap.lng - schoolLon) * Math.PI) / 180; | |
| let cosValue = Math.cos(radSchoolLat) * Math.cos(radNapLat) * Math.cos(radLonDiff) + | |
| Math.sin(radSchoolLat) * Math.sin(radNapLat); | |
| cosValue = Math.max(-1, Math.min(1, cosValue)); | |
| let dist = Math.abs(R * Math.acos(cosValue)); | |
| if (dist < minDist) { | |
| minDist = dist; | |
| nearestObj = nap; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| if (nearestObj) { | |
| let within300m = minDist <= 0.3 ? "Yes" : "No"; | |
| csvRows.push([ | |
| count, | |
| schoolLat, | |
| schoolLon, | |
| `"${nearestObj.name}"`, | |
| `"${nearestObj.region}"`, | |
| nearestObj.lat, | |
| nearestObj.lng, | |
| minDist.toFixed(4), | |
| within300m | |
| ].join(',')); | |
| } else { | |
| csvRows.push([count, schoolLat, schoolLon, '"No match in region area"', selectedRegion, '', '', '', 'No'].join(',')); | |
| } | |
| } | |
| } | |
| } | |
| // Download CSV | |
| const blob = new Blob([csvRows.join('\n')], { type: 'text/csv;charset=utf-8;' }); | |
| const url = URL.createObjectURL(blob); | |
| const link = document.createElement('a'); | |
| link.setAttribute('href', url); | |
| link.setAttribute('download', `Nearest_NAP_Results_${selectedRegion}.csv`); | |
| document.body.appendChild(link); | |
| link.click(); | |
| document.body.removeChild(link); | |
| status.style.color = 'green'; | |
| status.textContent = `✔ Complete! Processed ${count} coordinates in seconds. CSV Downloaded.`; | |
| } | |
| // JSON to CSV | |
| function normalizeObject(obj, prefix = '') { | |
| let flattened = {}; | |
| for (let key in obj) { | |
| if (!obj.hasOwnProperty(key)) continue; | |
| let propName = prefix ? `${prefix}.${key}` : key; | |
| let value = obj[key]; | |
| if (typeof value === 'object' && value !== null && !Array.isArray(value)) { | |
| Object.assign(flattened, normalizeObject(value, propName)); | |
| } else if (Array.isArray(value)) { | |
| flattened[propName] = value.map(v => (typeof v === 'object' ? JSON.stringify(v) : v)).join('; '); | |
| } else { | |
| flattened[propName] = value; | |
| } | |
| } | |
| return flattened; | |
| } | |
| function convertJSON() { | |
| const fileInput = document.getElementById('jsonInput'); | |
| const status = document.getElementById('status'); | |
| if (!fileInput.files.length) { | |
| status.textContent = 'Please select a JSON file first.'; | |
| status.style.color = 'red'; | |
| return; | |
| } | |
| const file = fileInput.files[0]; | |
| const reader = new FileReader(); | |
| reader.onload = function(e) { | |
| try { | |
| let jsonData = JSON.parse(e.target.result); | |
| if (!Array.isArray(jsonData)) { | |
| if (typeof jsonData === 'object') { | |
| jsonData = [jsonData]; | |
| } else { | |
| throw new Error("Invalid JSON structure"); | |
| } | |
| } | |
| const flatData = jsonData.map(item => normalizeObject(item)); | |
| const headers = Array.from(new Set(flatData.flatMap(item => Object.keys(item)))); | |
| const csvRows = []; | |
| csvRows.push(headers.join(',')); | |
| for (const row of flatData) { | |
| const values = headers.map(header => { | |
| let val = row[header] !== undefined ? row[header] : ''; | |
| val = String(val).replace(/"/g, '""'); | |
| return `"${val}"`; | |
| }); | |
| csvRows.push(values.join(',')); | |
| } | |
| const blob = new Blob([csvRows.join('\n')], { type: 'text/csv;charset=utf-8;' }); | |
| const url = URL.createObjectURL(blob); | |
| const link = document.createElement('a'); | |
| link.setAttribute('href', url); | |
| link.setAttribute('download', file.name.replace('.json', '.csv')); | |
| document.body.appendChild(link); | |
| link.click(); | |
| document.body.removeChild(link); | |
| status.textContent = 'Conversion successful! Downloading CSV...'; | |
| status.style.color = 'green'; | |
| } catch (err) { | |
| status.textContent = 'Error parsing JSON file. Make sure it is valid JSON.'; | |
| status.style.color = 'red'; | |
| } | |
| }; | |
| reader.readAsText(file); | |
| } | |
| </script> | |
| </body> | |
| </html> |