Skip to content

Commit

Permalink
fixed issues with journals (#86)
Browse files Browse the repository at this point in the history
* fixed issues

* changed printing
  • Loading branch information
Mast3rwaf1z authored May 20, 2024
1 parent c96e68f commit 328139f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
10 changes: 7 additions & 3 deletions include/Routes/Journals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ class Journals : public Route {
auto meta = entry["meta"].get<string>();
auto rating = entry["rating"].get<string>();
// run sentiment analysis on answer
auto result = split_string(run_cmd(format("python ./lib/datasets/sentiment_analysis.py \"{}\" \"{}\"", meta, question))["stdout"], "\n");
auto meta_value = result[0];
auto question_value = result[1];
auto analysis = run_cmd(format("python ./lib/datasets/sentiment_analysis.py \"{}\" \"{}\"", meta, question));
auto sa_stdout = split_string(analysis["stdout"], "\n");
if (sa_stdout.size() < 2) {
continue;
}
auto meta_value = sa_stdout[0];
auto question_value = sa_stdout[1];
auto final_value = mean({stod(question_value), stod(meta_value)});
db["answers"].add({
{"value", to_string(final_value)},
Expand Down
20 changes: 12 additions & 8 deletions include/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <memory>
#include <string>
#include <cctype>
#include <sstream>

using namespace std;

Expand Down Expand Up @@ -173,14 +174,17 @@ map<string, string> run_cmd(string command) {
auto final_command = format("bash -c '{} 2> {} 1> {}'", command, stderr_path, stdout_path);
auto error_code = system(final_command.c_str());
ifstream stdout_file{stdout_path};
ifstream stderr_file{stdout_path};
stdout_file >> result["stdout"];
stderr_file >> result["stderr"];
if (error_code) {
cout << "command: " << final_command << endl;
cout << "stdout: " << result["stdout"] << endl;
cout << "stderr: " << result["stderr"] << endl;
}
ifstream stderr_file{stderr_path};
stringstream out_stream;
stringstream err_stream;
out_stream << stdout_file.rdbuf();
err_stream << stderr_file.rdbuf();
result["stdout"] = out_stream.str();
result["stderr"] = err_stream.str();

cout << "stdout: " << result["stdout"] << endl;
cout << "stderr: " << result["stderr"] << endl;

return result;
}
catch (exception& e) {
Expand Down
2 changes: 1 addition & 1 deletion lib/datasets

0 comments on commit 328139f

Please sign in to comment.