HomeWaterLeaksDetection
Consumption Class Reference

#include <Consumption.h>

Public Types

enum  Type { DAY, WEEK, MONTH }
 Type of the monitoring period. More...
 

Public Member Functions

 Consumption (PulseCounter *pulseCounter, Type type)
 Constructor of the class. More...
 
void update ()
 Updates the variables. More...
 
int getConsumptionCount () const
 Returns the current number of pulses detected so far within the monitoring period. More...
 

Private Attributes

PulseCounterpulseCounter
 instance of PulseCounter (input [l]) More...
 
RTCDateTime initialDateTime
 instance of RTCDateTime (real-time module) More...
 
int count
 number of pulses detected within the monitoring period More...
 
Type type
 type of the monitoring period More...
 

Detailed Description

Author
silhavyj A17B0362P

This class is used to monitor daily, weekly, or monthly.

Definition at line 13 of file Consumption.h.

Member Enumeration Documentation

◆ Type

Type of the monitoring period.

It is set through the constructure when creating an instance.

Enumerator
DAY 

daily water consumption

WEEK 

weekly water consumption

MONTH 

monthly water consumption

Definition at line 19 of file Consumption.h.

19  {
20  DAY,
21  WEEK,
22  MONTH
23  };

Constructor & Destructor Documentation

◆ Consumption()

Consumption::Consumption ( PulseCounter pulseCounter,
Type  type 
)

Constructor of the class.

Parameters
pulseCounterinstance of PulseCounter (input)
typeof the monitoring period

Definition at line 3 of file Consumption.cpp.

3  {
4  this->pulseCounter = pulseCounter;
5  this->type = type;
6 
8  count = 0;
9 }

References count, DateTime::getDateTime(), DateTime::getInstance(), initialDateTime, pulseCounter, and type.

Member Function Documentation

◆ getConsumptionCount()

int Consumption::getConsumptionCount ( ) const

Returns the current number of pulses detected so far within the monitoring period.

Returns
number of pulses detected so far

Definition at line 44 of file Consumption.cpp.

44  {
45  return count;
46 }

References count.

Referenced by DailyOverview::update().

◆ update()

void Consumption::update ( )

Updates the variables.

If a pulse has just been detected, it will increment the counter. Also, if the monitoring period is over, it will reset the counter. This method is supposed to be called as frequently as possible in order to achieve precise results.

Definition at line 11 of file Consumption.cpp.

11  {
12  bool timeToReset = 0;
13  RTCDateTime currentDateTime = DateTime::getInstance()->getDateTime();
14 
15  // check if it's time to reset the counter as the
16  // monitoring period might be over
17  switch (type) {
18  case DAY:
19  // test if the current day is different
20  if (currentDateTime.day != initialDateTime.day)
21  timeToReset = 1;
22  break;
23  // test if the current week is different
24  case WEEK:
25  if (currentDateTime.dayOfWeek == 1 && initialDateTime.dayOfWeek == 7)
26  timeToReset = 1;
27  break;
28  // test if the current month is different
29  case MONTH:
30  if (currentDateTime.month != initialDateTime.month)
31  timeToReset = 1;
32  break;
33  }
34  // if it's time to reset the counter, do so
35  if (timeToReset) {
37  count = 0;
38  }
39  // if there's a pulse, increment the counter
40  if (pulseCounter->isActive())
41  count++;
42 }

References count, DAY, DateTime::getDateTime(), DateTime::getInstance(), initialDateTime, PulseCounter::isActive(), MONTH, pulseCounter, type, and WEEK.

Referenced by LeaksController::update().

Member Data Documentation

◆ count

int Consumption::count
private

number of pulses detected within the monitoring period

Definition at line 29 of file Consumption.h.

Referenced by Consumption(), getConsumptionCount(), and update().

◆ initialDateTime

RTCDateTime Consumption::initialDateTime
private

instance of RTCDateTime (real-time module)

Definition at line 28 of file Consumption.h.

Referenced by Consumption(), and update().

◆ pulseCounter

PulseCounter* Consumption::pulseCounter
private

instance of PulseCounter (input [l])

Definition at line 27 of file Consumption.h.

Referenced by Consumption(), and update().

◆ type

Type Consumption::type
private

type of the monitoring period

Definition at line 30 of file Consumption.h.

Referenced by Consumption(), and update().


The documentation for this class was generated from the following files:
Consumption::pulseCounter
PulseCounter * pulseCounter
instance of PulseCounter (input [l])
Definition: Consumption.h:27
Consumption::MONTH
@ MONTH
monthly water consumption
Definition: Consumption.h:22
Consumption::type
Type type
type of the monitoring period
Definition: Consumption.h:30
Consumption::initialDateTime
RTCDateTime initialDateTime
instance of RTCDateTime (real-time module)
Definition: Consumption.h:28
DateTime::getInstance
static DateTime * getInstance()
Returns the instance of the class.
Definition: DateTime.cpp:26
PulseCounter::isActive
int isActive() const
Returns information if a pulse has been detected.
Definition: PulseCounter.cpp:40
DateTime::getDateTime
RTCDateTime getDateTime() const
Returns the current datatime.
Definition: DateTime.cpp:51
Consumption::WEEK
@ WEEK
weekly water consumption
Definition: Consumption.h:21
Consumption::count
int count
number of pulses detected within the monitoring period
Definition: Consumption.h:29
Consumption::DAY
@ DAY
daily water consumption
Definition: Consumption.h:20