29 from CloudMsgs 
import FaceDetection
 
   30 from CloudMsgs 
import QrDetection
 
   31 from CloudMsgs 
import HumanDetection
 
   32 from CloudMsgs 
import HazardDetectionDoor
 
   33 from CloudMsgs 
import HazardDetectionLight
 
   34 from CloudMsgs 
import ObjectRecognitionCaffe
 
   35 from CloudMsgs 
import SetNoiseProfile
 
   36 from CloudMsgs 
import SpeechRecognitionSphinx
 
   37 from CloudMsgs 
import SpeechRecognitionGoogle
 
   38 from CloudMsgs 
import OntologySubclasses
 
   39 from CloudMsgs 
import OntologySuperclasses
 
   40 from CloudMsgs 
import OntologyIsSubsuperclass
 
   41 from CloudMsgs 
import CognitiveExerciseSelect
 
   42 from CloudMsgs 
import CognitiveGetHistory
 
   43 from CloudMsgs 
import CognitiveGetScores
 
   44 from CloudMsgs 
import CognitiveRecordPerformance
 
   45 from CloudMsgs 
import EmailFetch
 
   46 from CloudMsgs 
import EmailSend
 
   47 from CloudMsgs 
import WeatherReportCurrent
 
   48 from CloudMsgs 
import WeatherReportForecast
 
   49 from CloudMsgs 
import PathPlanningPlan2D
 
   50 from CloudMsgs 
import PathPlanningUploadMap
 
   51 from CloudMsgs 
import TextToSpeech
 
   52 from CloudMsgs 
import NewsExplore
 
   53 from CloudMsgs 
import Geolocation
 
   55 from Service 
import RappPlatformService
 
   58     """ RAPP Platform simple API implementation """ 
   63         """! Face detection API service call. 
   65         @type imageFilepath: string 
   66         @param imageFilepath: Path to the image file. 
   69         @param fast: Perform fast detection. If true, detection will take 
   70             less time but it will be less accurate. 
   73         @return: Returns a dictionary of the service call response. 
   74             {'faces': [], 'error': ''} 
   78             msg.req.imageFilepath = imageFilepath
 
   79             response = self.svc_caller.call(msg)
 
   80         except Exception 
as e:
 
   81             response = FaceDetection.Response(error=str(e))
 
   83             'faces': response.faces,
 
   84             'error': response.error
 
   88         """! QR code detection API service call. 
   90         @type imageFilepath: string 
   91         @param imageFilepath: Path to the image file. 
   94         @return: Returns a dictionary of the service call response. 
   95             {'qr_centers': [], 'qr_messages': [], 'error': ''} 
   99             msg.req.imageFilepath = imageFilepath
 
  100             response = self.svc_caller.call(msg)
 
  101         except Exception 
as e:
 
  102             response = QrDetection.Response(error=str(e))
 
  104             'qr_centers': response.qr_centers,
 
  105             'qr_messages': response.qr_messages,
 
  106             'error': response.error
 
  110         """! Human detection API service call. 
  112         @type imageFilepath: string 
  113         @param imageFilepath: Path to the image file. 
  116         @return: Returns a dictionary of the service call response. 
  117             {'humans': [], 'error': ''} 
  120         msg = HumanDetection()
 
  122             msg.req.imageFilepath = imageFilepath
 
  123             response = self.svc_caller.call(msg)
 
  124         except Exception 
as e:
 
  125             response = HumanDetection.Response(error=str(e))
 
  127             'humans': response.humans,
 
  128             'error': response.error
 
  132         """! Hazard detection door check API service call. 
  134         @type imageFilepath: string 
  135         @param imageFilepath: Path to the image file. 
  138         @return: Returns a dictionary of the service call response. 
  139             {'door_angle': 0.0, 'error': ''} 
  141         msg = HazardDetectionDoor()
 
  143             msg.req.imageFilepath = imageFilepath
 
  144             response = self.svc_caller.call(msg)
 
  145         except Exception 
as e:
 
  146             response = HazardDetectionDoor.Response(error=str(e))
 
  148             'door_angle': response.door_angle,\
 
  149             'error': response.error\
 
  153         """! Hazard detection light check API service call. 
  155         @type imageFilepath: string 
  156         @param imageFilepath: Path to the image file. 
  159         @return: Returns a dictionary of the service call response. 
  160             {'light_level': 0, 'error': ''} 
  162         msg = HazardDetectionLight()
 
  164             msg.req.imageFilepath = imageFilepath
 
  165             response = self.svc_caller.call(msg)
 
  166         except Exception 
as e:
 
  167             response = HazardDetectionLight.Response(error=str(e))
 
  169             'light_level': response.light_level,
 
  170             'error': response.error
 
  174         """! Object Recognition Caffe API service call. 
  176         @type imageFilepath: string 
  177         @param imageFilepath: Path to the image file. 
  180         @return: Returns a dictionary of the service call response. 
  181             {'object_class': '', 'error': ''} 
  183         msg = ObjectRecognitionCaffe()
 
  185             msg.req.imageFilepath = imageFilepath
 
  186             response = self.svc_caller.call(msg)
 
  187         except Exception 
as e:
 
  188             response = ObjectRecognitionCaffe.Response(error=str(e))
 
  190             'object_class': response.object_class,
 
  191             'error': response.error
 
  195         """! Set Noise Profile API service call. 
  197         @type audiofile: string 
  198         @param audiofile: Path to the audio file. 
  200         @type audio_source: string 
  201         @param audio_source: Audio source format. e.g. 'nao_wav_1_ch' 
  204         @return: Returns a dictionary of the service call response. 
  207         msg = SetNoiseProfile()
 
  209             msg.req.audiofile = audiofile
 
  210             msg.req.audio_source = audio_source
 
  211             response = self.svc_caller.call(msg)
 
  212         except Exception 
as e:
 
  213             response = SetNoiseProfile.Response(error=str(e))
 
  215             'error': response.error
 
  219                                 sentences=[], grammar=[]):
 
  220         """! Speech recognition Sphinx API service call. 
  222         @type audiofile: string 
  223         @param audiofile: Path to the audio file. 
  225         @type audio_source: string 
  226         @param audio_source: Audio source format. e.g. 'nao_wav_1_ch' 
  228         @type language: string 
  229         @param language: Language to use for speech recognition. 
  232         @param words: To recognize words. 
  234         @type sentences: list 
  235         @param sentences: Under consideration sentences. Same as 
  236             @ref words by default. 
  239         @param grammar: Grammar to use. Defaults to none. 
  242         @return: Returns a dictionary of the service call response. 
  243             {'words': [], 'error': ''} 
  245         msg = SpeechRecognitionSphinx()
 
  247             msg.req.audiofile = audiofile
 
  248             msg.req.audio_source = audio_source
 
  249             msg.req.language = language
 
  250             msg.req.words = words
 
  251             msg.req.sentences = sentences
 
  253                 msg.req.sentences = words
 
  254             msg.req.grammar = grammar
 
  255             response = self.svc_caller.call(msg)
 
  256         except Exception 
as e:
 
  257             response = SpeechRecognitionSphinx.Response(error=str(e))
 
  259             'words': response.words,
 
  260             'error': response.error
 
  264         """! Speech recognition Google API service call. 
  266         @type audiofile: string 
  267         @param audiofile: Path to the audio file. 
  269         @type audio_source: string 
  270         @param audio_source: Audio source format. e.g. 'nao_wav_1_ch' 
  272         @type language: string 
  273         @param language: Language to use for speech recognition. 
  276         @return: Returns a dictionary of the service call response. 
  277             {'words': [], 'alternatives': [], 'error': ''} 
  279         msg = SpeechRecognitionGoogle()
 
  281             msg.req.audiofile = audiofile
 
  282             msg.req.audio_source = audio_source
 
  283             msg.req.language = language
 
  284             response = self.svc_caller.call(msg)
 
  285         except Exception 
as e:
 
  286             response = SpeechRecognitionGoogle.Response(error=str(e))
 
  288             'words': response.words,
 
  289             'alternatives': response.alternatives,
 
  290             'error': response.error
 
  294         """! Ontology subclasses-of API service call. 
  296         @type ontology_class: string 
  297         @param ontology_class: The ontology class. 
  299         @type recursive: bool 
  300         @param recursive: Recursive search. Defaults to False. 
  303         @return: Returns a dictionary of the service call response. 
  304             {'results': [], 'error': ''} 
  306         msg = OntologySubclasses()
 
  308             msg.req.ontology_class = ontology_class
 
  309             msg.req.recursive = recursive
 
  310             response = self.svc_caller.call(msg)
 
  311         except Exception 
as e:
 
  312             response = OntologySubclasses.Response(error=str(e))
 
  314             'results': response.results,
 
  315             'error': response.error
 
  319         """! Ontology superclasses-of API service call. 
  321         @type ontology_class: string 
  322         @param ontology_class: The ontology class. 
  324         @type recursive: bool 
  325         @param recursive: Recursive search. Defaults to False. 
  328         @return: Returns a dictionary of the service call response. 
  329             {'results': [], 'error': ''} 
  331         msg = OntologySuperclasses()
 
  333             msg.req.ontology_class = ontology_class
 
  334             msg.req.recursive = recursive
 
  335             response = self.svc_caller.call(msg)
 
  336         except Exception 
as e:
 
  337             response = OntologySuperclasses.Response(error=str(e))
 
  339             'results': response.results,
 
  340             'error': response.error
 
  344         """! Ontology is-supsuperclass-of API service call. 
  346         @type parent_class: string 
  347         @param parent_class: The ontology parent class name. 
  349         @type child_class: string 
  350         @param child_class: The ontology child class name. 
  352         @type recursive: bool 
  353         @param recursive: Recursive search. Defaults to False. 
  356         @return: Returns a dictionary of the service call response. 
  357             {'result': False, 'error': ''} 
  359         msg = OntologyIsSubsuperclass()
 
  361             msg.req.parent_class = parent_class
 
  362             msg.req.child_class = child_class
 
  363             msg.req.recursive = recursive
 
  364             response = self.svc_caller.call(msg)
 
  365         except Exception 
as e:
 
  366             response = OntologyIsSubsuperclass.Response(error=str(e))
 
  368             'result': response.result,
 
  369             'error': response.error
 
  373                                 test_diff=-1, test_index=-1):
 
  374         """! Cognitive Exercise selection (chooser) API service call. 
  376         @type test_type: string 
  377         @param test_type: Cognitive Exercise test type. Defaults to empty. 
  379         @type test_subtype: string 
  380         @param test_subtype: Force exercise selection from this subtype. 
  384         @param test_diff: Force exercise selection from this difficulty. 
  387         @type test_index: int 
  388         @param test_diff: Force exercise selection from this difficulty. 
  392         @return: Returns a dictionary of the service call response. 
  394         msg = CognitiveExerciseSelect()
 
  396             msg.req.test_type = test_type
 
  397             msg.req.test_subtype = test_subtype
 
  399                 msg.req.test_diff = test_diff
 
  401                 msg.req.test_index = test_index
 
  402             response = self.svc_caller.call(msg)
 
  403         except Exception 
as e:
 
  404             response = CognitiveExerciseSelect.Response(error=str(e))
 
  406             'test_type': response.test_type,
 
  407             'test_subtype': response.test_subtype,
 
  408             'test_instance': response.test_instance,
 
  409             'questions': response.questions,
 
  410             'possib_ans': response.possib_ans,
 
  411             'correct_ans': response.correct_ans,
 
  412             'error': response.error
 
  416         """! Gognitive get history records API service call. 
  418         @type test_type: string 
  419         @param test_type: Cognitive Exercise test type. Defaults to empty. 
  422         @param time_from: Retrieve history records from this timestamp value. 
  423             Unix timestamp. Defaults to zero (0). 
  426         @param time_from: Retrieve history records up to this timestamp value. 
  427             Unix timestamp. Defaults to zero (0). 
  430         @return: Returns a dictionary of the service call response. 
  431             {'records': {}, 'error': ''} 
  433         msg = CognitiveGetHistory()
 
  435             msg.req.test_type = test_type
 
  436             msg.req.time_from = time_from
 
  437             msg.req.time_to = time_to
 
  438             response = self.svc_caller.call(msg)
 
  439         except Exception 
as e:
 
  440             response = CognitiveGetHistory.Response(error=str(e))
 
  442             'records': response.records,
 
  443             'error': response.error
 
  447         """! Gognitive get score records API service call. 
  449         @type test_type: string 
  450         @param test_type: Cognitive Exercise test type. Defaults to empty. 
  453         @param time_from: Retrieve score records up to this timestamp value. 
  454             Unix timestamp. Defaults to zero (0). 
  457         @return: Returns a dictionary of the service call response. 
  458             {'test_classes': [], 'scores': [], 'error': ''} 
  460         msg = CognitiveGetScores()
 
  462             msg.req.test_type = test_type
 
  463             msg.req.time_to = time_to
 
  464             response = self.svc_caller.call(msg)
 
  465         except Exception 
as e:
 
  466             response = CognitiveGetScores.Response(error=str(e))
 
  468             'test_classes': response.test_classes,
 
  469             'scores': response.scores,
 
  470             'error': response.error
 
  474         """! Gognitive record performance of an exercise API service call. 
  476         @type test_instance: string 
  477         @param test_instance: Performed cognitive exercise test instance. 
  478             The full cognitive test entry name as obtained from 
  479             CognitiveExerciseSelect API service call 
  482         @return: Returns a dictionary of the service call response. 
  483             {'performance_entry': '', 'error': ''} 
  485         msg = CognitiveRecordPerformance()
 
  487             msg.req.test_instance = test_instance
 
  488             msg.req.score = score
 
  489             response = self.svc_caller.call(msg)
 
  490         except Exception 
as e:
 
  491             response = CognitiveRecordPerformance.Response(error=str(e))
 
  493             'performance_entry': response.performance_entry,
 
  494             'error': response.error
 
  497     def emailFetch(self, email, password, server, port, date_from, date_to,
 
  498                    email_status=
'UNSEEN', num_emails=1):
 
  499         """! Email fetch API service call. 
  502         @param email: User's email username 
  504         @type password: string 
  505         @param password: User's email password 
  508         @param server: The email provider imap address. 
  511         @param port: The email provider imap port. 
  514         @param date_from: Fetch emails since this timestamp value. 
  518         @param date_to: Fetch emails up to this timestamp value. 
  521         @type email_status: string 
  522         @param email_status: Email status (ALL, UNSEEN). Defaults to 'UNSEEN' 
  524         @type num_emails: int 
  525         @param num_emails: Maximum number of emails to fetch. 
  528         @return: Returns a dictionary of the service call response. 
  529             {'emails': [], 'error': ''} 
  533             msg.req.email = email
 
  534             msg.req.password = password
 
  535             msg.req.server = server
 
  537             msg.req.date_from = date_from
 
  538             msg.req.date_to = date_to
 
  539             msg.req.email_status = email_status
 
  540             msg.req.num_emails = num_emails
 
  541             response = self.svc_caller.call(msg)
 
  542         except Exception 
as e:
 
  543             response = EmailFetch.Response(error=str(e))
 
  545             'emails': response.emails,
 
  546             'error': response.error
 
  549     def emailSend(self, email, password, server, port, recipients, body,
 
  550                   subject, attach_file=
''):
 
  551         """! Email fetch API service call. 
  554         @param email: User's email username 
  556         @type password: string 
  557         @param password: User's email password 
  560         @param server: The email provider imap address. 
  563         @param port: The email provider imap port. 
  565         @type recipients: list 
  566         @param recipients: List of recipients email addresses. 
  569         @param body: The body of the email. 
  571         @type subject: string 
  572         @param subject: The email subject. 
  574         @type attach_file: string 
  575         @param attach_file: Attachment file (path). Attachment file can be a 
  576             .zip file containing multiple attachment files for the email to send 
  579         @return: Returns a dictionary of the service call response. 
  584             msg.req.email = email
 
  585             msg.req.password = password
 
  586             msg.req.server = server
 
  588             msg.req.recipients = recipients
 
  590             msg.req.subject = subject
 
  591             msg.req.attach_file = attach_file
 
  592             response = self.svc_caller.call(msg)
 
  593         except Exception 
as e:
 
  594             response = EmailSend.Response(error=str(e))
 
  596             'error': response.error
 
  601         """! Weather report current API service call 
  604         @param city: City location. 
  606         @type weather_reporter: string 
  607         @param weather_reporter: The weather reporter API to use. 
  608             Defaults to 'forecast.io' 
  611         @param metric: Value units (0:Celcius, 1:Fahrenheit) 
  612             Defaults to 0 (Celcius) 
  615         @return: Returns a dictionary of the service call response. 
  617         msg = WeatherReportCurrent()
 
  620             msg.req.weather_reporter = weather_reporter
 
  621             msg.req.metric = metric
 
  622             response = self.svc_caller.call(msg)
 
  623         except Exception 
as e:
 
  624             response = WeatherReportCurrent.Response(error=str(e))
 
  626             'date': response.date,
 
  627             'temperature': response.temperature,
 
  628             'weather_description': response.weather_description,
 
  629             'humidity': response.humidity,
 
  630             'visibility': response.visibility,
 
  631             'pressure': response.pressure,
 
  632             'wind_speed': response.wind_speed,
 
  633             'wind_temperature': response.wind_temperature,
 
  634             'wind_direction': response.wind_direction,
 
  635             'error': response.error
 
  640         """! Weather report forecast API service call 
  643         @param city: City location. 
  645         @type weather_reporter: string 
  646         @param weather_reporter: The weather reporter API to use. 
  647             Defaults to 'forecast.io' 
  650         @param metric: Value units (0:Celcius, 1:Fahrenheit) 
  651             Defaults to 0 (Celcius) 
  654         @return: Returns a dictionary of the service call response. 
  656         msg = WeatherReportForecast()
 
  659             msg.req.weather_reporter = weather_reporter
 
  660             msg.req.metric = metric
 
  661             response = self.svc_caller.call(msg)
 
  662         except Exception 
as e:
 
  663             response = WeatherReportForecast.Response(error=str(e))
 
  665             'forecast': response.forecast,
 
  666             'error': response.error
 
  670                            pose_goal, algorithm=
'dijkstra'):
 
  671         """! Path planning plan path 2D API service call 
  673         @type map_name: string 
  674         @param map_name: The map name. 
  676         @type robot_type: string 
  677         @param robot_type: The robot type. e.g 'NAO' 
  679         @type pose_start: dict 
  680         @param pose_start: Start pose of the robot. 
  682         @type pose_goal: dict 
  683         @param pose_goal: Goal pose of the robot. 
  685         @type algorithm: string 
  686         @param algorithm: Path planning algorithm to apply. 
  687             Defaults to 'dijkstra' 
  690         @return: Returns a dictionary of the service call response. 
  691             {'plan_found': 0, 'path': [], 'error': ''} 
  694         msg = PathPlanningPlan2D()
 
  696             msg.req.map_name = map_name
 
  697             msg.req.robot_type = robot_type
 
  698             msg.req.algorithm = algorithm
 
  699             msg.req.pose_start = pose_start
 
  700             msg.req.pose_goal = pose_goal
 
  701             response = self.svc_caller.call(msg)
 
  702         except Exception 
as e:
 
  703             response = PathPlanningPlan2D.Response(error=str(e))
 
  705             'plan_found': response.plan_found,
 
  706             'path': response.path,
 
  707             'error': response.error
 
  711         """! Path planning upload map API service call 
  713         @type map_name: string 
  714         @param map_name: The map name 
  716         @type png_file: string 
  717         @param png_file: Path to the map png file 
  719         @type yaml_file: string 
  720         @param yaml_file: Path to the map descriptor yaml file. 
  723         @return: Returns a dictionary of the service call response. 
  726         msg = PathPlanningUploadMap()
 
  728             msg.req.map_name = map_name
 
  729             msg.req.png_file = png_file
 
  730             msg.req.yaml_file = yaml_file
 
  731             response = self.svc_caller.call(msg)
 
  732         except Exception 
as e:
 
  733             response = PathPlanningUploadMap.Response(error=str(e))
 
  735             'error': response.error
 
  739         """! Text to Speech API service call 
  742         @param text: Input text to translate to audio. 
  744         @type language: string 
  745         @param language: Text language. 
  747         @type audio_file: string 
  748         @param audio_file: File path to store the audio data. 
  751         @return: Returns a dictionary of the service call response. 
  757             msg.req.language = language
 
  758             response = self.svc_caller.call(msg)
 
  760             if response.error == 
u"":
 
  761                 response.store_audio(audio_file)
 
  762         except Exception 
as e:
 
  763             response = TextToSpeech.Response(error=str(e))
 
  765             'error': response.error
 
  768     def newsExplore(self, keywords, region='', topic='', news_engine='',
 
  769                     num_news=1, exclude_titles=[]):
 
  770         """! News Explorer API service call 
  773         @param keywords: Desired keywords. 
  776         @param region: language/region 
  779         @param topic: Main topic. e.g. 'sports', 'politics', etc 
  781         @type news_engine: string 
  782         @param news_engine: The news search engine to use. Optional 
  784         @type num_news: string 
  785         @param num_news: Number of news stories to request. 
  787         @type exclude_titles: list 
  788         @param exclude_titles: Exclude these titles 
  791         @return: Returns a dictionary of the service call response. 
  792             {'news_stories': [], 'error': ''} 
  796             msg.req.news_engine = news_engine
 
  797             msg.req.keywords = keywords
 
  798             msg.req.exclude_titles = exclude_titles
 
  799             msg.req.region = region
 
  800             msg.req.topic = topic
 
  801             msg.req.num_news = num_news
 
  802             response = self.svc_caller.call(msg)
 
  803         except Exception 
as e:
 
  804             response = NewsExplore.Response(error=str(e))
 
  806             'news_stories': response.news_stories,
 
  807             'error': response.error
 
  811         """! Geolocation API service call 
  814         @param ipaddr: The machine's ipv4 address. 
  817         @param engine: Engine to use. Defaults to 'ip-api'. 
  820         @return: Returns a dictionary of the service call response. 
  824             msg.req.ipaddr = ipaddr
 
  825             msg.req.engine = engine
 
  826             response = self.svc_caller.call(msg)
 
  827         except Exception 
as e:
 
  828             response = Geolocation.Response(error=str(e))
 
  830             'city': response.city,
 
  831             'country': response.country,
 
  832             'country_code': response.country_code,
 
  833             'latitude': response.latitude,
 
  834             'longtitude': response.longtitude,
 
  835             'region': response.region,
 
  836             'timezone': response.timezone,
 
  838             'error': response.error