Skip to content

Commit

Permalink
Debugging: Loading a general Analysis File
Browse files Browse the repository at this point in the history
  • Loading branch information
AKMaily committed Oct 7, 2024
1 parent ba6f621 commit 7f38b54
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
19 changes: 9 additions & 10 deletions src/analyze_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,17 @@ void AnalyzeStateManager::whileSendingProcess(){
void AnalyzeStateManager::generateAnalyzeAnswerPopUp(){
if(ImGui::BeginPopupModal(appLanguage[Key::Data_upload]), nullptr,
ImGuiWindowFlags_AlwaysAutoResize){
fs::path outFile;
ImGui::Text(appLanguage[Key::Analyse_Answer_Text]);
ImGui::SeparatorText(" ");
ImGui::Text(apiResponse == "empty" ? appLanguage[Key::Upload_failure]
: appLanguage[Key::Upload_success]);
ImGui::SeparatorText(" ");
if(!analyzeSaved){
this->writeAnalysisAnswerIntoFile(outFile);
this->writeAnalysisAnswerIntoFile();
}
if(ImGui::Button(appLanguage[Key::SeeAnalyzeResults])){
std::cout << "See results" << std::endl;
AddPlotFromFile(outFile);
AddPlotFromFile(this->outputFilePath);
reset();
ImGui::CloseCurrentPopup();
}
Expand All @@ -261,21 +260,21 @@ void AnalyzeStateManager::generateAnalyzeAnswerPopUp(){
}
}

void AnalyzeStateManager::writeAnalysisAnswerIntoFile(fs::path &outFile) {
void AnalyzeStateManager::writeAnalysisAnswerIntoFile() {
if (apiResponse != "empty") {
fs::path complete_path = fs::current_path() / "analyze";
if (!fs::exists(complete_path))
fs::create_directories(complete_path);

outFile = complete_path / ("Analysis_" + fs::path(fileNameBuf).filename().string());
outputFilePath = complete_path / ("Analysis_" + fs::path(fileNameBuf).filename().string());

std::ofstream writefile(outFile, std::ios::trunc);
std::ofstream writefile(outputFilePath, std::ios::trunc);
if (!writefile.is_open()) {
writefile.clear();
fmt::println("Could not create {} for writing!", outFile.string());
fmt::println("Could not create {} for writing!", outputFilePath.string());
} else {
fmt::println("Start saving {}.", outFile.string());
bool test = saveAsCSV(apiResponse, outFile);
fmt::println("Start saving {}.", outputFilePath.string());
bool test = saveAsCSV(apiResponse);
std::cout << "test:" << test << std::endl;
/*writefile << apiResponse;
writefile.flush();
Expand All @@ -286,7 +285,7 @@ void AnalyzeStateManager::writeAnalysisAnswerIntoFile(fs::path &outFile) {
}
}

bool AnalyzeStateManager::saveAsCSV(const std::string& apiResponse, const fs::path& outputFilePath) {
bool AnalyzeStateManager::saveAsCSV(const std::string& apiResponse) {
try {
// Parse den API-Response-String in ein JSON-Objekt
nlohmann::json jsonData = nlohmann::json::parse(apiResponse);
Expand Down
5 changes: 3 additions & 2 deletions src/analyze_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class AnalyzeStateManager {
void selectCurrentDevice(const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &);
void whileSendingProcess();

void writeAnalysisAnswerIntoFile(fs::path &);
void writeAnalysisAnswerIntoFile();

bool saveAsCSV(const std::string&, const fs::path&);
bool saveAsCSV(const std::string&);


private:
Expand All @@ -85,4 +85,5 @@ class AnalyzeStateManager {
std::future<std::string> future;
nlohmann::ordered_json loadedDataJSON;
std::string apiResponse;
fs::path outputFilePath;
};
9 changes: 7 additions & 2 deletions src/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void addPlots(const char *name,
plotAxes = getDeviceInfos();

if (ImPlot::BeginPlot(name, plotRegion, ImPlotFlags_NoFrame)) {

// TODO: if bool areFilesLoading = false this , else AddPlotFromFile
double x_min = std::numeric_limits<double>::max();
double x_max = std::numeric_limits<double>::min();

Expand Down Expand Up @@ -363,15 +365,18 @@ void rstSettings(const decltype(captureData) &loadedFiles) {
// TODO if(State::LOADDATAFROMFILE || State::LOADANALYSISDATA) { axesSetup(x_max, unit.first, ImAxis xaxis, unit.second, ImAxis y_axis, yMin, yMax);}
// TODO addPlot();

//TODO : Set this also up for saved OmniScope files

void AddPlotFromFile(fs::path &filePath){
LoadedFiles loadedFile;
loadedFile.LoadFromFile(filePath);
// ImPlot::SetAxis(loadedFile.units.first, loadedFile.units.second);
// ImPlot::PlotLine(outputFile.c_str(), loadedFile.data.first(), loadedFile.data.second, static_cast<int>(x_values.size()))
loadedFile.printData();

}

void LoadedFiles::LoadFromFile(fs::path &filePath) {
std::ifstream file(filePath);
std::ifstream file(filePath, std::ios::binary);
if (!file.is_open()) {
std::cerr << "Fehler: Datei konnte nicht geöffnet werden." << std::endl;
}
Expand Down

0 comments on commit 7f38b54

Please sign in to comment.