Skip to content

Commit

Permalink
Davis to 'dv' and 'dvs' (#72)
Browse files Browse the repository at this point in the history
* WIP (DAVIS to DVS)

* separate namespaces for davis

---------

Co-authored-by: Valery <[email protected]>
  • Loading branch information
AntonMrt and ValeryStk authored May 8, 2024
1 parent 983348c commit d2b20be
Show file tree
Hide file tree
Showing 18 changed files with 338 additions and 316 deletions.
30 changes: 15 additions & 15 deletions Tests/ArrayCoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ using std::string;
using std::vector;

TEST(ArrayCore, showDefaultSettings) {
EXPECT_EQ(davis::isPlotlyScriptExists(), true);
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
vector<vector<double>> values = {{30.3, 400, 400, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
bool result = davis::show(values, "testDefaultSettings");
bool result = dv::show(values, "testDefaultSettings");
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showHeatMap1) {
EXPECT_EQ(davis::isPlotlyScriptExists(), true);
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
vector<vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
auto settings = davis::createShowSettingsHeatMap(davis::colorscales::GLAMOUR);
bool result = davis::show(values, "showHeatMap1", settings.get());
auto settings = dvs::createShowSettingsHeatMap(dvs::colorscales::GLAMOUR);
bool result = dv::show(values, "showHeatMap1", settings.get());
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showSurface1) {
EXPECT_EQ(davis::isPlotlyScriptExists(), true);
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
vector<vector<double>> values = {{30.3, 40, 98, 76}, {99, 45, 20, 1}, {5, 56, 93, 25}, {45, 23, 90, 2}};
auto settings = davis::createShowSettingsSurface();
bool result = davis::show(values, "showSurface1", settings.get());
auto settings = dvs::createShowSettingsSurface();
bool result = dv::show(values, "showSurface1", settings.get());
EXPECT_EQ(result, true);
}

Expand All @@ -39,7 +39,7 @@ TEST(ArrayCore, showPseudo2D) {
vals4[i * cols + j] = i * cols + j;
}
}
bool result = davis::show(vals4, rows, cols, "showPseudo2D");
bool result = dv::show(vals4, rows, cols, "showPseudo2D");
EXPECT_EQ(result, true);
}

Expand All @@ -53,28 +53,28 @@ TEST(ArrayCore, showArray2D) {
vals5[i][j] = i * cols2 + j;
}
}
bool result = davis::show(vals5, rows2, cols2);
bool result = dv::show(vals5, rows2, cols2);
EXPECT_EQ(result, true);
}

TEST(ArrayCore, testChartDefault) {
vector<int> vec = {-5, -3, -1, 0, 2, 4, 8, 15, 16};
bool result = davis::show(vec, "testChartDefault");
bool result = dv::show(vec, "testChartDefault");
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showChart) {
int vals3[] = {2, 6, 4, -34, 56, 33, 2, 15};
bool result = davis::show(vals3, sizeof(vals3) / sizeof(vals3[0]), "showChart");
bool result = dv::show(vals3, sizeof(vals3) / sizeof(vals3[0]), "showChart");
EXPECT_EQ(result, true);
}

TEST(ArrayCore, readAndShowMatrixFromFile) {
EXPECT_EQ(davis::isPlotlyScriptExists(), true);
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
vector<vector<double>> values;
bool readRes = davis::readMatrix(values, "./data/2023_07_19-12_59_31_379_Baumer2_text.csv", ';');
bool readRes = dvs::readMatrix(values, "./data/2023_07_19-12_59_31_379_Baumer2_text.csv", ';');
EXPECT_EQ(readRes, true);
bool result = davis::show(values, "readAndShowMatrixFromFile");
bool result = dv::show(values, "readAndShowMatrixFromFile");
EXPECT_EQ(result, true);
}

Expand Down
18 changes: 9 additions & 9 deletions Tests/PlotlyLibTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using std::string;
TEST(PlotlyMaker, CreateDefaultHeatMapHtmlPageTest) {
std::vector<std::vector<double>>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}};
std::string str_page = "test_page";
bool result = davis::createHtmlPageWithPlotlyJS(testValues, str_page, davis::visualizationTypes::HEATMAP, davis::colorscales::GLAMOUR);
bool result = dvs::createHtmlPageWithPlotlyJS(testValues, str_page, dvs::visualizationTypes::HEATMAP, dvs::colorscales::GLAMOUR);
std::ofstream out("example.html");
if (out.is_open()) {
out << str_page.c_str();
Expand All @@ -22,32 +22,32 @@ TEST(PlotlyMaker, CreateDefaultHeatMapHtmlPageTest) {
TEST(PlotlyMaker, ShowGlamourHeatMapHtmlPageTest) {
std::vector<std::vector<double>>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}};
std::string str_page = "veryGlamourPage";
auto settings = std::make_unique<davis::ShowSettingsHeatMap>(davis::colorscales::GLAMOUR);
bool result = davis::showHeatMapInBrowser(testValues, str_page, settings.get());
auto settings = std::make_unique<dvs::ShowSettingsHeatMap>(dvs::colorscales::GLAMOUR);
bool result = dvs::showHeatMapInBrowser(testValues, str_page, settings.get());
EXPECT_EQ(result, true);
}

TEST(PlotlyMaker, ShowThermalHeatMapHtmlPageTest) {
std::vector<std::vector<double>>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}};
std::string str_page = "veryHotPage";
auto settings = std::make_unique<davis::ShowSettingsHeatMap>(davis::colorscales::THERMAL);
bool result = davis::showHeatMapInBrowser(testValues, str_page, settings.get());
auto settings = std::make_unique<dvs::ShowSettingsHeatMap>(dvs::colorscales::THERMAL);
bool result = dvs::showHeatMapInBrowser(testValues, str_page, settings.get());
EXPECT_EQ(result, true);
}

TEST(PlotlyMaker, ShowSunnyHeatMapHtmlPageTest) {
std::vector<std::vector<double>>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}};
std::string str_page = "SunnyPage";
auto settings = std::make_unique<davis::ShowSettingsHeatMap>(davis::colorscales::SUNNY);
bool result = davis::showHeatMapInBrowser(testValues, str_page, settings.get());
auto settings = std::make_unique<dvs::ShowSettingsHeatMap>(dvs::colorscales::SUNNY);
bool result = dvs::showHeatMapInBrowser(testValues, str_page, settings.get());
EXPECT_EQ(result, true);
}

TEST(PlotlyMaker, ShowThermalSurfaceHtmlPageTest) {
std::vector<std::vector<double>>testValues = {{43, 400, 54, 980}, {200, 36, 400, 55}, {120, 4, 650, 5}};
std::string str_page = "ThermalSurfacePage";
auto settings = std::make_unique<davis::ShowSettingsSurface>(davis::colorscales::THERMAL);
bool result = davis::showSurfaceInBrowser(testValues, str_page, settings.get());
auto settings = std::make_unique<dvs::ShowSettingsSurface>(dvs::colorscales::THERMAL);
bool result = dvs::showSurfaceInBrowser(testValues, str_page, settings.get());
EXPECT_EQ(result, true);
}

Expand Down
86 changes: 43 additions & 43 deletions array_core/array_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,138 +8,138 @@
#include "common_utils/common_utils.h"
#include "common_utils/common_constants.h"

namespace davis {
//#START_GRAB_TO_DAVIS_NAMESPACE
namespace dv {
//#START_GRAB_TO_DV_NAMESPACE

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


//! two-dimensional vector
template <typename T>
bool show(const vector<vector<T>>& data, const string& title = kAppName,
ShowSettings* settings = nullptr);
bool show(const vector<vector<T>>& data, const string& title = dvs::kAppName,
dvs::ShowSettings* settings = nullptr);

//! two-dimensional array
template <typename T>
bool show(T** data, uint64_t arrRows, uint64_t arrCols,
const string& title = kAppName, ShowSettings* settings = nullptr);
const string& title = dvs::kAppName, dvs::ShowSettings* settings = nullptr);

//! a one-dimensional array that simulates a two-dimensional one (element access [i*cols+j])
template <typename T>
bool show(const T* data, uint64_t arrRows, uint64_t arrCols,
const string& title = kAppName, ShowSettings* settings = nullptr);
const string& title = dvs::kAppName, dvs::ShowSettings* settings = nullptr);

//! one-dimensional vector
template <typename T>
bool show(const vector<T>& data, const string& title = kAppName,
ShowSettings* settings = nullptr);
bool show(const vector<T>& data, const string& title = dvs::kAppName,
dvs::ShowSettings* settings = nullptr);

//! one-dimensional array
template <typename T>
bool show(const T* data, uint64_t count, const string& title = kAppName,
ShowSettings* settings = nullptr);
bool show(const T* data, uint64_t count, const string& title = dvs::kAppName,
dvs::ShowSettings* settings = nullptr);

// ***********************************
// template functions implementations:
// ***********************************

template <typename T>
bool show(const vector<vector<T>>& data, const string& title,
ShowSettings* settings) {
dvs::ShowSettings *settings) {
vector<vector<double>> vecVecDbl;
vecVecDbl.reserve(data.size());
for (vector<T> row : data) {
vector<double> dblRow(row.begin(), row.end());
vecVecDbl.emplace_back(dblRow);
}
bool res = false;
std::unique_ptr<ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
std::unique_ptr<dvs::ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
if (settings == nullptr) {
settings = new ShowSettingsHeatMap();
settings = new dvs::ShowSettingsHeatMap();
smartP.reset(settings);
}
if (settings->getVisualType() == davis::visualizationTypes::HEATMAP)
res = davis::showHeatMapInBrowser(vecVecDbl, title, static_cast<const ShowSettingsHeatMap*>(settings));
else if (settings->getVisualType() == davis::visualizationTypes::SURFACE)
res = davis::showSurfaceInBrowser(vecVecDbl, title, static_cast<const ShowSettingsSurface*>(settings));
if (settings->getVisualType() == dvs::visualizationTypes::HEATMAP)
res = dvs::showHeatMapInBrowser(vecVecDbl, title, static_cast<const dvs::ShowSettingsHeatMap*>(settings));
else if (settings->getVisualType() == dvs::visualizationTypes::SURFACE)
res = dvs::showSurfaceInBrowser(vecVecDbl, title, static_cast<const dvs::ShowSettingsSurface*>(settings));
return res;
}

template <typename T>
bool show(T** data, uint64_t arrRows, uint64_t arrCols, const string& title,
ShowSettings* settings) {
dvs::ShowSettings *settings) {
vector<vector<double>> vecVecDbl;
vecVecDbl.reserve(arrRows);
for (uint64_t i = 0; i < arrRows; ++i) {
vector<double> dblRow(&data[i][0], &data[i][0] + arrCols);
vecVecDbl.emplace_back(dblRow);
}
bool res = false;
std::unique_ptr<ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
std::unique_ptr<dvs::ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
if (settings == nullptr) {
settings = new ShowSettingsHeatMap();
settings = new dvs::ShowSettingsHeatMap();
smartP.reset(settings);
}
if (settings->getVisualType() == davis::visualizationTypes::HEATMAP)
res = davis::showHeatMapInBrowser(vecVecDbl, title, static_cast<const ShowSettingsHeatMap*>(settings));
else if (settings->getVisualType() == davis::visualizationTypes::SURFACE)
res = davis::showSurfaceInBrowser(vecVecDbl, title, static_cast<const ShowSettingsSurface*>(settings));
if (settings->getVisualType() == dvs::visualizationTypes::HEATMAP)
res = dvs::showHeatMapInBrowser(vecVecDbl, title, static_cast<const dvs::ShowSettingsHeatMap*>(settings));
else if (settings->getVisualType() == dvs::visualizationTypes::SURFACE)
res = dvs::showSurfaceInBrowser(vecVecDbl, title, static_cast<const dvs::ShowSettingsSurface*>(settings));
return res;
}

template <typename T>
bool show(const T* data, uint64_t arrRows, uint64_t arrCols, const string& title,
ShowSettings* settings) {
dvs::ShowSettings *settings) {
vector<vector<double>> vecVecDbl;
vecVecDbl.reserve(arrRows);
for (uint64_t i = 0; i < arrRows; ++i) {
vector<double> dblRow(&data[i * arrCols], &data[i * arrCols] + arrCols);
vecVecDbl.emplace_back(dblRow);
}
bool res = false;
std::unique_ptr<ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
std::unique_ptr<dvs::ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
if (settings == nullptr) {
settings = new ShowSettingsHeatMap();
settings = new dvs::ShowSettingsHeatMap();
smartP.reset(settings);
}
if (settings->getVisualType() == davis::visualizationTypes::HEATMAP)
res = davis::showHeatMapInBrowser(vecVecDbl, title, static_cast<const ShowSettingsHeatMap*>(settings));
else if (settings->getVisualType() == davis::visualizationTypes::SURFACE)
res = davis::showSurfaceInBrowser(vecVecDbl, title, static_cast<const ShowSettingsSurface*>(settings));
if (settings->getVisualType() == dvs::visualizationTypes::HEATMAP)
res = dvs::showHeatMapInBrowser(vecVecDbl, title, static_cast<const dvs::ShowSettingsHeatMap*>(settings));
else if (settings->getVisualType() == dvs::visualizationTypes::SURFACE)
res = dvs::showSurfaceInBrowser(vecVecDbl, title, static_cast<const dvs::ShowSettingsSurface*>(settings));
return res;
}

template <typename T>
bool show(const vector<T>& data, const string& title,
ShowSettings* settings) {
dvs::ShowSettings* settings) {
vector<double> dblRow(data.begin(), data.end());
bool res = false;
std::unique_ptr<ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
std::unique_ptr<dvs::ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
if (settings == nullptr) {
settings = new ShowSettingsChart();
settings = new dvs::ShowSettingsChart();
smartP.reset(settings);
}
if (settings->getVisualType() == davis::visualizationTypes::CHART)
res = davis::showLineChartInBrowser(dblRow, title, static_cast<const ShowSettingsChart*>(settings));
if (settings->getVisualType() == dvs::visualizationTypes::CHART)
res = dvs::showLineChartInBrowser(dblRow, title, static_cast<const dvs::ShowSettingsChart*>(settings));
return res;
}

template <typename T>
bool show(const T* data, uint64_t count, const string& title,
ShowSettings* settings) {
dvs::ShowSettings *settings) {
vector<double> dblRow(data, data + count);
bool res = false;
std::unique_ptr<ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
std::unique_ptr<dvs::ShowSettings> smartP; //Smart pointer for auto deleting settings if it will be created bellow via NEW
if (settings == nullptr) {
settings = new ShowSettingsChart();
settings = new dvs::ShowSettingsChart();
smartP.reset(settings);
}
if (settings->getVisualType() == davis::visualizationTypes::CHART)
res = davis::showLineChartInBrowser(dblRow, title, static_cast<const ShowSettingsChart*>(settings));
if (settings->getVisualType() == dvs::visualizationTypes::CHART)
res = dvs::showLineChartInBrowser(dblRow, title, static_cast<const dvs::ShowSettingsChart*>(settings));
return res;
}
//#STOP_GRAB_TO_DAVIS_NAMESPACE
} // end namespace davis
//#STOP_GRAB_TO_DV_NAMESPACE
} // end namespace dvs

#endif //ARRAY_CORE_ARRAY_CORE_H_
6 changes: 3 additions & 3 deletions common_utils/common_constants.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "common_constants.h"

namespace davis {
//#START_GRAB_TO_DAVIS_NAMESPACE
namespace dvs {
//#START_GRAB_TO_NAMESPACE
const char kAppName[] = "davis";
const char kOutFolderName[] = "davis_htmls/";
const char kPlotlyJsWorkPath[] = "./davis_htmls/plotly-2.27.0.min.js";
const char kPlotlyJsName[] = "plotly-2.27.0.min.js";
const char kPlotlyJsResourcePath[] = "plotly_maker/plotly-2.27.0.min.js";
//#STOP_GRAB_TO_DAVIS_NAMESPACE
//#STOP_GRAB_TO_NAMESPACE
}
6 changes: 3 additions & 3 deletions common_utils/common_constants.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef COMMON_UTILS_COMMON_CONSTANTS_H
#define COMMON_UTILS_COMMON_CONSTANTS_H

namespace davis {
//#START_GRAB_TO_DAVIS_NAMESPACE
namespace dvs {
//#START_GRAB_TO_NAMESPACE
extern const char kAppName[];
extern const char kOutFolderName[];
extern const char kPlotlyJsName[];
extern const char kPlotlyJsResourcePath[];
extern const char kPlotlyJsWorkPath[];
//#STOP_GRAB_TO_DAVIS_NAMESPACE
//#STOP_GRAB_TO_NAMESPACE
}

#endif // COMMON_UTILS_COMMON_CONSTANTS_H
8 changes: 4 additions & 4 deletions common_utils/common_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void openFileBySystem(const string& file_name) {
//#STOP_GRAB_TO_NAMESPACE
} // namespace

namespace davis {
//#START_GRAB_TO_DAVIS_NAMESPACE
namespace dvs {
//#START_GRAB_TO_NAMESPACE
string getCurrentPath() {
#if defined (_WIN32) || (__linux__)
char buffer[1024];
Expand Down Expand Up @@ -170,5 +170,5 @@ vector<string> split(const string& target, char c) {

return result;
}
//#STOP_GRAB_TO_DAVIS_NAMESPACE
}; // namespace davis
//#STOP_GRAB_TO_NAMESPACE
}; // namespace dvs
8 changes: 4 additions & 4 deletions common_utils/common_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <vector>
//#STOP_GRAB_TO_INCLUDES_LIST

namespace davis {
//#START_GRAB_TO_DAVIS_NAMESPACE
namespace dvs {
//#START_GRAB_TO_NAMESPACE
using std::string;
using std::vector;

Expand All @@ -33,7 +33,7 @@ bool readMatrix(vector<vector<double>>& outMatrix, const string& path, char dlmt
// Now it doesn't work.
bool deleteFolder(const char* fname);

//#STOP_GRAB_TO_DAVIS_NAMESPACE
}; // namespace davis
//#STOP_GRAB_TO_NAMESPACE
}; // namespace dvs

#endif // COMMON_UTILS_COMMON_UTILS_H_
Loading

0 comments on commit d2b20be

Please sign in to comment.