RAPP Platform  v0.6.0
RAPP Platform is a collection of ROS nodes and back-end processes that aim to deliver ready-to-use generic services to robots
 All Classes Namespaces Files Functions Variables Macros
cognitive_exercise.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- encode: utf-8 -*-
3 
4 #Copyright 2015 RAPP
5 
6 #Licensed under the Apache License, Version 2.0 (the "License");
7 #you may not use this file except in compliance with the License.
8 #You may obtain a copy of the License at
9 
10  #http://www.apache.org/licenses/LICENSE-2.0
11 
12 #Unless required by applicable law or agreed to in writing, software
13 #distributed under the License is distributed on an "AS IS" BASIS,
14 #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #See the License for the specific language governing permissions and
16 #limitations under the License.
17 
18 # Author: Athanassios Kintsakis
19 # contact: akintsakis@issel.ee.auth.gr
20 
21 import rospy
22 from test_selector import TestSelector
23 from recordUserCognitiveTestPerformance import RecordUserCognitiveTestPerformance
24 from cognitive_test_creator import CognitiveTestCreator
25 from userScoresForAllCategories import UserScoresForAllCategories
26 from userScoreHistoryForAllCategories import UserScoreHistoryForAllCategories
27 from returnTestsOfTypeSubtypeDiffuclty import ReturnTests
28 
29 from rapp_platform_ros_communications.srv import (
30  testSelectorSrv,
31  testSelectorSrvResponse,
32  createOntologyAliasSrv,
33  createOntologyAliasSrvRequest,
34  createOntologyAliasSrvResponse,
35  recordUserCognitiveTestPerformanceSrv,
36  recordUserCognitiveTestPerformanceSrvResponse,
37  cognitiveTestCreatorSrv,
38  cognitiveTestCreatorSrvResponse,
39  userScoreHistoryForAllCategoriesSrv,
40  userScoreHistoryForAllCategoriesSrvResponse,
41  userScoresForAllCategoriesSrv,
42  userScoresForAllCategoriesSrvResponse,
43  returnTestsOfTypeSubtypeDifficultySrv,
44  returnTestsOfTypeSubtypeDifficultySrvResponse
45  )
46 
47 ## @class CognitiveExercise
48 # @brief The Cognitive exercise ros node
50 
51  ## @brief Default contructor
52  #
53  # Waits for services the node depends on and declares the callbacks of the node's services
54  def __init__(self):
55 
56  # Dependencies
57  self.serv_topic = rospy.get_param('rapp_knowrob_wrapper_create_ontology_alias')
58  if(not self.serv_topic):
59  rospy.logerror("rapp_knowrob_wrapper_create_ontology_alias param not found")
60  rospy.wait_for_service(self.serv_topic)
61 
62  self.serv_topic = rospy.get_param('rapp_mysql_wrapper_get_user_language_service_topic')
63  if(not self.serv_topic):
64  rospy.logerror("rapp_mysql_wrapper_get_user_language_service_topic param not found")
65  rospy.wait_for_service(self.serv_topic)
66 
67  self.serv_topic = rospy.get_param('rapp_knowrob_wrapper_user_performance_cognitve_tests')
68  if(not self.serv_topic):
69  rospy.logerror("rapp_knowrob_wrapper_user_performance_cognitve_tests topic not foud")
70  rospy.wait_for_service(self.serv_topic)
71 
72  serv_topic = rospy.get_param('rapp_knowrob_wrapper_cognitive_tests_of_type')
73  if(not serv_topic):
74  rospy.logerror("rapp_knowrob_wrapper_cognitive_tests_of_type not found")
75  rospy.wait_for_service(self.serv_topic)
76 
77  serv_topic = rospy.get_param('rapp_knowrob_wrapper_record_user_cognitive_tests_performance')
78  if(not serv_topic):
79  rospy.logerror("rapp_knowrob_wrapper_record_user_cognitive_tests_performance not found")
80  rospy.wait_for_service(serv_topic)
81 
82  serv_topic = rospy.get_param('rapp_knowrob_wrapper_create_cognitve_tests')
83  if(not serv_topic):
84  rospy.logerror("rapp_knowrob_wrapper_create_cognitve_tests not found")
85  rospy.wait_for_service(serv_topic)
86 
87  #Declare Callbacks
88  self.serv_topic = rospy.get_param("rapp_cognitive_exercise_chooser_topic")
89  if(not self.serv_topic):
90  rospy.logerror("rapp_cognitive_exercise_chooser_topic not found")
91  self.serv=rospy.Service(self.serv_topic, testSelectorSrv, self.chooserDataHandler)
92 
93  self.serv_topic = rospy.get_param("rapp_cognitive_exercise_record_user_cognitive_test_performance_topic")
94  if(not self.serv_topic):
95  rospy.logerror("rapp_cognitive_exercise_record_user_cognitive_test_performance_topic not found")
96  self.serv=rospy.Service(self.serv_topic, recordUserCognitiveTestPerformanceSrv, self.recordUserCognitiveTestPerformanceDataHandler)
97 
98  self.serv_topic = rospy.get_param("rapp_cognitive_test_creator_topic")
99  if(not self.serv_topic):
100  rospy.logerror("rapp_cognitive_test_creator_topic not found")
101  self.serv=rospy.Service(self.serv_topic, cognitiveTestCreatorSrv, self.cognitiveTestCreatorDataHandler)
102 
103  self.serv_topic = rospy.get_param("rapp_cognitive_exercise_user_all_categories_score_topic")
104  if(not self.serv_topic):
105  rospy.logerror("rapp_cognitive_exercise_user_all_categories_score_topic not found")
106  self.serv=rospy.Service(self.serv_topic, userScoresForAllCategoriesSrv, self.userScoresForAllCategoriesDataHandler)
107 
108  self.serv_topic = rospy.get_param("rapp_cognitive_exercise_user_all_categories_history_topic")
109  if(not self.serv_topic):
110  rospy.logerror("rapp_cognitive_exercise_user_all_categories_history_topic not found")
111  self.serv=rospy.Service(self.serv_topic, userScoreHistoryForAllCategoriesSrv, self.userScoreHistoryForAllCategoriesDataHandler)
112 
113  self.serv_topic = rospy.get_param("rapp_cognitive_exercise_return_tests_of_type_subtype_difficulty_topic")
114  if(not self.serv_topic):
115  rospy.logerror("rapp_cognitive_exercise_return_tests_of_type_subtype_difficulty_topic not found")
116  self.serv=rospy.Service(self.serv_topic, returnTestsOfTypeSubtypeDifficultySrv, self.returnTestsOfTypeSubtypeDifficultyDataHandler)
117 
118 
119 
120  ## @brief The cognitive exercise chooser service callback
121  # @param req [rapp_platform_ros_communications::testSelectorSrvRequest::Request&] The ROS service request
122  # @return res [rapp_platform_ros_communications::testSelectorSrvResponse::Response&] The ROS service response
123  def chooserDataHandler(self,req):
124  res = testSelectorSrvResponse()
125  it = TestSelector()
126  res=it.chooserFunction(req)
127  return res
128 
129  ## @brief The record user cognitive test performance service callback
130  # @param req [rapp_platform_ros_communications::recordUserCognitiveTestPerformanceSrvRequest::Request&] The ROS service request
131  # @return res [rapp_platform_ros_communications::recordUserCognitiveTestPerformanceSrvResponse::Response&] The ROS service response
133  res = recordUserCognitiveTestPerformanceSrvResponse()
134  it = RecordUserCognitiveTestPerformance()
135  res=it.recordPerformance(req)
136  return res
137 
138  ## @brief The cognitive test creator service callback
139  # @param req [rapp_platform_ros_communications::cognitiveTestCreatorSrvRequest::Request&] The ROS service request
140  # @return res [rapp_platform_ros_communications::cognitiveTestCreatorSrvResponse::Response&] The ROS service response
142  res = cognitiveTestCreatorSrvResponse()
143  it = CognitiveTestCreator()
144  res=it.testCreator(req)
145  return res
146 
147  ## @brief The userScoresForAllCategories service callback
148  # @param req [rapp_platform_ros_communications::userScoresForAllCategoriesSrvRequest::Request&] The ROS service request
149  # @return res [rapp_platform_ros_communications::userScoresForAllCategoriesSrvResponse::Response&] The ROS service response
151  res = userScoresForAllCategoriesSrvResponse()
153  res=it.returnUserScores(req)
154  return res
155 
156  ## @brief The userScoreHistoryForAllCategories service callback
157  # @param req [rapp_platform_ros_communications::userScoreHistoryForAllCategoriesSrv::Request&] The ROS service request
158  # @return res [rapp_platform_ros_communications::userScoreHistoryForAllCategoriesSrv::Response&] The ROS service response
160  res = userScoreHistoryForAllCategoriesSrvResponse()
162  res=it.returnUserHistory(req)
163  return res
164 
165  ## @brief The returnTestsOfTypeSubtypeDifficultyDataHandler service callback
166  # @param req [rapp_platform_ros_communications::returnTestsOfTypeSubtypeDifficultyDataHandler::Request&] The ROS service request
167  # @return res [rapp_platform_ros_communications::returnTestsOfTypeSubtypeDifficultyDataHandler::Response&] The ROS service response
169  res = returnTestsOfTypeSubtypeDifficultySrvResponse()
170  it = ReturnTests()
171  res=it.returnTestsFunction(req)
172  return res
def cognitiveTestCreatorDataHandler
The cognitive test creator service callback.
Provides the necessary functions for returning the user scores.
def returnTestsOfTypeSubtypeDifficultyDataHandler
The returnTestsOfTypeSubtypeDifficultyDataHandler service callback.
def chooserDataHandler
The cognitive exercise chooser service callback.
def recordUserCognitiveTestPerformanceDataHandler
The record user cognitive test performance service callback.
def userScoreHistoryForAllCategoriesDataHandler
The userScoreHistoryForAllCategories service callback.
Provides the necessary functions for returning the history of user scores.
def userScoresForAllCategoriesDataHandler
The userScoresForAllCategories service callback.
The Cognitive exercise ros node.