Skip to content

Commit

Permalink
Merge Master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
NP199 committed Jun 28, 2024
2 parents 2f211d6 + d0edbc2 commit abcfdb9
Show file tree
Hide file tree
Showing 15 changed files with 1,580 additions and 883 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
- os: windows-latest
triplet: x64-windows
- os: ubuntu-latest
compiler: gcc
gcc: 13
triplet: x64-linux

steps:
Expand Down Expand Up @@ -89,7 +91,7 @@ jobs:
languages/Deutsch.json
release:
runs-on: ubuntu-latest
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v')

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ target_include_directories(OmniView PUBLIC ${LIBUSB_INCLUDE_DIRS})
target_link_libraries(OmniView PUBLIC ${LIBUSB_LIBRARIES})

target_compile_definitions(OmniView PUBLIC BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
target_compile_features(OmniView PUBLIC cxx_std_20)
target_compile_features(OmniView PUBLIC cxx_std_23)
19 changes: 10 additions & 9 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
"input2": "scan_type",
"url": "https://postapi.aw4null.de/v1/uploadFile/"
},
"helplink": "https://moodle.aw4null.de/",
"github": {
"url": {
"config": "https://raw.githubusercontent.com/skunkforce/omniview/master/config/config.json",
"language": "https://raw.githubusercontent.com/skunkforce/omniview/master/languages/Deutsch.json"
}
},
"button": {
"sizex": 0.0,
"sizey": 0.0,
Expand Down Expand Up @@ -78,6 +71,13 @@
}
},
"firststart": true,
"github": {
"url": {
"config": "https://raw.githubusercontent.com/skunkforce/omniview/master/config/config.json",
"language": "https://raw.githubusercontent.com/skunkforce/omniview/master/languages/Deutsch.json"
}
},
"helplink": "https://moodle.aw4null.de/",
"language": "Deutsch",
"languagepath": "languages/",
"menubar": {
Expand All @@ -96,6 +96,7 @@
},
"scanfolder": "saves",
"text": {
"active_language": "German",
"color": {
"inactive": {
"blue": 0.5,
Expand All @@ -111,8 +112,8 @@
}
},
"font": "comicsans",
"minscale": 1,
"scale": 1.2
"minscale": 1.0,
"scale": 1.5000001192092896
},
"title": "Omniview 0.5",
"window": {
Expand Down
68 changes: 30 additions & 38 deletions src/generateTrainingData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ void generateTrainingData(
bool &open_generate_training_data,
const std::map<Omniscope::Id, std::vector<std::pair<double, double>>>
&captureData,
std::set<std::string> &savedFileNames, const nlohmann::json &config) {
std::set<std::string> &savedFileNames) {

namespace fs = std::filesystem;
ImGui::OpenPopup(appLanguage[Key::Gn_trng_data_pop]);
if (ImGui::BeginPopupModal(appLanguage[Key::Gn_trng_data_pop], nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
Expand Down Expand Up @@ -56,7 +55,7 @@ void generateTrainingData(
(ImGui::BeginCombo("##ComboDevice", "Devices & Waveforms Menu"))) {
// only one checkbox out of two sets of
// devices/waveforms is selected at any time
size_t i{};
int i{};
bool is_checked{false};
if (captureData.size())
for (const auto &[device, values] : captureData) {
Expand Down Expand Up @@ -93,14 +92,9 @@ void generateTrainingData(
} // End of the algorithm
ImGui::EndCombo();
}

// set browser properties
fileBrowser.SetTitle("Searching for .csv files");
// fileBrowser.SetTypeFilters({".csv"});

static std::string Measurement;
// one extra space for '\0' character
static char VIN[18];
static char VIN[19];
static std::string Mileage;
static std::vector<double> file_measuring_vals; // measurement values
static bool grayFields = false;
Expand All @@ -117,31 +111,27 @@ void generateTrainingData(
if (!readfile.is_open())
fmt::println("Failed to open file {}", filename);
else {
// first and second lines of file
std::string first_line, second_line;
for (size_t i = 0; !readfile.eof(); i++) {
if (i == 0) {
std::getline(readfile, first_line);
first_line.pop_back(); // remove ending new line
std::stringstream ss(first_line);
// extract input fields data from the first line
for (size_t j = 0; j < fieldsSize; j++) {
std::string substr;
std::getline(ss, substr, ',');
FieldsData[j] = substr;
}
} else if (i == 1)
std::getline(readfile, second_line); // device ID
else {
// read measuring values into the vector
constexpr size_t bigNumber{10'000'000};
readfile.ignore(bigNumber, ',');
double value{};
readfile >> value;
file_measuring_vals.emplace_back(value);
// at the last loop, the last number is picked and loop goes on
// vector pushes value before eof is reached
}
// first line of file
std::string first_line;
std::getline(readfile, first_line);
first_line.pop_back(); // remove ending new line
std::stringstream ss(first_line);
// extract input fields data from the first line
for (size_t j = 0; j < fieldsSize; j++) {
std::string substr;
std::getline(ss, substr, ',');
FieldsData[j] = substr;
}
while (!readfile.eof()) {
// read measuring values into the vector
double value{};
readfile >> value;
file_measuring_vals.emplace_back(value);
static constexpr size_t bigNumber{10'000'000};
readfile.ignore(bigNumber,
'\n'); // new line separator between elements
// at the last loop, the last number is picked, loop
// goes on and vector pushes value before eof is reached
}
// pop the extra last element
file_measuring_vals.pop_back();
Expand Down Expand Up @@ -190,6 +180,9 @@ void generateTrainingData(
callSetInptFields = false;
}

static ImGui::FileBrowser fileBrowser;
fileBrowser.SetTitle("Searching for .csv files"); // properties
// fileBrowser.SetTypeFilters({".csv"});
fileBrowser.Display();
if (fileBrowser.HasSelected()) {
if (isWrongFile(fileBrowser.GetSelected().string())) {
Expand Down Expand Up @@ -236,8 +229,7 @@ void generateTrainingData(
s += data->EventChar;
// strlen is updated when entered char passes the filter
size_t indx = strlen(VIN);

if (indx < 17)
if (indx < 18)
return !std::regex_match(
s, chars_regex); // return 0 as passed for matched chars
return 1; // discard exceeding chars
Expand Down Expand Up @@ -409,8 +401,8 @@ void generateTrainingData(

// upload data asynchronously using a separate thread
future = std::async(std::launch::async, [&] {
// take temp object returned from dump() and send it to sendData
std::string result = sendData(myJson.dump());
// take temp object returned from dump() and send it to sendData
std::string result = sendData(myJson.dump());
return result;
});

Expand Down
155 changes: 130 additions & 25 deletions src/handler.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "handler.hpp"

#include <implot.h>

#include <functional>
#include <set>

#include <implot.h>
#include "popups.hpp"
#include "get_from_github.hpp"
#include "../imgui-stdlib/imgui_stdlib.h"

std::vector<AxisInfo> getDeviceInfos() {
std::vector<AxisInfo> axisInfos;
Expand Down Expand Up @@ -226,29 +225,135 @@ void devicesList(bool const &flagPaused) {
for (auto &device : devices) doDevice(device, appLanguage[Key::Ready]);
}

void set_config(const std::string &configpath) {
if (std::filesystem::exists(configpath))
fmt::print("found config.json\n\r");
else {
fmt::print("Did not find config.json.\n Download from Github\n\r");
update_config_from_github();
void load_files(decltype(captureData) &loadedFiles,
std::map<Omniscope::Id, std::string> &loadedFilenames,
bool &loadFile) {
static std::set<fs::path> loadedFilePaths;
auto do_load = [&loadedFiles, &loadedFilenames] {
std::pair<Omniscope::Id, std::vector<std::pair<double, double>>> loadedFile;
for (const auto &path : loadedFilePaths) {
std::ifstream readfile(path, std::ios::binary);
if (!readfile.is_open())
fmt::println("Failed to open file {}", path.string());
else {
std::string first_line;
std::getline(readfile, first_line);
std::istringstream input{first_line};
static constexpr size_t fieldsSz{6};
// extract input fields data from the first line
for (size_t i = 0; i < fieldsSz; i++) {
std::string substr;
std::getline(input, substr, ',');
if (i == 3) // fourth element (Type of scope)
loadedFile.first.type = substr;
if (i == 4) // fifth element (serial of scope)
loadedFile.first.serial = substr;
}
size_t indx{2}; // y_values start from line 2 of the file
while (!readfile.eof()) { // fill the vector of the values
double value{};
readfile >> value;
loadedFile.second.emplace_back(indx++, value);
static constexpr size_t bigNumber{10'000'000};
readfile.ignore(bigNumber,
'\n'); // new line separator between elements
}
readfile.close();
loadedFile.second.pop_back(); // pop the extra last element
loadedFiles.emplace(loadedFile);
loadedFilenames.emplace(loadedFile.first, path.filename().string());
}
}
loadedFilePaths.clear();
};

if (ImGui::BeginPopupModal(appLanguage[Key::Load_file_data], nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SetItemDefaultFocus();
static ImGui::FileBrowser fileBrowser;
static std::vector<std::string> pathArr;
if (pathArr.empty())
pathArr.emplace_back("");

for (auto &path : pathArr) {
ImGui::PushID(&path); // unique IDs
ImGui::InputTextWithHint("##", appLanguage[Key::Path], &path);
ImGui::SameLine();
if (ImGui::Button(appLanguage[Key::Browse]))
fileBrowser.Open();
fileBrowser.Display();
info_popup(appLanguage[Key::Wrong_file_warning],
appLanguage[Key::Wrong_file_type]);
if (fileBrowser.HasSelected()) {
path = fileBrowser.GetSelected().string();
fileBrowser.ClearSelected();
}
if (!path.empty())
if (fs::path(path).extension() != ".csv") {
ImGui::OpenPopup(appLanguage[Key::Wrong_file_warning],
ImGuiPopupFlags_NoOpenOverExistingPopup);
path.clear();
} else
loadedFilePaths.emplace(path);
ImGui::PopID();
}
if (ImGui::Button(" + "))
pathArr.emplace_back("");
ImGui::SetItemTooltip(appLanguage[Key::Load_another_file]);
if (ImGui::Button(appLanguage[Key::Back])) {
pathArr.clear();
loadedFilePaths.clear();
loadFile = false;
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button(appLanguage[Key::Load_file])) {
pathArr.clear();
do_load();
loadFile = false;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}

void set_config(const std::string &configpath) {
if (fs::exists(configpath))
fmt::print("found config.json\n\r");
else {
fmt::print("Did not find config.json.\n Download from Github\n\r");
update_config_from_github();
}
}

void set_json(nlohmann::json &config) {
if (std::filesystem::exists(
load_json<std::string>(config, ("languagepath"))))
fmt::print("Found language: {}\n\r", appLanguage[Key::German]);
else {
fmt::print("Did not find {}.\n Download from Github\n\r",
appLanguage[Key::German]);
update_language_from_github();
}
if (fs::exists(load_json<std::string>(config, ("languagepath"))))
fmt::print("Found language: {}\n\r", appLanguage[Key::German]);
else {
fmt::print("Did not find {}.\n Download from Github\n\r",
appLanguage[Key::German]);
update_language_from_github();
}
}

void set_inital_config(nlohmann::json &config) {
ImGuiIO &io = ImGui::GetIO();
io.FontGlobalScale = config["text"]["scale"];
appLanguage =
config["text"]["active_language"] == "German" ? germanLan : englishLan;
}
void rstSettings() {
sampler.reset();
devices.clear();
savedFileNames.clear();
deviceManager.clearDevices();
captureData.clear();
plotAxes.clear();

void rstSettings(const decltype(captureData) &loadedFiles) {
sampler.reset();
devices.clear();
savedFileNames.clear();
deviceManager.clearDevices();
plotAxes.clear();
// erase all elements excpet loadedFiles
for (auto it = captureData.begin(); it != captureData.end();) {
if (!loadedFiles.contains(it->first))
it = captureData.erase(it);
else
++it;
}
}
7 changes: 5 additions & 2 deletions src/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ inline std::set<std::string> savedFileNames; // unique and ordered filenames
inline std::optional<OmniscopeSampler> sampler{};
inline std::map<Omniscope::Id, std::vector<std::pair<double, double>>>
captureData;
inline std::vector<AxisInfo> plotAxes;

inline std::vector<AxisInfo> plotAxes;
void addPlots(const char *, const bool, std::function<void(double, std::string, ImAxis_, double, double)>);
void parseDeviceMetaData(Omniscope::MetaData, std::shared_ptr<OmniscopeDevice>&);
void initDevices();
void devicesList(bool const& flagPaused);
void load_files(decltype(captureData) &, std::map<Omniscope::Id, std::string> &,
bool &);
void set_config(const std::string &);
void set_json(nlohmann::json &);
void rstSettings();
void set_inital_config(nlohmann::json &);
void rstSettings(const decltype(captureData) &);

#endif
Loading

0 comments on commit abcfdb9

Please sign in to comment.