<s> import rospy <EOL> import sys <EOL> import calendar <EOL> import time <EOL> from datetime import datetime <EOL> from os . path import expanduser <EOL> from collections import OrderedDict <EOL> from rapp_platform_ros_communications . srv import ( <EOL> createOntologyAliasSrv , <EOL> createOntologyAliasSrvRequest , <EOL> createOntologyAliasSrvResponse , <EOL> recordUserCognitiveTestPerformanceSrv , <EOL> recordUserCognitiveTestPerformanceSrvRequest , <EOL> recordUserCognitiveTestPerformanceSrvResponse , <EOL> recordUserPerformanceCognitiveTestsSrv , <EOL> recordUserPerformanceCognitiveTestsSrvRequest , <EOL> recordUserPerformanceCognitiveTestsSrvResponse <EOL> ) <EOL> from rapp_platform_ros_communications . msg import ( <EOL> StringArrayMsg <EOL> ) <EOL> class RecordUserCognitiveTestPerformance : <EOL> def recordPerformance ( self , req ) : <EOL> try : <EOL> res = recordUserCognitiveTestPerformanceSrvResponse ( ) <EOL> serv_topic = rospy . get_param ( '<STR_LIT>' ) <EOL> knowrob_service = rospy . ServiceProxy ( serv_topic , createOntologyAliasSrv ) <EOL> createOntologyAliasReq = createOntologyAliasSrvRequest ( ) <EOL> createOntologyAliasReq . username = req . username <EOL> createOntologyAliasResponse = knowrob_service ( createOntologyAliasReq ) <EOL> if ( createOntologyAliasResponse . success != True ) : <EOL> res . trace = createOntologyAliasResponse . trace <EOL> res . error = createOntologyAliasResponse . error <EOL> res . success = False <EOL> return res <EOL> serv_topic = rospy . get_param ( '<STR_LIT>' ) <EOL> knowrob_service = rospy . ServiceProxy ( serv_topic , recordUserPerformanceCognitiveTestsSrv ) <EOL> userPerformanceEntry = recordUserPerformanceCognitiveTestsSrvRequest ( ) <EOL> userPerformanceEntry . test = req . test <EOL> userPerformanceEntry . patient_ontology_alias = createOntologyAliasResponse . ontology_alias <EOL> userPerformanceEntry . timestamp = int ( time . time ( ) ) <EOL> userPerformanceEntry . score = req . score <EOL> userPerformanceEntryResponse = knowrob_service ( userPerformanceEntry ) <EOL> if ( userPerformanceEntryResponse . success != True ) : <EOL> res . trace = userPerformanceEntryResponse . trace <EOL> res . trace . append ( "<STR_LIT>" ) <EOL> res . error = userPerformanceEntryResponse . error + "<STR_LIT>" <EOL> res . success = False <EOL> return res <EOL> else : <EOL> res . success = True <EOL> res . userCognitiveTestPerformanceEntry = userPerformanceEntryResponse . cognitive_test_performance_entry <EOL> except IndexError : <EOL> res . trace . append ( "<STR_LIT>" ) <EOL> res . success = False <EOL> except IOError : <EOL> print "<STR_LIT>" <EOL> res . success = False <EOL> res . trace . append ( "<STR_LIT>" ) <EOL> return res </s>
