Skip to content

Commit

Permalink
POC
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeryStk committed Nov 18, 2023
1 parent 8d87b5b commit 1679e3b
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ add_subdirectory(plotly_maker)
add_subdirectory(array_core)
add_subdirectory(common_utils)

set(HEADER_FILES davis.h)

# tests
enable_testing()
add_subdirectory(Tests)

include_directories(${RESOURCE_MANAGER_INCLUDE_DIRS})
rm_embed_resources(RESOURCES "plotly_maker/plotly-2.27.0.min.js")

add_executable("davis_launcher" davis_launcher.cpp davis.h)

add_executable(${projectName} main.cpp cxxopts.hpp ${RESOURCES})
target_link_libraries(${projectName} "ArrayCore")
target_link_libraries("davis_launcher" "PlotlyMaker" "CommonUtils")



Expand Down
8 changes: 8 additions & 0 deletions common_utils/common_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,12 @@ bool getDataFromFile(const string& path, string& result) {
return true;
}

void runDavisBySystem(const string& args) {
std::string command = "davis ";
command.append(args);
system(command.c_str());
args.size();
command.reserve(1000);
}

}; // namespace davis
2 changes: 2 additions & 0 deletions common_utils/common_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ bool getDataFromFile(const string& path, string& result);
// Now it doesn't work.
bool deleteFolder(const char* fname);

void runDavisBySystem(const string& args);

}; // namespace davis

#endif // COMMON_UTILS_COMMON_UTILS_H_
111 changes: 111 additions & 0 deletions davis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#ifndef DAVIS_HPP
#define DAVIS_HPP

#include <string>
#include <vector>
#include <cstdlib>
#include "plotly_maker/plotly_maker.h"

namespace {

using std::string;
using std::vector;

constexpr char davis[] = "davis --";
constexpr char prefix[] = "=\"";
constexpr char postfix[] = "\"";
constexpr char command_heatmap[] = "heatmap";
constexpr char command_surface[] = "surface";
constexpr char command_line_chart[] = "linechart";

void runDavisBySystem(const string& args) {
system(args.c_str());
}
void makeStringFromValues(const vector<double> in_values,
string& out_values) {
for (size_t i = 0; i < in_values.size(); ++i) {
std::string value = std::to_string(in_values[i]);
out_values.append(value);
if (i != in_values.size() - 1) {
out_values.append(",");
}
}

}
void makeArgs(const davis::showSettings& settings,
const vector<vector<double>>& values, string& out) {

switch (settings.visualType) {
case davis::visualizationTypes::CHART:
break;
case davis::visualizationTypes::HEATMAP:
//duplicated code
out.append(davis);
out.append(command_heatmap);
out.append(prefix);
for (size_t i = 0; i < values.size(); ++i) {
makeStringFromValues(values[i], out);
if (i != values.size() - 1)
out.append(";");
}
out.append(postfix);
break;
case davis::visualizationTypes::SURFACE:
//duplicated code
out.append(davis);
out.append(command_surface);
out.append(prefix);
for (size_t i = 0; i < values.size(); ++i) {
makeStringFromValues(values[i], out);
if (i != values.size() - 1)
out.append(";");
}
out.append(postfix);
break;
}
}

void makeArgs(const davis::showSettings& settings,
vector<double>& values, string& out) {

switch (settings.visualType) {
case davis::visualizationTypes::CHART:
out.append(davis);
out.append(command_line_chart);
out.append(prefix);
makeStringFromValues(values, out);
out.append(postfix);
break;
case davis::visualizationTypes::HEATMAP:
break;
case davis::visualizationTypes::SURFACE:
break;
}
}

}

namespace dv {

void show(const davis::showSettings& settings,
vector<vector<double>>& values);
void show(const davis::showSettings& settings,
vector<double>& values);

void show(const davis::showSettings& settings,
vector<double>& values) {
string args;
makeArgs(settings, values, args);
runDavisBySystem(args);
}

void show(const davis::showSettings& settings,
vector<vector<double>>& values) {
string args;
makeArgs(settings, values, args);
runDavisBySystem(args);
}

}

#endif // DAVIS_HPP
14 changes: 14 additions & 0 deletions davis_launcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "davis.h"

int main(int argc, char* argv[]) {
davis::showSettings settings;
settings.visualType = davis::visualizationTypes::CHART;
vector<double>v = {8.0, 8.0, 9, 0, 55};
vector<vector<double>>hm = {{8.0, 8.0, 9, 0, 55}, {5.0, 18.0, 0.9, 50, 15}};
dv::show(settings, v);
settings.visualType = davis::visualizationTypes::HEATMAP;
dv::show(settings, hm);
settings.visualType = davis::visualizationTypes::SURFACE;
dv::show(settings, hm);
return EXIT_SUCCESS;
}
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


int main(int argc, char* argv[]) {

cxxopts::Options options("davis", "data visualization utility");
options.add_options()
("h,help", "davis commands")
Expand Down

0 comments on commit 1679e3b

Please sign in to comment.