DAQ  1.0.0
Data Acquisition System (basic demo)
dataaccess.h
Go to the documentation of this file.
1 /*! @brief This file have the interface for DataAccess class.
2  @file dataaccess.h
3  @author Alvaro Denis <denisacostaq@gmail.com>
4  @date 6/22/2019
5 
6  @copyright
7  @attention <h1><center><strong>COPYRIGHT &copy; 2019 </strong>
8  [<strong>denisacostaq</strong>][denisacostaq-URL].
9  All rights reserved.</center></h1>
10  @attention This file is part of [<strong>DAQs</strong>][DAQs-URL].
11 
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions
14  are met:
15  - 1. Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  - 2. Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  - 3. Neither the name of the University nor the names of its contributors
21  may be used to endorse or promote products derived from this software
22  without specific prior written permission.
23 
24  THIS PRODUCT IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33  THIS PRODUCT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35  [denisacostaq-URL]: https://about.me/denisacostaq "Alvaro Denis Acosta"
36  [DAQs-URL]: https://github.com/denisacostaq/DAQs "DAQs"
37  */
38 #ifndef DATABASESERVER_DATAACCESS_H
39 #define DATABASESERVER_DATAACCESS_H
40 
41 #include "src/database-server/data-access/idataaccess.h"
42 #include "src/database-server/data-source/idatasource.h"
43 
44 class DataAccess : public IDataAccess {
45  public:
46  explicit DataAccess(IDataSource* ds) noexcept;
47 
48  /**
49  * @brief add_variable add a new variable.
50  * @param var variable info.
51  * @return Ok on success.
52  * @sa IDataAccess::add_variable
53  */
55 
56  /**
57  * @brief add_variable_value add a new value for a given variable.
58  * @param var variable value.
59  * @return Ok on success.
60  * @sa IDataAccess::add_variable_value
61  */
63 
64  /**
65  * @brief fetch_variables get all variables.
66  * @return a vector with the variables.
67  * @sa IDataSource::add_variable
68  */
70 
71  /**
72  * @brief fetch_variable_values get values for a given variable.
73  * @param var_name variable name.
74  * @param max_len TODO(denisacostaq@gmail.com): not implemented yet
75  * @return a vector of values if any and an error code.
76  * @sa IDataAccess::fetch_variable_values
77  */
80 
81  /**
82  * @brief fetch_variable_values get values for a given variable in a period.
83  * @param var variable value.
84  * @param start_date start date.
85  * @param end_date end date
86  * @param max_len TODO(denisacostaq@gmail.com): not implemented yet
87  * @return a vector of values if any and an error code.
88  * @sa IDataAccess::fetch_variable_values
89  */
91  const std::string& var_name,
95 
96  /**
97  * @brief compress a dumy compression algorithm
98  * @param in_vals input values.
99  * @param out_vals output(compressed) values.
100  * @param max_len len of the compressed values.
101  * @return Err::Ok on success.
102  */
103  Err compress(const std::vector<VarValue>& in_vals,
104  std::vector<VarValue>* out_vals, size_t max_len) noexcept;
105 
106  private:
108 };
109 #endif // DATABASESERVER_DATAACCESS_H
VarValue(Variable &&variable, double &&val, std::uint64_t &&ts)
Definition: varvalue.cc:45
Err compress(const std::vector< VarValue > &in_vals, std::vector< VarValue > *out_vals, size_t max_len) noexcept
compress a dumy compression algorithm
Definition: dataaccess.cc:54
Definition: variable.h:44
virtual std::tuple< std::vector< VarValue >, Err > fetch_variable_values(const std::string &var_name, const std::chrono::system_clock::time_point &start_date, const std::chrono::system_clock::time_point &end_date, size_t max_len=std::numeric_limits< size_t >::infinity()) noexcept=0
fetch_variable_values get values for a variable in a date range.
Err add_variable(const Variable &var) noexceptoverride
add_variable add a new variable.
Definition: dataaccess.cc:45
Err add_variable_value(const VarValue &var) noexceptoverride
add_variable_value add a new value for a given variable.
Definition: dataaccess.cc:49
IDataSource * ds_
Definition: dataaccess.h:107
virtual Err count_variable_values(const std::string &var_name, const std::chrono::system_clock::time_point &start_date, const std::chrono::system_clock::time_point &end_date, const std::function< void(size_t count)> &send_count) noexcept=0
count_variable_values count all values of a given variable
DataAccess(IDataSource *ds) noexcept
Definition: dataaccess.cc:43
Err
Definition: idataaccess.h:57
std::tuple< std::vector< VarValue >, Err > fetch_variable_values(const std::string &var_name, const std::chrono::system_clock::time_point &start_date, const std::chrono::system_clock::time_point &end_date, size_t max_len) noexceptoverride
fetch_variable_values get values for a given variable in a period.
Definition: dataaccess.cc:132