Skip to content

brittleru/Java-Sensor-Data-From-CSV-v2

Repository files navigation

Java program for parsing data from CSV and creating new CSVs version 2.0

This is a project I had in university in the third year at the Java and Python Programming course. This course was taught by Conf. Dr. Ing. Victor Constantin.
I had to find a way to parse a comma separated values (CSV) file which had some data from sensors, the CSV had three different columns for temperatures, three different columns for humidity, one for velocity, two columns for presence (it was a Boolean value), one row for time for that particular value and one for current number.
The task was to create a different CSV for each type of values form the sensors (e.g., one CSV for all three columns of temperatures). Every CSV needed to have a column (beside the values) for the date when the readings were done and also a column for the current number.
There were some restrictions for each new CSV:

  • Temperature: there I had to overwrite the value to be between -5 and 5 and set it to -5 if it was lower than -5 and 5 if it was higher than 5.
  • Humidity: there I had to overwrite the values form the sensor to be 40 if they are lower than 40
  • Velocity: there I had to increment the value from the sensor with 1

My solution

This is my second solution for the project. This solution is more OOP based and each line is commented (being my final solution). Here I used System.getProperty(“user.dir”) to avoid hardcoding the path, that line is for the current directory of the java project.
I created only one class with two private methods first is enrange(Double value, Double min, Double max), this method is used to delete verify the data for the overwriting and the second one is getValue(String[] row, int index) this method is checking for the column for each type of value form the sensor and return the first private method. This class also have a method GenerateCSV(String in, String out, int… columns) for generating the CSV :>, for that I used a for loop for every line in the CSV and then a foreach loop where for the values I called the getValue() function.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages