Logo

dev-resources.site

for different kinds of informations.

Displaying air quality data in the terminal

Published at
10/21/2023
Categories
python
environment
programming
Author
gbafana25
Categories
3 categories in total
python
open
environment
open
programming
open
Author
9 person written this
gbafana25
open
Displaying air quality data in the terminal

Intro

My local county reports data on the level of several pollutants throughout the area. However, the only way to see this data is via an online dashboard. My project air-monitor is a Python script that uses the backend APIs of the dashboard to display the same data in the terminal.

Obtaining the data

The dashboard makes separate requests for each pollutant type, which are specified in the request parameter where, along with the desired time span.
The service measures the following pollutant types:
- sulfur dioxide
- carbon monoxide
- Particulate Matter (10 and 2.5)
- ozone
- nitrogen oxide

The data is returned in an array of JSON objects, each of which contains a value as well as the date and time the data was collected

The are also several sensors placed throughout the county's area, which each generate their own sets of data points. In the web dashboard, these are shown in different colors/lines. In the future, ANSI codes could be used to show multiple data sources. For now, I've opted to use an averaging function that combines pollutants with multiple data sources, which is handled by the chart library.

Graphing the Data

To graph the data, chart.py uses a numpy matrix that is allocated based on the possible values ranges of a pollutant, since each pollutant is measured with different unit types (ppb, ppm, ug/m^3). Each pollutant type has it's own array size and conversion factors to display. For example, here are the values for CO.

  "CO":(40, 2, -0.01, "ppm", 100, 100, "{:.2f}", 100), # ppm
Enter fullscreen mode Exit fullscreen mode

The first value is used as the size for the outer array (the columns), and each of the sub-arrays is allocated according to the number of hours the data covers. The rest of the values are used to round and display the numbers. Then, the values are printed for each interval where a data point exists.
In order to average data from several locations, the data is first arranged into a dictionary with each time slot as a key. Then, any duplicates are averaged together and re-packaged with the same format as the original JSON data.

Image description

Challenges

The main challenge with this project is getting the data to fit inside the terminal, while also making it legible enough. My goal was for the user to visually be able to match the shape of the graph to the one in the web dashboard, but also fit on smaller displays/terminals with fewer columns. I wanted to make an initial version of this project that just used regular terminal output, without depending on any special ANSI codes. Future updates would include adding colors to the output and adding connecting lines/dots to better show the curve of the graph.

Project repo: https://github.com/gbafana25/air-monitor
VODs of coding streams: https://youtube.com/@gbafana25

environment Article's
30 articles in total
Favicon
Understanding and Fixing the Externally-Managed-Environment Error
Favicon
Optimizing Environmental Resource Management with IoT and AI Integration
Favicon
The 3 Rules that 10x my Productivity (1 min read)
Favicon
Env-Core: An Easy Way to Validate Environment Variables in Node.js Projects
Favicon
Handling Environment Variables in Vite
Favicon
PDF Scan File Size: What To Do About It.
Favicon
Anaconda Installation and Virtual Environments: A Comprehensive Guide for Windows, Linux, and macOS
Favicon
A greener planet with tech
Favicon
Setting Up a Development Environment Using Laravel Sail (Docker)
Favicon
Daniel Siegel Alonso Suggests Sustainable Practices for the Music Industry
Favicon
@Environment variables
Favicon
Ongoing Carbon Emission Reduction Efforts Beneficial to Global Blue Ammonia Market Growth
Favicon
Parsing structured environment variables in Rust
Favicon
Sustainable Practices in Sports Turf Manufacturing: Reducing Environmental Footprint
Favicon
Adding Environment Variables to Your Webpack Project
Favicon
Building Environmental Analyzer using Lyzr SDK
Favicon
Playing with Python in node
Favicon
PHP on Manjaro with ASDF
Favicon
Harnessing Solar Power: The Key to Environmental Protection
Favicon
Navigating Challenges in Scaling Your Engineering Team: Strategies for Success
Favicon
Displaying air quality data in the terminal
Favicon
Dotenv: Python app environment variable vs. Linux environment variable
Favicon
Uncaught ReferenceError: process is not defined
Favicon
How to Get Environment Specific Configuration at Runtime in Angular
Favicon
How cryptocurrency destroys environment
Favicon
Python Virtual Environments
Favicon
shell 變數與環境變數
Favicon
The intersectionality of web performance
Favicon
Setting up an Alias for a Directory in Apache2 Server
Favicon
PyEnv & Poetry - BFFs 💖

Featured ones: