60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#include "inputlogcsv.hh"
|
|
#include "posexcept.hh"
|
|
#include "mobile.hh"
|
|
#include "calibrationrequest.hh"
|
|
#include "referencepoint.hh"
|
|
|
|
#include <sstream>
|
|
|
|
using namespace std ;
|
|
using std::tr1::unordered_map ;
|
|
|
|
|
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
const string InputLogCSV::request_to_csv(const Request &request) const
|
|
{
|
|
ostringstream csv_line ;
|
|
if (request.get_mobile() != NULL)
|
|
csv_line << request.get_mobile()->get_mac_addr() ;
|
|
csv_line
|
|
<< ';' << static_cast<uint_fast16_t>(request.get_type())
|
|
<< ';' << request.get_time_sent()
|
|
<< ';' ;
|
|
|
|
const CalibrationRequest *calibration_request =
|
|
dynamic_cast<const CalibrationRequest*>(&request) ;
|
|
if (calibration_request == NULL)
|
|
csv_line << "0;0;0;0" ;
|
|
else
|
|
{
|
|
csv_line
|
|
<< calibration_request->get_reference_point()->get_x() << ';'
|
|
<< calibration_request->get_reference_point()->get_y() << ';'
|
|
<< calibration_request->get_reference_point()->get_z() << ';'
|
|
<< static_cast<int>(calibration_request->get_direction()) ;
|
|
}
|
|
|
|
const unordered_map<string, Measurement> &measurements =
|
|
request.get_measurements() ;
|
|
for (unordered_map<string, Measurement>::const_iterator i
|
|
= measurements.begin() ; i != measurements.end() ; ++i)
|
|
{
|
|
const vector<ss_t> &ss_list = i->second.get_ss_list() ;
|
|
const string &ap_mac = i->second.get_ap() != NULL
|
|
? i->second.get_ap()->get_mac_addr()
|
|
: "" ;
|
|
for (vector<ss_t>::const_iterator i = ss_list.begin() ;
|
|
i != ss_list.end() ; ++i)
|
|
{
|
|
csv_line << ';' << ap_mac ;
|
|
csv_line << ';' << *i ;
|
|
}
|
|
}
|
|
|
|
csv_line << '\n' ;
|
|
return csv_line.str() ;
|
|
}
|