Skip to content

Commit

Permalink
removed dep
Browse files Browse the repository at this point in the history
  • Loading branch information
SermetPekin committed Nov 4, 2024
1 parent 4139564 commit 4a1e748
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 110 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ build/
.env
.json

*.csv

evdscpp
evdscpp.dSYM


3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ make
```


g++ -g -o ./bin/t ./src/main.cpp -lcurl -L./extern/nlohmann-json_arm64-osx/include --std=c++20

## Manual Compilation

If you prefer to compile `evdscpp` manually, you can use the following `g++` command. Make sure you have all necessary dependencies, including `libcurl` and `nlohmann-json`, installed and available in your include/library paths.

```bash
g++ -g -o ./evdscpp ./src/main.cpp -lcurl -L./extern/nlohmann-json_arm64-osx/include --std=c++20
g++ -g -o ./evdscpp ./src/main.cpp -lcurl -L./extern/nlohmann --std=c++20

```

Expand Down
110 changes: 3 additions & 107 deletions src/dataframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
#include <iostream>
#include <optional>

// #include "export_xls.h"
#include <OpenXLSX.hpp>

using namespace OpenXLSX;


#include <typeindex>
#include <typeinfo>
Expand All @@ -32,7 +30,6 @@ namespace evds

class DataFrame;

void save_as_excel(const DataFrame &df, const std::string &filename);

void save_as_csv(const DataFrame &df, const std::string &filename, std::optional<char> delimiter = std::nullopt) ;
using Cell = std::variant<std::monostate, double, long long, std::string>;
Expand Down Expand Up @@ -178,24 +175,7 @@ namespace evds
"Unsupported file name type. Must be std::string, const char*, or char array.");
}
}
template <typename T>
void to_excel(const T &file_name)
{
if constexpr (std::is_same_v<T, std::string> ||
std::is_same_v<T, const char *> ||
(std::is_array_v<T> && std::is_same_v<std::remove_extent_t<T>, char>))
{
m_save_as_excel(file_name);
}
else
{
static_assert(std::is_same_v<T, std::string> ||
std::is_same_v<T, const char *> ||
(std::is_array_v<T> && std::is_same_v<std::remove_extent_t<T>, char>),
"Unsupported file name type. Must be std::string, const char*, or char array.");
}
}


void show()
{
auto cols = get_column_names();
Expand Down Expand Up @@ -245,94 +225,10 @@ namespace evds
save_as_csv(*this, file_name_ , delimiter );
}

void m_save_as_excel(const std::string &file_name)
{
save_as_excel(*this, file_name);
}

void m_save_as_excel(const char *file_name)
{
const std::string file_name_(file_name);
save_as_excel(*this, file_name_);
}

};

void save_as_excel(const DataFrame &df, const std::string &filename)
{

std::cout << "[saving excel] " << filename << "\n";
XLDocument doc;
doc.create(filename);
auto wks = doc.workbook().worksheet("Sheet1");

auto column_names = df.get_column_names();
size_t max_num_rows = 0;

for (const auto &col_name : column_names)
{
auto col_data = df.columns.at(col_name);
max_num_rows = std::max(max_num_rows, col_data.size());
}

// ............................................................. headers

for (size_t col = 0; col < column_names.size(); ++col)
{
wks.cell(1, col + 1).value() = column_names[col];
}

// ..................................................... Main Iteration
for (size_t row = 0; row < max_num_rows; ++row)
{
for (size_t col = 0; col < column_names.size(); ++col)
{
const auto &col_name = column_names[col];
const auto &col_data = df.columns.at(col_name);

if (row < col_data.size())
{
// Get the value from the column
const auto &cell = col_data[row];

// .............. main
std::visit([&](const auto &value)
{
using T = std::decay_t<decltype(value)>;
if constexpr (std::is_same_v<T, std::monostate>)
{
wks.cell(row + 2, col + 1).value() = "NaN";
}
else if constexpr (std::is_same_v<T, double>)
{
if (std::isnan(value))
{
wks.cell(row + 2, col + 1).value() = "NaN";
}
else
{
wks.cell(row + 2, col + 1).value() = value;
}
}
else
{
wks.cell(row + 2, col + 1).value() = value;
} }, cell);
}
else
{

wks.cell(row + 2, col + 1).value() = "NaN";
}
}
}

doc.save();
doc.close();
}




void save_as_csv(const DataFrame &df, const std::string &filename, std::optional<char> delimiter )
{
std::cout << "[saving csv] " << filename << "\n";
Expand Down
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ int main(int argc, char *argv[])
df_current = df;
std::string f_name = getShortFilename(x);

//df.to_excel("data_" + f_name + ".xlsx");
df.to_csv("data_" + f_name + ".csv" , ',');

}
Expand Down

0 comments on commit 4a1e748

Please sign in to comment.