[Positioner] Add Request::to_csv()
Code moved from InputLogCSV.
This commit is contained in:
parent
5d94fe8cc4
commit
3808c2ce6f
|
@ -4,53 +4,4 @@
|
|||
* (Université de Franche-Comté), France.
|
||||
*/
|
||||
|
||||
|
||||
#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_nb_packets()
|
||||
<< ';' << 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)
|
||||
csv_line << i->second.to_csv() ;
|
||||
|
||||
csv_line << '\n' ;
|
||||
return csv_line.str() ;
|
||||
}
|
||||
// Place holder for potential additional code for InputLogCSV.
|
||||
|
|
|
@ -20,8 +20,6 @@ class InputLogCSV: public InputLogMedium
|
|||
protected:
|
||||
TextFileWriter file ;
|
||||
|
||||
const std::string request_to_csv(const Request &request) const ;
|
||||
|
||||
public:
|
||||
InputLogCSV(const std::string &filename):
|
||||
file(filename) {}
|
||||
|
@ -39,7 +37,7 @@ public:
|
|||
|
||||
inline bool InputLogCSV::log_request(const Request &request)
|
||||
{
|
||||
return file.write_text(request_to_csv(request)) ;
|
||||
return file.write_text(request.to_csv() + '\n') ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
|
||||
#include "request.hh"
|
||||
#include "calibrationrequest.hh"
|
||||
#include "referencepoint.hh"
|
||||
#include "mobile.hh"
|
||||
|
||||
using namespace std ;
|
||||
|
@ -197,6 +199,41 @@ bool Request::operator==(const Request &source) const
|
|||
|
||||
|
||||
|
||||
const string Request::to_csv() const
|
||||
{
|
||||
ostringstream csv_line ;
|
||||
|
||||
if (mobile != NULL)
|
||||
csv_line << mobile->get_mac_addr() ;
|
||||
|
||||
csv_line
|
||||
<< ';' << static_cast<uint_fast16_t>(type)
|
||||
<< ';' << nb_packets
|
||||
<< ';' << time_sent
|
||||
<< ';' ;
|
||||
|
||||
const CalibrationRequest *calibration_request =
|
||||
dynamic_cast<const CalibrationRequest*>(this) ;
|
||||
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()) ;
|
||||
}
|
||||
|
||||
for (unordered_map<string, Measurement>::const_iterator i
|
||||
= measurements.begin() ; i != measurements.end() ; ++i)
|
||||
csv_line << i->second.to_csv() ;
|
||||
|
||||
return csv_line.str() ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ostream& operator<<(ostream &os, const Request &r)
|
||||
{
|
||||
// Timestamp
|
||||
|
|
|
@ -96,6 +96,12 @@ public:
|
|||
void clear(void) ;
|
||||
//@}
|
||||
|
||||
/** @name Conversion accessors */
|
||||
//@{
|
||||
/// Converts to a CSV string
|
||||
const std::string to_csv(void) const ;
|
||||
//@}
|
||||
|
||||
/** @name Operations */
|
||||
//@{
|
||||
/// Computes the similarity of two Request
|
||||
|
|
Loading…
Reference in New Issue