1 #ifndef RAPP_CLOUD_COGNITIVE_EXERCISES
2 #define RAPP_CLOUD_COGNITIVE_EXERCISES
23 const std::string user,
24 const std::string test_type,
25 const std::string token,
26 std::function<
void(std::vector<std::string>,
27 std::vector<std::string>,
28 std::vector<std::string>,
31 std::string)> callback
35 boost::property_tree::ptree tree;
36 tree.put(
"test_type", test_type);
38 boost::property_tree::write_json(ss, tree,
false);
40 header_ =
"POST /hop/cognitive_test_selector HTTP/1.1\r\n"
41 +
"Content-Type: application/x-www-form-urlencoded\r\n";
51 std::stringstream ss(json);
52 std::vector<std::string> questions;
53 std::vector<std::string> possib_ans;
54 std::vector<std::string> correct_ans;
55 std::string test_instance;
56 std::string test_type;
57 std::string test_subtype;
59 boost::property_tree::ptree tree;
60 boost::property_tree::read_json(ss, tree);
62 for (
auto child : tree.get_child(
"questions")) {
63 questions.push_back(child.second.get_value<std::string>());
65 for (
auto child : tree.get_child(
"possib_ans")) {
66 possib_ans.push_back(child.second.get_value<std::string>());
68 for (
auto child : tree.get_child(
"correct_ans")) {
69 correct_ans.push_back(child.second.get_value<std::string>());
71 for (
auto child : tree.get_child(
"test_instance")) {
72 test_instance = child.second.get_value<std::string>();
74 for (
auto child : tree.get_child(
"test_type")) {
75 test_type = child.second.get_value<std::string>();
77 for (
auto child : tree.get_child(
"test_subtype")) {
78 test_subtype = child.second.get_value<std::string>();
80 for (
auto child : tree.get_child(
"error")) {
81 const std::string value = child.second.get_value<std::string>();
83 std::cerr <<
"cognitive_test_selector JSON error: " << value << std::endl;
87 catch (boost::property_tree::json_parser::json_parser_error & je) {
88 std::cerr <<
"cognitive_test_selector::handle_reply Error parsing: " << je.filename()
89 <<
" on line: " << je.line() << std::endl;
90 std::cerr << je.message() << std::endl;
101 std::function<void(std::vector<std::string>,
102 std::vector<std::string>,
103 std::vector<std::string>,
126 const std::string test_instance,
128 const std::string token,
129 std::function<
void(std::string)> callback
133 boost::property_tree::ptree tree;
134 tree.put(
"test_instance", test_instance);
135 tree.put(
"score", boost::lexical_cast<std::string>(score));
136 std::stringstream ss;
137 boost::property_tree::write_json(ss, tree,
false);
139 header_ =
"POST /hop/cognitive_record_performance HTTP/1.1\r\n"
140 +
"Content-Type: application/x-www-form-urlencoded\r\n";
150 std::stringstream ss(json);
151 std::string performance_entry;
153 boost::property_tree::ptree tree;
154 boost::property_tree::read_json(ss, tree);
156 for (
auto child : tree.get_child(
"performance_entry")) {
157 performance_entry = second.get_value<std::string>();
159 for (
auto child : tree.get_child(
"error")) {
160 const std::string value = child.second.get_value<std::string>();
161 if (!value.empty()) {
162 std::cerr <<
"cognitive_record_performance JSON error: " << value << std::endl;
166 catch (boost::property_tree::json_parser::json_parser_error & je) {
167 std::cerr <<
"cognitive_record_performance::handle_reply Error parsing: " << je.filename()
168 <<
" on line: " << je.line() << std::endl;
169 std::cerr << je.message() << std::endl;
196 unsigned int from_time,
197 unsigned int to_time,
198 const std::string test_type,
199 const std::string token,
200 std::function<
void(std::string)> callback
204 boost::property_tree::ptree tree;
205 tree.put(
"from_time", boost::lexical_cast<std::string>(from_time));
206 tree.put(
"to_time", boost::lexical_cast<std::string>(to_time));
207 tree.put(
"test_type", test_type);
208 std::stringstream ss;
209 boost::property_tree::write_json(ss, tree,
false);
211 header_ =
"POST /hop/cognitive_get_history HTTP/1.1\r\n"
212 +
"Content-Type: application/x-www-form-urlencoded\r\n";
246 unsigned int up_to_time,
247 const std::string test_type,
248 const std::string token,
249 std::function<
void(std::vector<unsigned int>,
250 std::vector<float>)> callback
254 boost::property_tree::ptree tree;
255 tree.put(
"up_to_time", boost::lexical_cast<std::string>(from_time));
256 tree.put(
"test_type", test_type);
257 std::stringstream ss;
258 boost::property_tree::write_json(ss, tree,
false);
260 header_ =
"POST /hop/cognitive_get_scores HTTP/1.1\r\n"
261 +
"Content-Type: application/x-www-form-urlencoded\r\n";
271 std::stringstream ss(json);
272 std::vector<unsigned int> test_classes;
273 std::vector<float> scores;
275 boost::property_tree::ptree tree;
276 boost::property_tree::read_json(ss, tree);
278 for (
auto child : tree.get_child(
"test_classes")) {
279 test_classes.push_back(second.get_value<
unsigned int>());
281 for (
auto child : tree.get_child(
"scores")) {
282 scores.push_back(second.get_value<
float>());
284 for (
auto child : tree.get_child(
"error")) {
285 const std::string value = child.second.get_value<std::string>();
286 if (!value.empty()) {
287 std::cerr <<
"cognitive_get_scores JSON error: " << value << std::endl;
291 catch (boost::property_tree::json_parser::json_parser_error & je) {
292 std::cerr <<
"cognitive_get_scores::handle_reply Error parsing: " << je.filename()
293 <<
" on line: " << je.line() << std::endl;
294 std::cerr << je.message() << std::endl;
300 std::function<void(std::vector<unsigned int>,
std::function< void(std::string)> delegate_
std::string header_
Header that will be used.
cognitive_get_scores(unsigned int up_to_time, const std::string test_type, const std::string token, std::function< void(std::vector< unsigned int >, std::vector< float >)> callback)
get cognitive test scores
cognitive_test_selector(const std::string user, const std::string test_type, const std::string token, std::function< void(std::vector< std::string >, std::vector< std::string >, std::vector< std::string >, std::string, std::string, std::string)> callback)
handler obtains a cognitive test from cloud.rapp
std::string post_
Actual post Data.
void handle_reply(std::string json)
forward (don't parse) platform reply
std::function< void(std::vector< std::string >, std::vector< std::string >, std::vector< std::string >, std::string, std::string, std::string)> delegate_
chose a congitive game to play
cognitive_get_history(unsigned int from_time, unsigned int to_time, const std::string test_type, const std::string token, std::function< void(std::string)> callback)
get history of cognitive game
std::function< void(std::vector< unsigned int >, std::vector< float >)> delegate_
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
base class for asynchronous http websockets used for connecting to cloud services ...
void handle_reply(std::string json)
handle platform's JSON reply
void handle_reply(std::string json)
handle platform's JSON reply