4 #include <spdlog/spdlog.h>
19 return this->label.c_str();
23 spdlog::debug(
"measurement - ID: {0}", this->
id);
26 spdlog::debug(
"measurement - measuree_id: {0}", this->
measuree_id);
27 spdlog::debug(
"measurement - measurer_id: {0}", this->
measurer_id);
28 spdlog::debug(
"measurement - measuring_length: {0}", this->
measuring_length);
31 spdlog::debug(
"measurement - measuring start: {0}", buf);
33 strftime(buf, 64,
"%Y-%m-%d %H:%M:%S", &(this->
measuring_end));
34 spdlog::debug(
"measurement - measuring end: {0}", buf);
35 spdlog::debug(
"measurement - description: {0}", this->
description.c_str());
36 spdlog::debug(
"measurement - value_length: {0}", this->
value_length);
37 spdlog::debug(
"measurement - value_count: {0}", this->
value_count);
38 spdlog::debug(
"measurement - raw_values size: {0}", this->
values.size());
39 spdlog::debug(
"measurement - x_val_med: {0}", this->
x_val_med);
40 spdlog::debug(
"measurement - x_val_avg: {0}", this->
x_val_avg);
41 spdlog::debug(
"measurement - all_val_med: {0}", this->
all_val_med);
42 spdlog::debug(
"measurement - all_val_avg: {0}", this->
all_val_avg);
44 strftime(buf, 64,
"%Y-%m-%d %H:%M:%S", &(this->
created_at));
45 spdlog::debug(
"measurement - created at: {0}", buf);
50 HX711::Mass x_med(
x_val_med, HX711::Mass::Unit::G);
51 HX711::Mass x_avg(
x_val_avg, HX711::Mass::Unit::G);
52 HX711::Mass all_med(
all_val_med, HX711::Mass::Unit::G);
53 HX711::Mass all_avg(
all_val_avg, HX711::Mass::Unit::G);
76 strftime(buf, 64,
"%Y-%m-%d %H:%M:%S", &(this->
measuring_end));
78 this->
end_str = std::string(buf);
86 sprintf(buf,
"%ld ms", std::chrono::duration_cast<std::chrono::milliseconds>
101 spdlog::debug(
"Comparing:");
103 spdlog::debug(
"to:");
105 spdlog::info(
"Comparing start");
132 spdlog::debug(
"values.size() diff: {0} - {1}", this->
values.size(), m->
values.size());
136 for (
size_t i = 0; i < len; i++) {
138 spdlog::error(
"values (binary) start to differ at index {0}", i);
143 spdlog::info(
"Comparing end");
159 std::tm *start_tm, std::tm *end_tm,
unsigned long m_length)
161 spdlog::debug(
"user_workspace.cpp - Initing basic measuring parameters");
192 if (ms.size() <= 0)
return;
200 unsigned long total_length = 0;
201 double xm_sum = 0.0, xa_sum = 0.0, am_sum = 0.0, aa_sum = 0.0;
203 for (
size_t i = 0; i < ms.size(); i++) {
205 total_length += ms[i].measuring_length / 1000000;
206 xm_sum += ms[i].x_val_med;
207 xa_sum += ms[i].x_val_avg;
208 am_sum += ms[i].all_val_med;
209 aa_sum += ms[i].all_val_avg;
221 size_t it = 0, inc = 0;
222 std::vector<double> vect = m->
values;
223 std::vector<double> meds;
224 std::vector<double> avgs;
226 while (it < vect.size()) {
230 inc = vect.size() - it;
232 auto it_start = vect.begin() + it;
233 auto it_end = vect.begin() + it + inc;
235 std::vector<double> tmp(it_start, it_end);
237 meds.push_back(HX711::Utility::median(&tmp));
238 avgs.push_back(HX711::Utility::average(&tmp));
243 return std::pair<double, double>(HX711::Utility::median(&meds), HX711::Utility::average(&avgs));
247 std::vector<double> vect = m->
values;
248 return std::pair<double, double>(HX711::Utility::median(&vect), HX711::Utility::average(&vect));
257 std::string name, std::string lastname, std::string description, uint8_t role, std::tm reg_date,
258 std::tm last_login_date, std::tm created_at_date, std::tm date_of_birth)
275 spdlog::debug(
"user_cont - User ID: {0}", this->
id);
276 spdlog::debug(
"user_cont - User RFID: {0:x} {1:x} {2:x} {3:x} {4:x} {5:x} {6:x} {7:x} {8:x} {9:x}",
280 spdlog::debug(
"user_cont - User rfid_ser_len: {0}", this->
rfid_ser_len);
281 spdlog::debug(
"user_cont - User username: {0}", this->
username);
282 spdlog::debug(
"user_cont - User name: {0}", this->
name);
283 spdlog::debug(
"user_cont - User lastname: {0}", this->
lastname);
284 spdlog::debug(
"user_cont - User description: {0}", this->
description);
285 spdlog::debug(
"user_cont - User role: {0}", this->
role);
288 strftime(buf, 64,
"%Y-%m-%d %H:%M:%S", &(this->
reg_date));
289 spdlog::debug(
"user_cont - User reg_date: {0}", buf);
292 spdlog::debug(
"user_cont - User last_login_date: {0}", buf);
295 spdlog::debug(
"user_cont - User created_at_date: {0}", buf);
297 strftime(buf, 64,
"%Y-%m-%d %H:%M:%S", &(this->
date_of_birth));
298 spdlog::debug(
"user_cont - User date_of_birth: {0}", buf);
307 this->user.reset(user);
317 return this->
picked.get();
325 if (this->user->rfid_serial_bin[i] != tag->
serial[i])
334 return this->user.get() !=
nullptr;
338 return this->
subuser.get() !=
nullptr;
342 return std::pair<uint8_t*, uint8_t>(this->user->rfid_serial_bin, this->user->rfid_ser_len);
346 return this->user->id;
350 return this->user.get();
354 return this->user->username;
358 return this->user->name;
362 return this->user->lastname;
365 return this->user->description;
369 return this->user->role;
373 switch (this->user->role) {
387 if (this->
subuser.get() !=
nullptr) {
388 return this->
subuser->measur_headers;
390 return this->user->measur_headers;
395 if (this->
subuser.get() !=
nullptr) {
398 return this->user.get();
403 if (this->
subuser.get() !=
nullptr) {
406 return this->user->id;
411 if (this->
subuser.get() !=
nullptr) {
412 return this->
subuser->username;
414 return this->user->username;
419 spdlog::debug(
"user_workspace.cpp - Initing basic measuring parameters");
Container for measurement data and (convenience) variables, that are used to show measurement in GUI.
unsigned long measuring_length
static std::pair< double, double > calc_every_x_values_stats(measurement *m)
Calculates the median of medians and avarages of avarages of every X values (X is a defined constant ...
std::string all_val_avg_str
int compare(measurement *m)
std::vector< double > values
static void prepare_continuous_to_picked(std::vector< measurement > &ms, measurement *picked)
unsigned long value_count
HX711::Mass::Unit current_unit
void log_measurement_to_debug()
void init_convinience_vars(const char *measurer_uname, const char *measuree_uname)
std::string all_val_med_str
void init_start_end_strings()
static void init_simple_measuring(measurement *m, std::vector< double > &values)
std::string x_val_med_str
unsigned long measuree_id
static std::pair< double, double > calc_all_values_stats(measurement *m)
Calculates the median and avarage of all values.
unsigned long measurer_id
static void init_measuring(measurement *m, user_workspace *uspace, std::vector< double > &values, std::tm *start_tm, std::tm *end_tm, unsigned long m_length)
static void calc_measuring_results(measurement *m)
std::string x_val_avg_str
std::string measurer_uname
void init_value_strings()
std::string measuree_uname
unsigned long measurement_number
Class used as a container for user data, that are selected from database. (and also for insert,...
user_cont(unsigned long, uint8_t *, uint8_t, std::string, std::string, std::string, std::string, uint8_t, std::tm, std::tm, std::tm, std::tm)
Construct a new user cont object through value parameters, but this isn't used. Originally inteded fo...
unsigned long measure_count
uint8_t rfid_serial_bin[10]
Container that servers for storing users data and manipulating them.
unsigned long get_user_id()
void init_measured(std::vector< double > values, std::tm *start_tm, std::tm *end_tm, unsigned long m_length)
std::string & get_username()
std::string & get_lastname()
int compare_rfid_serials(rfid_reader::rfid_tag *tag)
std::unique_ptr< user_cont > subuser
unsigned long get_measured_id()
std::unique_ptr< measurement > measured
std::string & get_description()
measurement * get_last_hx_measuring()
std::vector< std::unique_ptr< measurement_header > > & get_user_measur_headers()
std::string & get_measured_username()
std::unique_ptr< measurement > picked
user_cont * get_measured_user()
const char * get_role_string()
measurement * get_picked_hx_measuring()
std::pair< uint8_t *, uint8_t > get_rfid_serial()
user_workspace(user_cont *user)
Construct a new user workspace object. This can only be done with a user that is logged in.
const char * get_localized_text(const char *key)
Get the localized text object.
RFID tag structure. Stores data read from SPI.