-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Implemented Statistics and DataProcessing API - Added automatic parameter values history and statistics (PSRAM required)
- Loading branch information
Showing
13 changed files
with
448 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* HomeGenie-Mini (c) 2018-2024 G-Labs | ||
* | ||
* | ||
* This file is part of HomeGenie-Mini (HGM). | ||
* | ||
* HomeGenie-Mini is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* HomeGenie-Mini is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with HomeGenie-Mini. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* | ||
* Authors: | ||
* - Generoso Martello <[email protected]> | ||
* | ||
*/ | ||
|
||
#include "Statistics.h" | ||
|
||
#ifndef DISABLE_DATA_PROCESSING | ||
|
||
namespace Data { namespace Processing { | ||
|
||
int Statistics::historyIndex = 0; | ||
bool Statistics::historyIsFull = false; | ||
StatValue **Statistics::History = nullptr; | ||
|
||
}} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* HomeGenie-Mini (c) 2018-2024 G-Labs | ||
* | ||
* | ||
* This file is part of HomeGenie-Mini (HGM). | ||
* | ||
* HomeGenie-Mini is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* HomeGenie-Mini is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with HomeGenie-Mini. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* | ||
* Authors: | ||
* - Generoso Martello <[email protected]> | ||
* | ||
*/ | ||
|
||
#ifndef HOMEGENIE_MINI_STATISTICS_H | ||
#define HOMEGENIE_MINI_STATISTICS_H | ||
|
||
#include "io/IOEventData.h" | ||
#include "Module.h" | ||
|
||
#ifndef DISABLE_DATA_PROCESSING | ||
|
||
namespace Data { namespace Processing { | ||
|
||
using IO::IOEventDataType; | ||
using Data::ModuleParameter; | ||
|
||
class StatValue { | ||
public: | ||
ModuleParameter *parameter; | ||
double value; | ||
double timestamp; | ||
|
||
StatValue() { | ||
parameter = nullptr; | ||
value = 0; | ||
timestamp = 0; | ||
} | ||
}; | ||
|
||
const unsigned int STATS_HISTORY_LIMIT = 2000; | ||
const unsigned int STATS_HISTORY_RESULTS_DEFAULT_PAGE_SIZE = 100; | ||
|
||
class Statistics { | ||
public: | ||
Statistics() { | ||
History = (StatValue **) ps_malloc(STATS_HISTORY_LIMIT * sizeof(StatValue *)); | ||
} | ||
|
||
static size_t getHistorySize() { | ||
return historyIsFull ? STATS_HISTORY_LIMIT : historyIndex; | ||
} | ||
|
||
static StatValue *getHistory(int position) { | ||
auto i = (historyIndex - position - 1); | ||
if (i < 0) i = STATS_HISTORY_LIMIT - i; | ||
return History[i % STATS_HISTORY_LIMIT]; | ||
} | ||
|
||
static unsigned int collect(ModuleParameter *parameter) { | ||
auto ci = historyIndex; | ||
auto sv = (StatValue *) ps_malloc(sizeof(StatValue)); | ||
sv->parameter = parameter; | ||
sv->value = parameter->value.toDouble(); | ||
// unix timestamp in milliseconds | ||
sv->timestamp = ((double) Config::getRTC()->getEpoch()) + ((double) (millis() % 1000) / 1000.0f); | ||
|
||
if (historyIsFull) free(History[ci]); | ||
History[ci] = sv; | ||
|
||
// circular / overwrite old data... | ||
if (++historyIndex > STATS_HISTORY_LIMIT - 1) { | ||
historyIndex = 0; | ||
historyIsFull = true; | ||
} | ||
|
||
return ci; | ||
} | ||
|
||
private: | ||
static int historyIndex; | ||
static StatValue **History; | ||
static bool historyIsFull; | ||
}; | ||
|
||
}} | ||
|
||
#endif // DISABLE_DATA_PROCESSING | ||
|
||
#endif //HOMEGENIE_MINI_STATISTICS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.