Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC #61

Merged
merged 1 commit into from
Nov 19, 2023
Merged

POC #61

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
111 changes: 111 additions & 0 deletions davis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#ifndef DAVIS_H
#define DAVIS_H

#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_H
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;
}