Giter Club home page Giter Club logo

gbj_appfilter's Introduction

gbj_appfilter

This is an application library, which is used usually as a project library for particular PlatformIO project. It unifies and encapsulates the functionality of data filtering with valid data range for measures with various data types. The encapsulation provides following advantages:

  • Functionality is hidden from the main sketch.
  • The library follows the principle separation of concerns.
  • Update in library is valid for all involved projects.
  • The library manages the filtering and provides the same interface for various data types without need of comparison expressions.

Fundamental functionality

  • The library is templated, so that it can utilize various data types.
  • It provides filtering of samples against their valid range by setting minimal and maximal valid values.
  • It evaluates the difference between consecutive values for filtering as well.
  • The library caches the recent input value as well as consecutive value change, so that all methods can be used on it without any argument, which avoids using always the same input value.
  • If none input value has been provided since creation of the instance object at calling some method without input argument, the zero value is implicitly used as a cached value.
  • Until an input value is provided and cached, the instance object is considered as not initialized. In that case all methods returning the logical value returns false.
  • At the very first input value since creation of the instance object, the values change from previous value is considered as zero.

Dependency

Arduino platform

  • Arduino.h: Main include file for the Arduino SDK.
  • inttypes.h: Integer type conversions. This header file includes the exact-width integer definitions and extends them with additional facilities provided by the implementation.

Espressif ESP8266 platform

  • Arduino.h: Main include file for the Arduino platform.

Espressif ESP32 platform

  • Arduino.h: Main include file for the Arduino platform.

Particle platform

  • Particle.h: Includes alternative (C++) data type definitions.

Unit testing

The subfolder tests in the folder extras, i.e., gbj_appfilter/extras/test, contains testing file(s) with unit tests of library gbj_appfilter executable by Unity test runner. Each testing file should be placed in an individual test folder of a particular project, usually in the structure test/<testname>/<testfile>.

  • test_filter.cpp: Test file providing test cases for standard filtering.
  • test_filter_change_float.cpp: Test file providing test cases for change management of float values filtering.

Constants

  • VERSION: Name and semantic version of the library.

Interface

Setters

Getters

gbj_appfilter()

Description

Constructor creates the class instance with initial valid range limits and maximal valid change of consecutive inputs applied at filtering.

  • It is templated for various data types.
  • If constructor has just one argument, that one is considered as the maximum of general valid range.
  • If both arguments for valid range are defined, the constructor sorts them internally if needed.
  • Initial limits and difference can be overriden by corresponding setters.

Syntax

gbj_appfilter<typename DAT>(DAT valMax, DAT valMin, DAT difMax)

Parameters

  • DAT: Data type of input values.

    • Valid values: various
    • Default value: float
  • valMax: Maximum of valid range.

    • Valid values: by templated data type
    • Default value: none
  • valMin: Minimum of valid range.

    • Valid values: by templated data type
    • Default value: 0
  • difMax: Maximal consecutive change of values for their validity. Only the absolute value of the difference is internally stored. It is limited to the current valid range, i.e., to the difference between maximum and minimum of valid range.

    • Valid values: by templated data type
    • Default value: 0

Returns

Object performing filtering management.

Example

#include "gbj_appfilter.h"

gbj_appfilter filterFloat = gbj_appfilter(54.3, 23.4, 10.5);
gbj_appfilter<int> filterInt = gbj_appfilter<int>(50, -10);
gbj_appfilter<unsigned int> filterUint = gbj_appfilter<unsigned int>(50);

See also

setMinimum(), setMaximum()

setDifference()

Back to interface

init()

Description

The method initializes the instance object and sets its status as it would be just created, i.e., without any input value cached.

  • It might be useful for unit tests.
  • It is used for resetting the change filtering management.

Syntax

void init()

Parameters

None

Returns

None

See also

gbj_appfilter()

isInit()

Back to interface

limit()

Description

The overloaded method constrains either the input value or cached value to actual valid range defined either by constructor or by setters.

  • In case of no input argument, the method uses the internally cached value input by some of previous methods calls.
  • Implicit (initial, default) cached value is zero.
  • If input or cached value is less than current minimum of valid range, it returns that minimum.
  • If input or cached is greater than current maximum of valid range, it returns that maximum.

Syntax

DAT limit(DAT data)
DAT limit()

Parameters

  • data: Value to be constrained.
    • Valid values: by templated data type
    • Default value: none

Returns

Value limited to the current valid range.

See also

gbj_appfilter()

setMinimum(), setMaximum()

Back to interface

setMinimum(), setMaximum()

Description

The particular method sets the corresponding extreme of the valid range for filtering.

  • Input value in contrast to the constructor is not sanitized neither sorted internally, just stored in the instance object.

Syntax

void setMinimum(DAT data)
void setMaximum(DAT data)

Parameters

  • data: Corresponding extreme value of the valid range.
    • Valid values: by templated data type
    • Default value: none

Returns

None

See also

gbj_appfilter()

Back to interface

setDifference()

Description

The method sets the maximal valid difference between consecutive input values.

  • Input value in contrast to the constructor is not sanitized neither sorted internally, just stored in the instance object.
  • Only the absolute value is internally stored.
  • The valid difference is limited to the current valid range, i.e., to the difference between maximum and minimum of valid range.

Syntax

void setDifference(DAT data)

Parameters

  • data: Corresponding maximal valid difference.
    • Valid values: by templated data type
    • Default value: none

Returns

None

See also

gbj_appfilter()

Back to interface

setValue()

Description

The method caches provided input value for further usage by methods without input argument as well as initiates for change filtering management.

Syntax

void setValue(DAT data)

Parameters

  • data: Value to be cached for filtering.
    • Valid values: by templated data type and valid range
    • Default value: none

Returns

None

See also

getValue()

isInit()

Back to interface

getMinimum(), getMaximum()

Description

The particular method returns current (recently set) extreme value for the valid range.

Syntax

DAT getMinimum()
DAT getMaximum()

Parameters

None

Returns

Corresponding recent extreme value of the valid range.

See also

setMinimum(), setMaximum()

Back to interface

getDifference()

Description

The method returns current (recently set) maximal valid difference of consecutive values.

Syntax

DAT getDifference()

Parameters

None

Returns

Recent valid difference.

See also

setDifference()

Back to interface

getValue()

Description

The method returns currently cached value, which is recently input value, but not filtered against current valid range.

Syntax

DAT getValue()

Parameters

None

Returns

Recently cached value.

See also

setValue()

Back to interface

isInit()

Description

The method returns flag determining whether the library instance object is initiated, i.e., whether some input value has been cached.

Syntax

bool isInit()

Parameters

None

Returns

Flag determining initiation status of the instance object.

See also

init()

Back to interface

isValid(), isInvalid()

Description

The particular overloaded method returns flag determining corresponding result of checking the input or recently cached value against the valid range and against valid consecutive change, if the maximal valid difference has been defined.

Syntax

bool isValid(DAT data)
bool isValid()
bool isInvalid(DAT data)
bool isInvalid()

Parameters

  • data: Value to be checked against the current valid range.
    • Valid values: by templated data type
    • Default value: none

Returns

Flag determining result of checking the input or recently cached value against the valid range and maximal valid difference.

Back to interface

isJump()

Description

The overloaded method returns flag determining whether the consecutive current or recently cached value change exceeds the maximal valid difference, if it has been defined.

  • It is the main method for consecutive change filtering management.
  • If the change is above the valid difference, the value is invalid as well.
  • The method always returns false flag, if the maximal valid difference has not been initialized yet.
  • The method always returns false flag, if the instance object has not been initialized yet, i.e., no input value has been used including this call since the instance object creation or initiation.

Syntax

bool isJump(DAT data)
bool isJump()

Parameters

  • data: Value to be checked against the current maximal valid difference.
    • Valid values: by templated data type
    • Default value: none

Returns

Flag determining result of checking consecutive change of the input or recently cached value against the maximal valid difference.

Back to interface

isLow(), isHigh()

Description

The particular overloaded method returns flag determining whether the input or recently cached value is below or above the valid range.

  • If the value is outside the valid range, it is invalid as well.

Syntax

bool isLow(DAT data)
bool isLow()
bool isHigh(DAT data)
bool isHigh()

Parameters

  • data: Value to be checked against an extreme of the current valid range.
    • Valid values: by templated data type
    • Default value: none

Returns

Flag determining result of checking the input or recently cached value against corresponding extreme of the valid range.

Back to interface

isDecr(), isIncr(), isEqual()

Description

The particular overloaded method returns flag determining whether the cached consecutive value change is negative (decremented), positive (incremented), or none (equal).

  • The methods always return false flag, if the instance object has not been initialized yet, i.e., no input value has been used used including this call since the instance object creation or initiation.
  • The methods are usable regardless of definition of maximal valid difference.

Syntax

bool isDecr(DAT data)
bool isDecr()
bool isIncr(DAT data)
bool isIncr()
bool isEqual(DAT data)
bool isEqual()

Parameters

  • data: Value to be checked against the polarity of the consecutive value change.
    • Valid values: by templated data type
    • Default value: none

Returns

Flag determining result of checking the consecutive value change polarity.

Back to interface

gbj_appfilter's People

Contributors

mrkale avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.