Skip to content

Commit

Permalink
fix avr boards compilation error and small performance improvements (#10
Browse files Browse the repository at this point in the history
)

* refactor(DataTomeMvAvg): 🎨 mean and count aliases now belongs to DataTomeMvAvg instead of DataTomeAnalysis

Mean and count aliases now belongs to DataTomeMvAvg instead of DataTomeAnalysis. Comments were fixed to reflect the changes. keywords.txt was updated.

* style(test): 🎨 fix typing case of DataTome instances on test code

* refactor(DataTomeAnalysis): ⚡ improve calculation of method var

* docs: 📝 update lib description

* fix(DataTomeAnalysis): 🚑 fix var method miscalculation

* docs: 📝 fix docs url file name

* docs(readme): 🎨 improve readme style

* docs(library_metadata): 📝 update library description

* fix(DataTome): 🐛 fixed the library compiling issue on avr boards

#12

* fix(DataTomeAnalysis): 🐛 fix qsort callback function
  • Loading branch information
AlexandreHiroyuki authored Aug 5, 2024
1 parent d0902ce commit 5ca50c8
Show file tree
Hide file tree
Showing 15 changed files with 259 additions and 160 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ build/
.idea/
CMakeSettings.json

.pio/
# Local Build Test
main.cpp

.pio/
55 changes: 53 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +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"
"DataTomeMvAvg",
"test",
"readme",
"library_metadata",
"DataTome"
]
}
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
[![Top Language](https://img.shields.io/github/languages/top/AlexandreHiroyuki/DataTome)](https://github.com/AlexandreHiroyuki/DataTome)

<p align="center">
<img src="./docs/icon.png" width="128" height="128" />
<img src="https://raw.githubusercontent.com/AlexandreHiroyuki/DataTome/main/docs/icon.png" width="128" height="128" />
</p>

## Description

Data Tome is a C++ library for data analysis and data filtering on IoT devices. Focus on the developer's experience and performance.
Data Tome is a C++ library for data analysis and data filtering on embedded devices (IoT). Focus on the developer's experience and performance.

## Getting Started

Expand All @@ -28,14 +28,14 @@ Data Tome is a C++ library for data analysis and data filtering on IoT devices.

This library calculates statistical functions using a time-series sample implemented with a circular array that improves the performance.

> Online Docs: _[Click here to see the full documentation](https://alexandrehiroyuki.github.io/DataTomeDocs/)_
>
> Docs GitHub Repository: _[The documentation is coded with docusaurus, and you can visit the repository](https://github.com/AlexandreHiroyuki/DataTomeDocs)_
- Online Docs: _[Click here to see the full documentation](https://alexandrehiroyuki.github.io/DataTomeDocs/)_

- Docs GitHub Repository: _[The documentation is coded with docusaurus, and you can visit the repository](https://github.com/AlexandreHiroyuki/DataTomeDocs)_

## Contributing

[Read here how to contribute](https://github.com/AlexandreHiroyuki/DataTome/blob/master/CONTRIBUTING.md).

## Developed by

**Alexandre Hiroyuki**[GitHub](https://github.com/AlexandreHiroyuki)[LinkedIn](https://www.linkedin.com/in/alexandre-hiroyuki-yamauchi-7137241a6/)
**Alexandre Hiroyuki**[GitHub](https://github.com/AlexandreHiroyuki)[LinkedIn](https://www.linkedin.com/in/alexandre-hiroyuki-yamauchi/)
File renamed without changes.
15 changes: 15 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,43 @@ DataTomeAnalysis KEYWORD1
push KEYWORD2
get KEYWORD2
get_by_brute KEYWORD2
mean KEYWORD2

front KEYWORD2
back KEYWORD2

atIndex KEYWORD2
size KEYWORD2
point_count KEYWORD2
count KEYWORD2

grow KEYWORD2
resize KEYWORD2
clear KEYWORD2

partial_create KEYWORD2
partial_get KEYWORD2
partial_mean KEYWORD2
partial_size KEYWORD2
partial_point_count KEYWORD2
partial_count KEYWORD2

#######################################
# Methods and Functions (KEYWORD2)
# DataTomeAnalysis
#######################################

min KEYWORD2
max KEYWORD2
median KEYWORD2
lowest_mode KEYWORD2
highest_mode KEYWORD2
std KEYWORD2
var KEYWORD2
partial_min KEYWORD2
partial_max KEYWORD2
partial_median KEYWORD2
partial_lowest_mode KEYWORD2
partial_highest_mode KEYWORD2
partial_var KEYWORD2
partial_std KEYWORD2
8 changes: 5 additions & 3 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
"name": "DataTome",
"version": "1.6.3",
"description": "Data Tome is a C++ library for data analysis and data filtering on IoT devices. Focus on the developer's experience and performance.",
"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": {
"type": "git",
Expand Down Expand Up @@ -43,7 +43,9 @@
],
"export": {
"exclude": [
".github"
".github",
".gitignore",
".vscode"
]
},
"srcDir": "src"
Expand Down
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=DataTome
version=1.6.3
version=1.7.0
author=Alexandre Hiroyuki Yamauchi <alex.hiroyuki@outlook.com>
maintainer=Alexandre Hiroyuki Yamauchi <alex.hiroyuki@outlook.com>
sentence=Moving Average and other statistical functions compatible with any number type.
paragraph=Fully documented. Data Tome is a C++ library for data analysis and data filtering on IoT devices. Focus on the developer experience and performance.
sentence=Data analysis and filtering using time series for embedded devices (IoT). All in a single C++ library, Data Tome.
paragraph=Fully documented. Focus on the developer's experience and performance.
category=Data Processing
url=https://github.com/AlexandreHiroyuki/DataTome
architectures=*
9 changes: 7 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/DataTome.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@

#include <DataTomeAnalysis.h>
#include <DataTomeMvAvg.h>
#include <DataTomeUtils.h>

#endif // DATA_TOME_H
75 changes: 29 additions & 46 deletions src/DataTomeAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,31 @@
#define DATA_TOME_ANALYSIS_H

#include <DataTomeMvAvg.h>

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <DataTomeUtils.h>
#include <math.h>
#include <stdlib.h>

template <typename TypeOfArray, typename TypeOfSum = TypeOfArray>
class DataTomeAnalysis : public DataTomeMvAvg<TypeOfArray, TypeOfSum> {
public:
DataTomeAnalysis(size_t size) : DataTomeMvAvg<TypeOfArray, TypeOfSum>(size) {}

/** Aliases **/

TypeOfArray mean() { return this->get(); }
size_t count() { return this->point_count(); }

/** Proper Methods **/

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() {
Expand All @@ -52,7 +44,7 @@ class DataTomeAnalysis : public DataTomeMvAvg<TypeOfArray, TypeOfSum> {

memcpy(temp, this->_array, current_size * sizeof(TypeOfArray));

std::sort(temp, temp + current_size);
qsort(temp, current_size, sizeof(TypeOfArray), sort_ascend<TypeOfArray>);

if (current_size % 2 == 0) {
median = (temp[current_size / 2 - 1] + temp[current_size / 2]) / 2;
Expand All @@ -73,7 +65,7 @@ class DataTomeAnalysis : public DataTomeMvAvg<TypeOfArray, TypeOfSum> {

memcpy(temp, this->_array, current_size * sizeof(TypeOfArray));

std::sort(temp, temp + current_size);
qsort(temp, current_size, sizeof(TypeOfArray), sort_ascend<TypeOfArray>);

size_t max_count = 0;
TypeOfArray mode = temp[0];
Expand Down Expand Up @@ -108,7 +100,7 @@ class DataTomeAnalysis : public DataTomeMvAvg<TypeOfArray, TypeOfSum> {

memcpy(temp, this->_array, current_size * sizeof(TypeOfArray));

std::sort(temp, temp + current_size);
qsort(temp, current_size, sizeof(TypeOfArray), sort_ascend<TypeOfArray>);

size_t max_count = 0;
TypeOfArray mode = temp[0];
Expand Down Expand Up @@ -140,7 +132,8 @@ class DataTomeAnalysis : public DataTomeMvAvg<TypeOfArray, TypeOfSum> {

TypeOfArray var = 0;
for (size_t i = 0; i < this->point_count(); i++) {
var += ((*this)[i] - average) * ((*this)[i] - average);
TypeOfArray data_point = (*this)[i] - average;
var += (data_point) * (data_point);
}

return var;
Expand All @@ -150,33 +143,22 @@ class DataTomeAnalysis : public DataTomeMvAvg<TypeOfArray, TypeOfSum> {

/** Partial Methods **/

/** Aliases **/

TypeOfArray partial_mean(size_t partial_id) {
return this->partial_get(partial_id);
}
size_t partial_count(size_t partial_id) {
return this->partial_size(partial_id);
}

/** Proper 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) {
Expand All @@ -190,7 +172,7 @@ class DataTomeAnalysis : public DataTomeMvAvg<TypeOfArray, TypeOfSum> {
temp[i] = (*this)[i];
}

std::sort(temp, temp + current_size);
qsort(temp, current_size, sizeof(TypeOfArray), sort_ascend<TypeOfArray>);

if (current_size % 2 == 0) {
median = (temp[current_size / 2 - 1] + temp[current_size / 2]) / 2;
Expand All @@ -213,7 +195,7 @@ class DataTomeAnalysis : public DataTomeMvAvg<TypeOfArray, TypeOfSum> {
temp[i] = (*this)[i];
}

std::sort(temp, temp + current_size);
qsort(temp, current_size, sizeof(TypeOfArray), sort_ascend<TypeOfArray>);

size_t max_count = 0;
TypeOfArray mode = temp[0];
Expand Down Expand Up @@ -250,7 +232,7 @@ class DataTomeAnalysis : public DataTomeMvAvg<TypeOfArray, TypeOfSum> {
temp[i] = (*this)[i];
}

std::sort(temp, temp + current_size);
qsort(temp, current_size, sizeof(TypeOfArray), sort_ascend<TypeOfArray>);

size_t max_count = 0;
TypeOfArray mode = temp[0];
Expand Down Expand Up @@ -282,7 +264,8 @@ class DataTomeAnalysis : public DataTomeMvAvg<TypeOfArray, TypeOfSum> {

TypeOfArray var = 0;
for (size_t i = 0; i < this->partial_point_count(partial_id); i++) {
var += ((*this)[i] - average) * ((*this)[i] - average);
TypeOfArray data_point = (*this)[i] - average;
var += (data_point) * (data_point);
}

return var;
Expand Down
Loading

0 comments on commit 5ca50c8

Please sign in to comment.