Commit 09b31aae authored by fmg005's avatar fmg005

Added a format_duration method

parent c6cfebd2
......@@ -6,9 +6,11 @@ CLA::LOGGER::LOGGER(const string& name): m_patient_name(move(name)){
m_logstream[0].open(prosim_logs_dir+"prosim_"+m_patient_name+current_time(false)+".log");
m_logstream[1].open(prosim_results_dir+"duration_"+m_patient_name+current_time(false)+".txt");
m_logstream[2].open(prosim_results_dir+"data_"+m_patient_name+current_time(false)+".txt");
m_logstream[0]<< "Date"<<setw(12)<<"Time"<<setw(12)<<"Tz"<<setw(3)<<" "<<"Level"<<setw(9)<<"Message"<<endl;
m_logstream[1]<<"start time,"<<"end time,"<<"duration(s),"<<"next_update time"<<endl;
m_logstream[2]<<"Time,"<<"Sytolic,"<<"Diatolic,"<<"MAP,"<<"infusion_rate"<<endl;
m_logstream[0]<< "Date"<<setw(12)<<"Time"<<setw(12)<<"Tz"<<setw(3)<<" "\
<<"Level"<<setw(9)<<"Message"<<endl;
m_logstream[1]<<"start time,"<<"engine adv duration(s),"<<"command duration(s),"\
<<"infusion duration(s),"<<"totals duration(s),"<<"next_update time"<<endl;
m_logstream[2]<<"Time,"<<"Systolic,"<<"Diastolic,"<<"MAP,"<<"Pump rate"<<endl;
/* mapping strings to levels */
logging_levels["DEBUG"] = CLA::LOGGER::DEBUG;
logging_levels["INFO"] = CLA::LOGGER::INFO;
......@@ -23,9 +25,11 @@ m_patient_name(move(name)) {
m_logstream[0].open(prosim_logs_dir+m_filename+".log", ios::out|ios::binary);
m_logstream[1].open(prosim_results_dir+"duration_"+m_filename+".txt", ios::out|ios::binary);
m_logstream[2].open(prosim_results_dir+"data_"+m_filename+".txt", ios::out|ios::binary);
m_logstream[0] << "Date"<<setw(12)<<"Time"<<setw(12)<<"Tz"<<setw(3)<<" "<<"Level"<<setw(9)<<"Message"<<endl;
m_logstream[1] <<"start time,"<<"end time,"<<"duration(s),"<<"next_update time"<<endl;
m_logstream[2]<<"Time,"<<"Sytolic,"<<"Diatolic,"<<"MAP,"<<"infusion_rate"<<endl;
m_logstream[0] << "Date"<<setw(12)<<"Time"<<setw(12)<<"Tz"<<setw(3)<<" "\
<<"Level"<<setw(9)<<"Message"<<endl;
m_logstream[1]<<"start time,"<<"engine adv duration(s),"<<"command duration(s),"\
<<"infusion duration(s),"<<"totals duration(s),"<<"next_update time"<<endl;
m_logstream[2]<<"Time,"<<"Systolic,"<<"Diastolic,"<<"MAP,"<<"Pump rate"<<endl;
/* mapping strings to levels */
logging_levels["DEBUG"] = CLA::LOGGER::DEBUG;
logging_levels["INFO"] = CLA::LOGGER::INFO;
......@@ -57,6 +61,12 @@ string CLA::LOGGER::current_time(bool display_timezone) {
return buffer;
}
string CLA::LOGGER::format_duration(time_t t) {
char buff[10];
sprintf(buff, "%.3f", static_cast<float>(t)/1000);
return buff;
}
string CLA::LOGGER::format_chrono_time(time_t t) {
char buff[20];
strftime(buff, 20, "%X", localtime(&t));
......@@ -66,7 +76,7 @@ string CLA::LOGGER::format_chrono_time(time_t t) {
string CLA::LOGGER::format_chrono_time(system_clock::time_point t) {
char buff[20];
auto in_time = system_clock::to_time_t(t);
strftime(buff, 20, "%X.", localtime(&in_time));
strftime(buff, 20, "%X", localtime(&in_time));
return buff;
}
......@@ -82,21 +92,26 @@ string CLA::LOGGER::format_chrono_time_ms(system_clock::time_point t) {
return buff;
}
void CLA::LOGGER::log_duration(system_clock::time_point start_time, system_clock::time_point
end_time, time_t duration_time, time_t next_update_time) {
void CLA::LOGGER::log_duration(system_clock::time_point start_time, time_t engine_duration,
time_t command_duration, time_t infusion_duration,time_t total_duration, time_t \
next_update_time) {
ss<< format_chrono_time(start_time);
ss<< ",";
ss<< format_chrono_time(end_time);
ss<< format_duration(engine_duration);
ss<< ",";
ss<< format_duration(command_duration);
ss<< ",";
ss<<format_duration(infusion_duration);
ss<< ",";
ss<< static_cast<float>(duration_time)/1000;
ss<<format_duration(total_duration);
ss<< ",";
ss<<format_chrono_time(next_update_time);
m_logstream[1] << ss.str() << endl;
ss.str("");
}
void CLA::LOGGER::log_data(system_clock::time_point _time, double systolic, double diastolic,
double MAP, double rate) {
void CLA::LOGGER::log_data(system_clock::time_point _time, double systolic, \
double diastolic, double MAP, double rate) {
ss<< format_chrono_time(_time);
ss<< ",";
ss<< systolic;
......
......@@ -25,7 +25,7 @@ namespace CLA {
string level_name;
const string m_filename;
const string m_patient_name;
ofstream m_logstream[2];
ofstream m_logstream[3];
ostringstream ss;
bool m_verbosity = true;
enum LEVEL {DEBUG, INFO, WARN, ERROR, FATAL, NONE};
......@@ -35,16 +35,17 @@ namespace CLA {
string format_chrono_time(system_clock::time_point);
string format_chrono_time_ms(system_clock::time_point);
string convert_level_to_string(LEVEL);
string format_duration(time_t);
map<std::string, LEVEL> logging_levels;
public:
LOGGER(const string&);
LOGGER(const string&, const string&);
void log_duration(system_clock::time_point, system_clock::time_point, time_t, time_t);
~LOGGER();
void log_duration(system_clock::time_point, time_t, time_t, time_t, \
time_t, time_t);
void log_data(system_clock::time_point, double, double, double, double);
~LOGGER();
void setLevel(const string&);
void setVerbosity(bool);
template <typename T>
void debug(const T& t) {
if (LOGGER::DEBUG >= DEFAULT_LEVEL) {
......@@ -79,7 +80,7 @@ namespace CLA {
ss.str("");
}
}
template <typename T>
void warn(const T& t) {
if (LOGGER::WARN >= DEFAULT_LEVEL) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment