Robowflex  v0.1
Making MoveIt Easy
robowflex::JSONPlanDataSetOutputter Class Reference

A benchmark outputter for storing data in a single JSON file. More...

#include <benchmarking.h>

+ Inheritance diagram for robowflex::JSONPlanDataSetOutputter:

Public Member Functions

 JSONPlanDataSetOutputter (const std::string &file)
 Constructor. More...
 
 ~JSONPlanDataSetOutputter () override
 Destructor. Closes outfile_. More...
 
void dump (const PlanDataSet &results) override
 Dumps results into outfile_, and opens outfile_ if not already done so. More...
 
- Public Member Functions inherited from robowflex::PlanDataSetOutputter
virtual ~PlanDataSetOutputter ()=default
 Virtual destructor for cleaning up resources. More...
 

Private Attributes

bool is_init_ {false}
 Have we initialized the outputter (on first result)? More...
 
const std::string file_
 Filename to open. More...
 
std::ofstream outfile_
 Output stream. More...
 

Detailed Description

A benchmark outputter for storing data in a single JSON file.

Definition at line 522 of file benchmarking.h.

Constructor & Destructor Documentation

◆ JSONPlanDataSetOutputter()

JSONPlanDataSetOutputter::JSONPlanDataSetOutputter ( const std::string file)

Constructor.

Parameters
[in]fileFilename to save results to.

JSONPlanDataSetOutputter

Definition at line 532 of file benchmarking.cpp.

532  : file_(file)
533 {
534 }
const std::string file_
Filename to open.
Definition: benchmarking.h:541

◆ ~JSONPlanDataSetOutputter()

JSONPlanDataSetOutputter::~JSONPlanDataSetOutputter ( )
override

Destructor. Closes outfile_.

Definition at line 536 of file benchmarking.cpp.

537 {
538  outfile_ << "}" << std::endl;
539  outfile_.close();
540 }
std::ofstream outfile_
Output stream.
Definition: benchmarking.h:542
T close(T... args)
T endl(T... args)

Member Function Documentation

◆ dump()

void JSONPlanDataSetOutputter::dump ( const PlanDataSet results)
overridevirtual

Dumps results into outfile_, and opens outfile_ if not already done so.

Parameters
[in]resultsResults to dump to file.

Implements robowflex::PlanDataSetOutputter.

Definition at line 542 of file benchmarking.cpp.

543 {
544  if (not is_init_)
545  {
547  outfile_ << "{";
548  // TODO: output specific information about the scene and planner structs?
549 
550  is_init_ = true;
551  }
552  else
553  outfile_ << ",";
554 
555  outfile_ << "\"" << results.name << "\":[";
556 
557  const auto &data = results.getFlatData();
558 
559  for (size_t i = 0; i < data.size(); i++)
560  {
561  const auto &run = data[i];
562  outfile_ << "{";
563 
564  outfile_ << "\"name\": \"run_" << run->query.name << "\",";
565  outfile_ << "\"time\":" << run->time << ",";
566  outfile_ << "\"success\":" << run->success;
567 
568  for (const auto &metric : run->metrics)
569  outfile_ << ",\"" << metric.first << "\":" << toMetricString(metric.second);
570 
571  outfile_ << "}";
572 
573  // Write the command between each run.
574  if (i != data.size() - 1)
575  outfile_ << "," << std::endl;
576  }
577 
578  outfile_ << "]";
579 }
bool is_init_
Have we initialized the outputter (on first result)?
Definition: benchmarking.h:540
std::vector< PlanDataPtr > getFlatData() const
Get the full data set as a flat vector.
std::string name
Name of this dataset.
Definition: benchmarking.h:167
void createFile(std::ofstream &out, const std::string &file)
Creates a file and opens an output stream. Creates directories if they do not exist.
std::string toMetricString(const PlannerMetric &metric)
Convert a planner metric into a string.

Member Data Documentation

◆ file_

const std::string robowflex::JSONPlanDataSetOutputter::file_
private

Filename to open.

Definition at line 541 of file benchmarking.h.

◆ is_init_

bool robowflex::JSONPlanDataSetOutputter::is_init_ {false}
private

Have we initialized the outputter (on first result)?

Definition at line 540 of file benchmarking.h.

◆ outfile_

std::ofstream robowflex::JSONPlanDataSetOutputter::outfile_
private

Output stream.

Definition at line 542 of file benchmarking.h.


The documentation for this class was generated from the following files: