HomeWaterLeaksDetection
DailyOverview.cpp
Go to the documentation of this file.
1 #include "DailyOverview.h"
2 
6  Consumption *dailyConsumption,
7  Consumption *monthlyConsumption) {
8 
9  // store all the params given through the constructor
10  this->highLeakDetection = highLeakDetection; // high algorithm
11  this->lowLeakDetection = lowLeakDetection; // low algorithm
12  this->totalLeakDetection = totalLeakDetection; // total algorithm
13 
14  this->dailyConsumption = dailyConsumption;
15  this->monthlyConsumption = monthlyConsumption;
16 
17  // store the initial date time
19 
20  // set the hour and minute (e.g 10:30) when the daily
21  // overview should be sent to the user
24 
25  // reset the monitoring period
26  reset();
27 }
28 
33 }
34 
36  // get the current date time
37  RTCDateTime currentDateTime = DateTime::getInstance()->getDateTime();
38 
39  // TODO: add the minutes to the condition as well
40  // so it doesn't depend only on the hour
41  if (initialDateTime.day != currentDateTime.day) {
42  #ifdef EMAIL_NOTIFICATION
43  String data = "";
44  data += "Daily water consumption: " + String(PULSE_TO_LITER(dailyConsumption->getConsumptionCount())) + "l\r\n";
45  data += "Monthly water consumption: " + String(PULSE_TO_LITER(monthlyConsumption->getConsumptionCount())) + "l\r\n";
46  data += "max high leak detected: " + String(maxHighLeakPercentage) + "%\r\n";
47  data += "max low leak detected: " + String(maxLowLeakPercentage) + "%\r\n";
48  data += "max total leak detected: " + String(maxTotalLeakPercentage) + "%\r\n";
51  "Daily overview",
52  data);
53  #endif
54 
55  // start a new monitoring period
56  initialDateTime = currentDateTime;
57  reset();
58  }
59 
60  // update the maximum values (% detected) of all three
61  // water leak detection algorithms
65 }
66 
67 #ifdef LCD_DISPLAY
68  const String DailyOverview::getRow(int row) const {
69  switch(row) {
70  case 0:
71  // 1st row on the LCD
72  return String("Overview (2)");
73  case 1:
74  // 2nd row on the LCD
75  return String("DAY CONS.=") + String(PULSE_TO_LITER(dailyConsumption->getConsumptionCount())) + "l";
76  break;
77  case 2:
78  // 3rd row on the LCD
79  return String("MON CONS.=") + String(PULSE_TO_LITER(monthlyConsumption->getConsumptionCount())) + "l";
80  break;
81  case 3:
82  // 4th row on the LCD
83  return "";
84  break;
85  }
86  return "UNTITLED"; // for any other row return "UNTITLED"
87  }
88 #endif
lowLeakDetection
LowLeakDetection * lowLeakDetection
Definition: main.cpp:52
highLeakDetection
HighLeakDetection * highLeakDetection
Definition: main.cpp:51
TotalLeakDetection
Definition: TotalLeakDetection.h:15
DAILY_OVERVIEW_INIT_HOUR
#define DAILY_OVERVIEW_INIT_HOUR
hour when the daily overview email will be sent off
Definition: Setup.h:22
HighLeakDetection
Definition: HighLeakDetection.h:23
Consumption::getConsumptionCount
int getConsumptionCount() const
Returns the current number of pulses detected so far within the monitoring period.
Definition: Consumption.cpp:44
DailyOverview::maxLowLeakPercentage
float maxLowLeakPercentage
max [%] low-water leak detection within the monitoring period (extreme)
Definition: DailyOverview.h:39
DailyOverview::reset
void reset()
Resets all the variables at the end of the day.
Definition: DailyOverview.cpp:29
DailyOverview::totalLeakDetection
TotalLeakDetection * totalLeakDetection
instance of a total-water leak detection algorithm
Definition: DailyOverview.h:32
DailyOverview::dailyConsumption
Consumption * dailyConsumption
instance of Consumption (daily water consumption)
Definition: DailyOverview.h:34
DateTime::getInstance
static DateTime * getInstance()
Returns the instance of the class.
Definition: DateTime.cpp:26
totalLeakDetection
TotalLeakDetection * totalLeakDetection
Definition: main.cpp:53
DailyOverview::lowLeakDetection
LowLeakDetection * lowLeakDetection
instance of a low-water leak detection algorithm
Definition: DailyOverview.h:31
Consumption
Definition: Consumption.h:13
DailyOverview::monthlyConsumption
Consumption * monthlyConsumption
instance of Consumption (monthly water consumption)
Definition: DailyOverview.h:35
PULSE_TO_LITER
#define PULSE_TO_LITER(p)
Converts pulses to liters.
Definition: LimitsDefinition.h:17
LowLeakDetection::getPercentLeakDetected
float getPercentLeakDetected() const
Returns percentage information about how close the algorithm is from being reset.
Definition: LowLeakDetection.cpp:174
EmailSender::sendEmail
byte sendEmail(String subject, String data)
Sends an e-mail off to the smtp2go server.
Definition: EmailSender.cpp:93
DailyOverview::update
void update() override
Updates the class.
Definition: DailyOverview.cpp:35
DateTime::getDateTime
RTCDateTime getDateTime() const
Returns the current datatime.
Definition: DateTime.cpp:51
DailyOverview::initialDateTime
RTCDateTime initialDateTime
instance of RTCDateTime (real-time module)
Definition: DailyOverview.h:36
DailyOverview.h
DailyOverview::maxHighLeakPercentage
float maxHighLeakPercentage
max [%] high-water leak detection within the monitoring period (extreme)
Definition: DailyOverview.h:38
DailyOverview::maxTotalLeakPercentage
float maxTotalLeakPercentage
max [%] total-water leak detection within the monitoring period (extreme)
Definition: DailyOverview.h:40
DailyOverview::DailyOverview
DailyOverview(HighLeakDetection *highLeakDetection, LowLeakDetection *lowLeakDetection, TotalLeakDetection *totalLeakDetection, Consumption *dailyConsumption, Consumption *monthlyConsumption)
Constructor of the class.
Definition: DailyOverview.cpp:3
DAILY_OVERVIEW_INIT_MIN
#define DAILY_OVERVIEW_INIT_MIN
minute when the daily overview email will be sent off
Definition: Setup.h:23
HighLeakDetection::getPercentLeakDetected
float getPercentLeakDetected() const
Returns percentage information about how close the algorithm is from being reset.
Definition: HighLeakDetection.cpp:142
EmailSender::DAILY_OVERVIEW
@ DAILY_OVERVIEW
daily overview about the system
Definition: EmailSender.h:46
DailyOverview::highLeakDetection
HighLeakDetection * highLeakDetection
instance of a high-water leak detection algorithm
Definition: DailyOverview.h:30
LowLeakDetection
Definition: LowLeakDetection.h:21
DailyOverview::getRow
const String getRow(int row) const override
Returns the content of the row given as a parameter.
EmailSender::getInstance
static EmailSender * getInstance()
Returns the instance of the class.
Definition: EmailSender.cpp:87