Air Quality Index to Environmental Sensor Reading Converter

AQI to Environmental Sensor Reading Converter

Enter Air Quality Index (AQI) value, select pollutant type, and convert to sensor readings.

Pollutant Type: ${pollutantDisplay[pollutantType]}

Sensor Reading: ${sensorReading.toFixed(2)} ${unit}

`; resultSection.innerHTML = resultText; resultSection.style.display = 'block'; pdfButton.disabled = false; }; const downloadPDF = () => { if (!currentResults.pollutantType || !resultSection.innerText) { errorMessage.textContent = 'No results available to download.'; errorMessage.style.display = 'block'; return; } try { const { jsPDF } = window.jspdf; if (!jsPDF) { console.error('jsPDF is not loaded.'); errorMessage.textContent = 'PDF generation failed. Please try again.'; errorMessage.style.display = 'block'; return; } const doc = new jsPDF(); doc.setFont('helvetica', 'bold'); doc.setFontSize(16); doc.text('AQI to Environmental Sensor Reading Converter', 20, 20); doc.setLineWidth(0.5); doc.line(20, 25, 190, 25); doc.setFont('helvetica', 'normal'); doc.setFontSize(12); const pollutantDisplay = { pm25: 'PM2.5', pm10: 'PM10', o3: 'Ozone (O3)', no2: 'Nitrogen Dioxide (NO2)', co: 'Carbon Monoxide (CO)' }; doc.text(`AQI Value: ${currentResults.aqiValue.toFixed(0)}`, 20, 40); doc.text(`Pollutant Type: ${pollutantDisplay[currentResults.pollutantType]}`, 20, 50); doc.text(`Sensor Reading: ${currentResults.sensorReading.toFixed(2)} ${currentResults.unit}`, 20, 60); doc.setDrawColor(200); doc.rect(15, 35, 180, 30); doc.save('aqi_sensor_reading.pdf'); } catch (error) { console.error('PDF generation error:', error); errorMessage.textContent = 'Failed to generate PDF. Please try again.'; errorMessage.style.display = 'block'; } }; const resetForm = () => { converterForm.reset(); resultSection.innerHTML = ''; resultSection.style.display = 'none'; errorMessage.style.display = 'none'; pdfButton.disabled = true; currentResults = { aqiValue: 0, pollutantType: '', sensorReading: 0, unit: '' }; aqiValueInput.focus(); }; convertButton.addEventListener('click', calculateSensorReading); resetButton.addEventListener('click', resetForm); pdfButton.addEventListener('click', downloadPDF); converterForm.addEventListener('submit', (e) => { e.preventDefault(); calculateSensorReading(); }); }); })();
Scroll to Top