Medial Code Documentation
Loading...
Searching...
No Matches
CommonTestingTools.h
1#ifndef __COMMONTESTINGTOOLS_H
2#define __COMMONTESTINGTOOLS_H
3
4#include <AlgoMarker/AlgoMarker/AlgoMarker.h>
5#include <AlgoMarker/DynAMWrapper/DynAMWrapper.h>
6#include <AlgoMarker/CommonTestingTools/CommonTestingTools.h>
9#include <MedProcessTools/MedProcessTools/MedSamples.h>
10#include <MedIO/MedIO/MedIO.h>
11#include <json/json.hpp>
12
13#include <boost/property_tree/ptree.hpp>
14#include <boost/property_tree/json_parser.hpp>
15#include <boost/algorithm/string/predicate.hpp>
16#include <boost/algorithm/string.hpp>
17#include <algorithm>
18#include <string>
19#include <vector>
20#include "DataLoader.h"
21
22
23#ifdef __linux__
24#include <wordexp.h>
25#elif _WIN32
26#include "windows.h"
27#endif
28
29namespace CommonTestingTools {
30
31 class DataLoader;
32
33 const map<int, int> code_to_status_tbl = {
34 { 300, 2 },
35 { 301, 2 },
36 { 310, 2 },
37 { 311, 2 },
38 { 320, 1 },
39 { 321, 2 },
40 { 390, 0 },
41 { 391, 1 },
42 { 392, 2 }
43 };
44
45 const map<string, string> units_tbl = {
46 { "BMI" , "kg/m^2" },
47 { "Glucose" , "mg/dL" },
48 { "HbA1C" , "%" },
49 { "HDL" , "mg/dL" },
50 { "Triglycerides" , "mg/dL" },
51 { "ALT" , "U/L" },
52 { "RBC" , "10^6/uL" },
53 { "Na" , "mmol/L" },
54 { "Weight" , "Kg" },
55 { "WBC" , "10^3/uL" },
56 { "Basophils#" , "#" },
57 { "Basophils%" , "%" },
58 { "Eosinophils#" , "#" },
59 { "Eosinophils%" , "%" },
60 { "Hematocrit" , "%" },
61 { "Hemoglobin" , "g/dL" },
62 { "Lymphocytes#" , "#" },
63 { "Lymphocytes%" , "%" },
64 { "MCH" , "pg/cell" },
65 { "MCHC-M" , "g/dL" },
66 { "MCV" , "fL" },
67 { "Monocytes#" , "#" },
68 { "Monocytes%" , "%" },
69 { "MPV" , "mic*3" },
70 { "Neutrophils#" , "#" },
71 { "Neutrophils%" , "%" },
72 { "Platelets" , "10^3/uL" },
73 { "RDW" , "%" },
74 { "MSG" , "#" }
75 };
76
77
78 using namespace std;
79
80 string precision_float_to_string(float val);
81 json read_json_array_next_chunk(ifstream& infile, bool& in_array);
82
83 //Expand string with embedded Environment variables in it
84 string expandEnvVars(const string &str);
85
86 // convert a C++ vector of strings to a char**
87 class charpp_adaptor : public vector<string> {
88 protected:
89 char** charpp_arr;
90 char* charpp_buf;
91 public:
92 void init() {
93 charpp_arr = (char**)malloc(1);
94 charpp_buf = (char*)malloc(1);
95 }
97 free(charpp_arr);
98 free(charpp_buf);
99 };
100 charpp_adaptor() : vector<string>() { init(); };
101 charpp_adaptor(int capacity) : vector<string>(capacity) { init(); };
102 charpp_adaptor(const charpp_adaptor& other) : vector<string>(other) { init(); };
103
104 char** get_charpp();
105 };
106
107 // get a malloc'ed read-write copy of a vector's .data() pointer
108 template<typename T>
110 protected:
111 T * data_p;
112 size_t data_p_size;
113 int n_elem;
114 public:
116 free(data_p);
117 };
118
119 T* from_vec(const vector<T>& orig) {
120 n_elem = (int)orig.size();
121 data_p_size = n_elem * sizeof(T);
122 if (data_p_size == 0)
123 return nullptr;
124 data_p = (T*)realloc(data_p, data_p_size);
125 memcpy(data_p, orig.data(), data_p_size);
126 return data_p;
127 };
128
129 get_volatile_data_adaptor(const vector<T>& orig) : n_elem(0), data_p_size(0) { data_p = (T*)malloc(1); from_vec(orig); }
130
131 T* get_volatile_data() {
132 if (data_p_size == 0)
133 return nullptr;
134 return data_p;
135 }
136 };
137
138 json json_AddData(const char *signalName, int TimeStamps_len, long long* TimeStamps, int Values_len, float* Values, int n_time_channels, int n_val_channels);
139 json json_AddDataStr(const char *signalName, int TimeStamps_len, long long* TimeStamps, int Values_len, char** Values, int n_time_channels, int n_val_channels);
140
141 int get_preds_from_algomarker(AlgoMarker *am, vector<MedSample> &res, bool print_msgs, DataLoader& d, bool force_add_data, ofstream& msgs_stream, vector<string> ignore_sig, bool extended_score=false);
142 int get_preds_from_algomarker_single(AlgoMarker *am, vector<MedSample> &res, bool print_msgs, DataLoader& d, bool force_add_data, ofstream& msgs_stream, vector<string> ignore_sig, ofstream& json_reqfile_stream, bool extended_score=false);
143 void save_sample_vec(vector<MedSample> sample_vec, const string& fname);
144}
145
146#endif // __COMMONTESTINGTOOLS_H
Logger.h - allowing logs with more control.
Definition AlgoMarker.h:272
Definition DataLoader.h:24
Definition CommonTestingTools.h:87
Definition CommonTestingTools.h:109
Definition StdDeque.h:58