0% found this document useful (0 votes)
8 views6 pages

Report

The document outlines a project at Hanoi University of Science and Technology focused on simulating PM2.5 dust sensors and analyzing the collected data through three main tasks. The tasks involve generating random dust data, processing this data into multiple CSV files, and facilitating the transmission of valid dust data using a specified communication protocol. The project successfully completed all tasks, demonstrating effective error handling and data integrity assurance, although the results were noted to be less accurate than expected.

Uploaded by

Nhat Minh Dang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Report

The document outlines a project at Hanoi University of Science and Technology focused on simulating PM2.5 dust sensors and analyzing the collected data through three main tasks. The tasks involve generating random dust data, processing this data into multiple CSV files, and facilitating the transmission of valid dust data using a specified communication protocol. The project successfully completed all tasks, demonstrating effective error handling and data integrity assurance, although the results were noted to be less accurate than expected.

Uploaded by

Nhat Minh Dang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

Dust sensor simulation and data analaysis

Abstract— It shall complete three tasks for this Task 3: Facilitating the transmission of valid
project. Making a CSV file with the data will be dust data obtained from Task 2.2 using a
the first task. based on the location and the data specified communication protocol. This
generated in job 1. Task 2 will accept a CSV file protocol defines the structure and format of data
as input.Task 2 will generate four CSV files by packets that are to be sent and received,
processing and calculating data. In task 3, the ensuring reliable and standardized
data will come from the Dat file into the CSV communication between systems. The
file, or task 2.1's CSV file as will be used, implementation will involve reading dust data
converted to hex code, and saved in the Dat file. from a file, converting each data entry into a
structured data packet, and writing these packets
I. INTRODUCTION to an output file.

This project is making in Window operating II. DETAIL DESIGN OF THE PROGRAME
system, coding on Vscode and compile by using
gcc or g++ in MinGW-w64 has a goal of Beginning of this part all the C/C++ library that
designing a program to simulate PM2.5 dust included in this project will be summarize as
sensors which measure the concentration of dust below:
particles with the size < 2.5 microns in ambient  For Task 1, 2 and 3:
air. The programe is written in C/C++ and #include <iostream>: Using to provide input
and output operations.
𝜇𝑔/𝑚3 with resolution is 0.1), store it in CSV
generate random dust value (range 1 ÷ 800
#include <vector> : Using to provide abilities to
file called “dust_sensor.csv” with multipe use function and class using the data structure
sensors with a specific time interval as a “vector”.
requirement in Task 1. The analysis part of the #include <string>: Using to provide functions
belong to Task 2 and 3 of the project to for manipulating strings.
processes data file, based on the csv file was
generated in Task 1 to filter out outliers dust #include <fstream>: Using to provide ability to
value, summarizing valid data and calculate work with file such as “ ifstream, ofstream”.
maximum minimum and average dust value of #include <sstream>: Using to provide string
the valid data. All the data will be store stream classes as: “stringstream” for easier work
respectively in different CSV files such as: with string.
“dust_outlier.csv, dust_valid.csv, dust_aqi.csv #include <bits/stdc++.h>: Includes almost all
and dust_summary.csv”, in the other hand, task standard libraries for convenience (mainly for
2.4 require to calculate total number of hours for competitive programming).
each pollution level at each sensor and generate
it in “dust_statistics.csv”.

1
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

#include <iomanip>: manage input and output


formatting such as: “strftime()”,
“setprecision()”,.. A. Task 1
#include <cmath>: Offers mathematical In this first task the goal is simply generate random
functions like power, square root, and dust value from 0 ÷ 800 µg/m3 with 0.1 resolution.
trigonometry. To do this the main fuction first parsing the
#include <ctime>: Provides tools to work with command line with respectively argc and argv[], in
time and date that, the “argc” is the number of arguments in the
command line, and the pointer “*argv[]” of each
#include <random>: Generates random numbers
strings of arguments. If it’s valid and pass through
with customizable distributions.
the file check function ( check if the file in read
#include <bits/stdc++.h>: Includes almost all mode or not ), the output file will be
standard libraries for convenience (mainly for “dust_sensor.csv”.
competitive programming).
For the value part, the programe will random
#include <stdint.h>: Provides fixed-width number between 0 to 8000, after that it will multiply
integer types for precise control over integer by 0.1 and output will be 0 to 800 as result.
size.
#include <vector>: Implements the std::vector
container, which is a dynamic array that can
resize automatically
 For printing out error in log file
(task1.log, task2.log and task3.log) the
logError() function will be used in entire
task 1 and 2. For more detail the
function will generate the respectively
error with the time at the moment the
program run.
 Task 3 reads dust data from a CSV file,
converts it into structured data packets, it
handles errors. The result is a .dat file
ensuring standardized data
communication. Figure 2: Overall Flowchart of task 1

For task 1:
In conclude of this part, the all the project file will
be stored in a folder as bellow:  Input:
o Command line
 Output:
o A CSV file name
“dust_sensor.csv”
 Pre – conditions:
o The program should be work
with correct command line
arguments.
Figure 1: Folder design o The file must have the proper
name and writable
 Post – condition:

2
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

o A csv file name  Post – conditions:


“dust_sensor.csv” must be o The “dust_valid.csv” must contain
created. dust value from 3 to 550.5 µg/m3
and the others value must be move to
“dust_outlier.csv”.
o The “dust_summary.csv” must
calculate the right max, min, median
and average of the id in 1-hour
interval so does its time’s.
o The “dust_statistic.csv” should
provide the correct total number of
hours for each pollution level at each
sensor.

In this task, it will generate 4 different csv


file as follow subtasks: task 2.1, task 2.2, task 2.3
and task 2.4 to calculating and analysis data to get
valid data, outlier data, max, min, mean, median
value of dust and changes in frequency of the dust
data.

Figure 3: Flowchart of generateData() function in task 1.

B. Task 2

For the task:


 Input: File “dust_sensor.csv”

 Output:File“dust_outlier.csv”,
“dust_valid.csv”, “dust_dust_summary.csv”,
“dust_statistics.csv”

 Pre – conditions:
o The input file “dust_sensor.csv”
must exist and readable.
o The output file “dust_valid.csv”,
“dust_outlier.csv”, Figure 3: Overall Flowchart of task 2
“dust_summary.csv”, “dust_aqi.csv"
and “dust_statistics.csv” must be For task 2.1: it’s will generate 2 files as
created and writable. “dust_valid.csv” and “dust_outlier.csv”. For valid
part, all the dust value data, which was generate
randomly in the file “dust_sensor.csv” from task 1,
3
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

which from 3 to 550.5 µg/m3 will be stored in


“dust_valid.csv” and this file will be used to C. Task 3
perform 2.3. Input: File “dust_valid.csv”
Output: File “output.dat”

Figure 4: Flowchart of DataProcessing() – main function run


subtask 2.1
Figure 5: Overall Flowchart of task 3
In task 2.2, we need to create a program to
calculate the the average dust concentration per The program expects exactly two command-line
hour based on the table 1.Finally, the resusts should arguments: the input file name and the output file
be store in a file named “dust_aqi.csv”. name. If the arguments are not provided correctly, it
prints an error message:
- Reads the first line of the input CSV file to
initialize the previous timestamp and dust values.
- For each subsequent line: Reads the sensor ID,
timestamp, and dust. Checks if the data format is
correct and if the data is duplicated. If data is
invalid or duplicated, logs an error and continues to
In task 2.3: The program will read data in the next line. If data is valid:
“dust_valid.csv” which was already generate in Converts the timestamp to Unix time format.
subtask 2.1. After that, it creates an output file in Calculates the time difference between the
write mod called: “dust_summary.csv”. Then the current and previous timestamps.
code calculating the average, maximum and Calculates the acceleration based on the current
minimum for each sensor over 1-hour intervals and and previous dusts and the time difference.
write the 3 data line in the output file. Forms a data packet with the start byte, packet
length, sensor ID, Unix timestamp, dust,
The task 2.4 requires determining calculate acceleration, checksum, and stop byte.
total number of hours for each pollution level at Computes the checksum for the data packet.
each sensor. So, the input of the program is Writes the data packet to the output file in
“dust_aqi.csv”. At the end, all the data will be print hexadecimal format.
out in “dust_statistics.csv”.

4
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

- Logs any errors encountered during file


operations or data processing to task3.log for
debugging and traceability.

III. RESULT

All the tasks are completed and working


smoothly, no run-time error occurred during the
running progress.

For Task 1, it works perfectly and successful


in generate the output file with correct form,
even when the flags and values are missing, the
code still work fine with default values as
number of sensors is 1, sampling time is 60
seconds and sampling interval is 86400 second
(24-hour). With Task 2, the program still run
without the input file and successfully in
generate all the file as requires. The max, min
and mean are calculated correctly so does the
number of frequency and the alert message as
below: Figure 6: Result of programe
For task 3: successfully converts data from
IV. CONCLUSION
a CSV file into structured data packets following a
specified communication protocol. Effective error All tasks have been completed as required. Inconclusion a
handling and data integrity assurance are key chart below shows the Percentage of contribution of
strengths of the program. However, the results group members in completing this project:
given are not as accurate as the examples given in
the article. Member/ID Task Percentage
After running successful, the program has
result as below: Đặng Nhật Minh 1 25%
20222844

Cù Minh Đạt 2.1, 2.2 25%


20222821

Lê Hoàng Vũ 2.3, 2.4 25%


20222807
Trần Hoàng Linh 3 25%
20222842

5
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

ACKNOWLEDGMENT
Giving specially thanks to Mr. Nguyen Tri Cuong for
teaching, supporting and taking the time to listen our
questions.

REFERENCES
[1] Nguyen Tri Cuong, “mini_project_20241_en_v1.pdf”,
HUST

You might also like