-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlidingArray.h
More file actions
139 lines (109 loc) · 4.37 KB
/
SlidingArray.h
File metadata and controls
139 lines (109 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
File: SlidingArray.h
Version: 0.0.6
Date: 05-Jan-2019
Revision: 15-Jun-2019
Author: Jerome Drouin (jerome.p.drouin@gmail.com)
SlidingArray.h - Library for 'duino
https://github.com/JeromeDrouin/SlidingArray
Copyright (c) 2018 Jerome Drouin All rights reserved.
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
Editions:
- 0.0.1 : First version
- 0.0.2 : Addition of imin, imax members variables MinID and MaxID
member methods
- 0.0.3 : Addition of variance, stddeviation
- 0.0.4 : Renaming PopulateArray into AddArgument
Adding a Slow (Add) and a Fast (Add_NoMom) mode to the
Add method to deal with speed.
- Add_NoMom only adds data the the sliding array: statistics can be
recalculated later via the Get methods.
- Add adds data and calculates min, max, mean, variance &
stddeviation on the fly.
- 0.0.5 : Renaming AddArgument, AddArgument_NoMom into Add and Add_Fast
Renaming ClearArray into Flush
- 0.0.6 : Introducing NOTAVAIL
*/
// ensure this library description is only included once
#ifndef SlidingArray_h
#define SlidingArray_h
#include "Arduino.h"
// DEFINES /////////////////////////////////////////////////////////////
#define VER_SlidingArray "0.0.6" //
#define REL_SlidingArray "15Jun2019" //
#define NOTAVAIL -9999
#define MAX_ARRAY_SIZE 10000
#define MAX_FLOAT_VALUE 0xFFFFFFFF
#define MIN_FLOAT_VALUE -3.4028235E+38
// library interface description
class SlidingArray
{
// user-accessible "public" interface
public:
// methods
SlidingArray(void);
explicit SlidingArray(int _arraySize);
~SlidingArray();
void Flush();
void Sort(int operation);
void Trim(int low_pos, int high_pos);
void Add_Fast(float Obs); // Fast version of Add with No Moments calculated
void Add(float Obs); // Slower version of Add with standard moments cacl'ed on the fly.
// if control=1, this method recalculates all moments
int PushArgument(int pos, float Obs);
float PullArgument(int pos);
float GetArgument(int pos);
int GetSize(void);
int GetCount(void);
bool IsFull(void);
bool HasArgs(void);
float GetSum_xi(void);
float GetSum_xi2(void);
float RecalcAverage(void); // Recalculate and return Average, Variance, etc.
float RecalcVariance(void);
float RecalcStdDeviation(void);
float RecalcMin(void);
float RecalcMax(void);
float GetAverage(void); // Return the pre-calculated Average, Variance, etc.
float GetVariance(void);
float GetStdDeviation(void);
float GetMin(void);
float GetMax(void);
int GetMaxID(void);
int GetMinID(void);
String GetVersion();
String GetReleaseDate();
// library-accessible "private" interface
//private:
void RecalcAllMoments(void);
protected:
// variables
int error;
int isMom; // Control parameter for Add_NoMom call. =0 after NoMom called. =1 after
// Add called. GetAverage(), GetVariance, GetStdDeviation() are unavailable when
// isMom is not equal to 1
int size; // Size of Array
int count; // current Size of Array
float sum_xi; // current sum or args for average. Calculated automatically after each Populate
float sum_xi2; // current sum or args^2 for variance. Calculated automatically after each Populate
float average; // current average. Calculated automatically after each Populate
float variance; // current variance. Calculated automatically after each Populate
float stddeviation; // current stddeviation. Calculated automatically after each Populate
float cmin; // current minimum. Calculated automatically after each Populate
float cmax; // current maximum. Calculated automatically after each Populate
int imax; // The array position of Max
int imin; // The array position of Min
float * arg; // Array values
// methods
};
#endif
// END OF FILE