holoscan::CsvDataExporter

Beta
View as Markdown

A class to support exporting Holoscan application data in CSV format for Holoscan Federated Analytics.

The directory will be created with the app name in the data root directory if it is not present already. Inside the application directory, a directory with the current timestamp will be created.

The output file name can be specified using the environment variable HOLOSCAN_ANALYTICS_DATA_FILE_NAME. If not specified, the output file named data.csv will be created inside the timestamp directory. The column names are added to the output file as a first row.

Using this class mainly involves two steps:

  • Create CsvDataExporter object specifying app name and columns.
  • Call export_data() method to add a single row to the output file.

Example:

#include <holoscan/csv_data_exporter.hpp>

Example

#include <holoscan/core/analytics/csv_data_exporter.hpp>
void export_data() {
const std::string app_name = "sample_app";
const std::vector<std::string> columns = {"column1", "column2", "column3"};
CsvDataExporter data_exporter(app_name, columns);
const std::vector<std::string> data = {"1", "2", "3"};
data_exporter.export_data(data);
...
}

Inherits from: holoscan::DataExporter (public)


Constructors

CsvDataExporter

holoscan::CsvDataExporter::CsvDataExporter(holoscan::CsvDataExporter::CsvDataExporter(
const std::string &app_name,
const std::vector<std::string> &columns
)

The constructor creates required directories and CSV file with the specified names.

Parameters

app_name
const std::string &

The application name.

columns
const std::vector<std::string> &

The column names list which will be added to the CSV file as a first row.

Destructor

~CsvDataExporter

holoscan::CsvDataExporter::~CsvDataExporter()holoscan::CsvDataExporter::~CsvDataExporter()

Methods

export_data

void holoscan::CsvDataExporter::export_data(
const std::vector<std::string> &data
) override

Exports given data to a CSV file.

Each call to the function will add one more row to the csv file.

Parameters

data
const std::vector<std::string> &

The data to be written to the CSV file.

output_file_name

const std::string & holoscan::CsvDataExporter::output_file_name() const

Returns output file name.

columns

const std::vector<std::string> & holoscan::CsvDataExporter::columns() const

Returns the column names.

app_name

const std::string & holoscan::CsvDataExporter::app_name() const

Return the application name.

data_directory

const std::string & holoscan::CsvDataExporter::data_directory() const

Returns a data directory name.

cleanup_data_directory

void holoscan::CsvDataExporter::cleanup_data_directory()

Remove the data directory and its contents.

write_row

void holoscan::CsvDataExporter::write_row(
const std::vector<std::string> &data
)

Write one row to a CSV file.

Each call to the function will just add one more row to the csv file.

Parameters

data
const std::vector<std::string> &

The data to be written to the CSV file. The number of strings passed should be same as the number of columns in CSV file.


Static methods

get_analytics_data_file_name_env

static expected<std::string, ErrorCode> holoscan::CsvDataExporter::get_analytics_data_file_name_env()

Get the value of analytics output file name environment variable HOLOSCAN_ANALYTICS_DATA_FILE_NAME.

Returns: A string if the environment variable is set else it returns error code.

get_analytics_data_directory_env

static expected<std::string, ErrorCode> holoscan::CsvDataExporter::get_analytics_data_directory_env()

Get the value of analytics data directory environment variable HOLOSCAN_ANALYTICS_DATA_DIRECTORY.

Returns: A string if the environment variable is set else it returns error code.


Member variables

NameTypeDescription
file_name_std::string
columns_std::vector< std::string >
file_std::ofstream
app_name_std::string
directory_name_std::string