diff --git a/.gitignore b/.gitignore index 485f2a8..de51fbd 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,7 @@ build/ .idea/ CMakeSettings.json -.pio/ \ No newline at end of file +# Local Build Test +main.cpp + +.pio/ diff --git a/.vscode/settings.json b/.vscode/settings.json index f8c2dbf..63a6748 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,15 +1,63 @@ { "files.associations": { + "*.postcss": "tailwindcss", + "*.svelte": "svelte", + "*.html": "html", "array": "cpp", "string_view": "cpp", "initializer_list": "cpp", - "utility": "cpp" + "utility": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "fstream": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" }, "conventionalCommits.scopes": [ "DataTomeAnalysis", "DataTomeMvAvg", "test", "readme", - "library_metadata" + "library_metadata", + "DataTome" ] } \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1e0029e..0230747 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,10 @@ Open an issue on the repository and provide the following information: 2. What board and/or framework are you using? 3. How can the issue be reproduced? Provide a minimal code snippet that reproduces the issue if possible. +## Code Convention + +- Don't include C++ standard library functions, because it does not compile for AVR boards (C std libs still works). + ## Testing The library comes with a set of automated tests. Contributions should include tests to cover the new functionality and ensure that no regressions are introduced. diff --git a/library.json b/library.json index dc1caf6..04b6f29 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json", "name": "DataTome", - "version": "1.6.3", + "version": "1.7.0", "description": "Data analysis and filtering using time series for embedded devices (IoT). All in a single C++ library, Data Tome. Focus on the developer's experience and performance.", "keywords": "sensors, input, data, processing, analysis, arduino, library, filter, moving average, smooth, standard, deviation, mean, partial, tome, datatome", "repository": { diff --git a/library.properties b/library.properties index 8b7b490..53dfc04 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=DataTome -version=1.6.3 +version=1.7.0 author=Alexandre Hiroyuki Yamauchi maintainer=Alexandre Hiroyuki Yamauchi sentence=Data analysis and filtering using time series for embedded devices (IoT). All in a single C++ library, Data Tome. diff --git a/platformio.ini b/platformio.ini index 89189c3..3ee1e86 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,7 +13,12 @@ platform = espressif32 board = esp32dev framework = arduino +[env:arduino_avr] +framework = arduino +platform = atmelavr +board = uno + [env:desktop] platform = native -build_flags = - -D unitTesting +build_flags = -D unitTesting +build_type = test diff --git a/src/DataTomeAnalysis.h b/src/DataTomeAnalysis.h index 23b93d4..fbd6e5a 100644 --- a/src/DataTomeAnalysis.h +++ b/src/DataTomeAnalysis.h @@ -8,32 +8,30 @@ #define DATA_TOME_ANALYSIS_H #include - -#include -#include -#include +#include +#include template class DataTomeAnalysis : public DataTomeMvAvg { public: DataTomeAnalysis(size_t size) : DataTomeMvAvg(size) {} - TypeOfArray min() { - TypeOfArray min = (*this)[0]; + TypeOfArray minimum() { + TypeOfArray result = (*this)[0]; for (size_t i = 1; i < this->point_count(); i++) { - if ((*this)[i] < min) min = (*this)[i]; + if ((*this)[i] < result) result = (*this)[i]; } - return min; + return result; } - TypeOfArray max() { - TypeOfArray max = (*this)[0]; + TypeOfArray maximum() { + TypeOfArray result = (*this)[0]; for (size_t i = 1; i < this->point_count(); i++) { - if ((*this)[i] > max) max = (*this)[i]; + if ((*this)[i] > result) result = (*this)[i]; } - return max; + return result; } TypeOfArray median() { @@ -45,7 +43,10 @@ class DataTomeAnalysis : public DataTomeMvAvg { memcpy(temp, this->_array, current_size * sizeof(TypeOfArray)); - std::sort(temp, temp + current_size); + qsort(temp, current_size, sizeof(TypeOfArray), + [](const void *a, const void *b) -> int { + return (*(TypeOfArray *)a - *(TypeOfArray *)b); + }); if (current_size % 2 == 0) { median = (temp[current_size / 2 - 1] + temp[current_size / 2]) / 2; @@ -66,7 +67,10 @@ class DataTomeAnalysis : public DataTomeMvAvg { memcpy(temp, this->_array, current_size * sizeof(TypeOfArray)); - std::sort(temp, temp + current_size); + qsort(temp, current_size, sizeof(TypeOfArray), + [](const void *a, const void *b) -> int { + return (*(TypeOfArray *)a - *(TypeOfArray *)b); + }); size_t max_count = 0; TypeOfArray mode = temp[0]; @@ -101,7 +105,10 @@ class DataTomeAnalysis : public DataTomeMvAvg { memcpy(temp, this->_array, current_size * sizeof(TypeOfArray)); - std::sort(temp, temp + current_size); + qsort(temp, current_size, sizeof(TypeOfArray), + [](const void *a, const void *b) -> int { + return (*(TypeOfArray *)a - *(TypeOfArray *)b); + }); size_t max_count = 0; TypeOfArray mode = temp[0]; @@ -144,22 +151,22 @@ class DataTomeAnalysis : public DataTomeMvAvg { /** Partial Methods **/ - TypeOfArray partial_min(size_t partial_id) { - TypeOfArray min = (*this)[0]; + TypeOfArray partial_minimum(size_t partial_id) { + TypeOfArray result = (*this)[0]; for (size_t i = 1; i < this->partial_point_count(partial_id); i++) { - if ((*this)[i] < min) min = (*this)[i]; + if ((*this)[i] < result) result = (*this)[i]; } - return min; + return result; } - TypeOfArray partial_max(size_t partial_id) { - TypeOfArray max = (*this)[0]; + TypeOfArray partial_maximum(size_t partial_id) { + TypeOfArray result = (*this)[0]; for (size_t i = 1; i < this->partial_point_count(partial_id); i++) { - if ((*this)[i] > max) max = (*this)[i]; + if ((*this)[i] > result) result = (*this)[i]; } - return max; + return result; } TypeOfArray partial_median(size_t partial_id) { @@ -173,7 +180,10 @@ class DataTomeAnalysis : public DataTomeMvAvg { temp[i] = (*this)[i]; } - std::sort(temp, temp + current_size); + qsort(temp, current_size, sizeof(TypeOfArray), + [](const void *a, const void *b) -> int { + return (*(TypeOfArray *)a - *(TypeOfArray *)b); + }); if (current_size % 2 == 0) { median = (temp[current_size / 2 - 1] + temp[current_size / 2]) / 2; @@ -196,7 +206,10 @@ class DataTomeAnalysis : public DataTomeMvAvg { temp[i] = (*this)[i]; } - std::sort(temp, temp + current_size); + qsort(temp, current_size, sizeof(TypeOfArray), + [](const void *a, const void *b) -> int { + return (*(TypeOfArray *)a - *(TypeOfArray *)b); + }); size_t max_count = 0; TypeOfArray mode = temp[0]; @@ -233,7 +246,10 @@ class DataTomeAnalysis : public DataTomeMvAvg { temp[i] = (*this)[i]; } - std::sort(temp, temp + current_size); + qsort(temp, current_size, sizeof(TypeOfArray), + [](const void *a, const void *b) -> int { + return (*(TypeOfArray *)a - *(TypeOfArray *)b); + }); size_t max_count = 0; TypeOfArray mode = temp[0]; diff --git a/src/DataTomeMvAvg.h b/src/DataTomeMvAvg.h index 60588d7..aa189df 100644 --- a/src/DataTomeMvAvg.h +++ b/src/DataTomeMvAvg.h @@ -5,8 +5,8 @@ #ifndef DATA_TOME_MV_AVG_H #define DATA_TOME_MV_AVG_H -#include -#include // memset +#include +#include // memset template class DataTomeMvAvg { @@ -159,6 +159,8 @@ class DataTomeMvAvg { DataTomeMvAvg &clear() { memset(_array, 0, sizeof(TypeOfArray) * _array_size); + memset(_partial_sums, 0, sizeof(TypeOfArray) * _partial_sums_counter); + _current_index = 0; _average_sum = 0; diff --git a/test/test_DataTomeAnalysis/DataTomeAnalysis.test.cpp b/test/test_DataTomeAnalysis/DataTomeAnalysis.test.cpp index 62615c6..2afc7f9 100644 --- a/test/test_DataTomeAnalysis/DataTomeAnalysis.test.cpp +++ b/test/test_DataTomeAnalysis/DataTomeAnalysis.test.cpp @@ -16,8 +16,8 @@ void test_minAndMax(void) { testAnalysis.push(data[i]); } - TEST_ASSERT_EQUAL(data[0], testAnalysis.min()); - TEST_ASSERT_EQUAL(data[9], testAnalysis.max()); + TEST_ASSERT_EQUAL(data[0], testAnalysis.minimum()); + TEST_ASSERT_EQUAL(data[9], testAnalysis.maximum()); } void test_median(void) { @@ -87,8 +87,8 @@ void test_partialMinAndMax(void) { testAnalysis.push(data[i]); } - TEST_ASSERT_EQUAL(data[2], testAnalysis.partial_min(partial_id)); - TEST_ASSERT_EQUAL(data[4], testAnalysis.partial_max(partial_id)); + TEST_ASSERT_EQUAL(data[2], testAnalysis.partial_minimum(partial_id)); + TEST_ASSERT_EQUAL(data[4], testAnalysis.partial_maximum(partial_id)); } void test_partialMedian(void) {