def testVariablesSmooth(self): o1 = OOCSI() ov1 = o1.variable('variableChannel', 'testVarS') o2 = OOCSI() ov2 = o2.variable('variableChannel', 'testVarS').smooth(2) # check default self.assertEquals(ov1.get(), ov2.get()) ov1.set(10) ov1.set(20) time.sleep(0.5) self.assertEquals(20, ov1.get()) self.assertEquals(15, ov2.get()) ov1.set(10) time.sleep(0.1) ov1.set(10) time.sleep(0.1) ov1.set(10) time.sleep(0.1) self.assertEquals(10, ov1.get()) self.assertEquals(10, ov2.get()) o1.stop() o2.stop()
def testVariablesSmoothSigma1(self): o1 = OOCSI() ov11 = o1.variable('variableChannel', 'testVarSS11').smooth(2, 1) ov12 = o1.variable('variableChannel', 'testVarSS12').smooth(2, 2) o2 = OOCSI() ov21 = o2.variable('variableChannel', 'testVarSS11').smooth(2, 1) ov22 = o2.variable('variableChannel', 'testVarSS12').smooth(2, 2) # check default self.assertEquals(ov11.get(), ov21.get()) ov11.set(1) time.sleep(0.1) ov11.set(2) time.sleep(0.1) ov12.set(1) time.sleep(0.1) ov12.set(2) time.sleep(0.1) self.assertEquals(1.5, ov21.get()) self.assertEquals(1.5, ov22.get()) # move up a lot ov21.set(10.2) time.sleep(0.1) ov22.set(10.2) time.sleep(0.1) self.assertEquals(2, ov11.get()) self.assertTrue(ov11.get() < ov12.get()) # do it again ov21.set(10.2) time.sleep(0.1) ov21.set(10.2) time.sleep(0.1) self.assertEquals(2.625, ov11.get()) ov21.set(-10.2) time.sleep(0.1) ov21.set(10.2) time.sleep(0.1) self.assertEquals(2.53125, ov11.get()) o1.stop() o2.stop()
def testVariablesSmoothSigma2(self): o1 = OOCSI() ov1 = o1.variable('variableChannel', 'testVarSS2') o2 = OOCSI() ov2 = o2.variable('variableChannel', 'testVarSS2').smooth(2, 1) # check default self.assertEquals(ov1.get(), ov2.get()) ov1.set(10) ov1.set(20) time.sleep(0.1) self.assertEquals(20, ov1.get()) # should be half sigma self.assertEquals(10.5, ov2.get()) # do it again print(ov1.value) print(ov2.values) ov1.set(20) time.sleep(0.1) print(ov1.value) print(ov2.values) self.assertEquals(20, ov1.get()) # should be half sigma ((10 + 11)/2 + 0.5) # only because the first "mean" will be calculated by division of 1 self.assertEquals(11, ov2.get()) ov1.set(10) time.sleep(0.1) ov1.set(10) time.sleep(0.1) ov1.set(10) time.sleep(0.1) self.assertEquals(10, ov1.get()) self.assertEquals(10, ov2.get()) o1.stop() o2.stop()
def testVariablesBasic(self): o1 = OOCSI() ov1 = o1.variable('variableChannel', 'testVar') o2 = OOCSI() ov2 = o2.variable('variableChannel', 'testVar') # check default self.assertEquals(ov1.get(), ov2.get()) ov1.set(10) time.sleep(0.5) self.assertEquals(ov1.get(), ov2.get()) o1.stop() o2.stop()
def testVariablesMinMax(self): o1 = OOCSI() ov1 = o1.variable('variableChannel', 'testVarMM').min(2).max(5) o2 = OOCSI() ov2 = o2.variable('variableChannel', 'testVarMM').min(3).max(6) # check default self.assertEquals(2, ov1.get()) self.assertEquals(3, ov2.get()) ov1.set(10) time.sleep(0.5) self.assertEquals(5, ov1.get()) self.assertEquals(6, ov2.get()) o1.stop() o2.stop()
def testDirectCommunication(self): eventSink = [] def receiveEvent(sender, recipient, event): eventSink.append(event) o1 = OOCSI(handle='testclient1', callback=receiveEvent) o2 = OOCSI() message = {} message['color'] = int(400) message['position'] = int(255) o2.send('testclient1', message) time.sleep(0.5) self.assertEquals(1, len(eventSink)) o1.stop() o2.stop()
def testChannelCommunicationBurst(self): eventSink = [] eventSink2 = [] def receiveEvent(sender, recipient, event): eventSink.append(event) def receiveEvent2(sender, recipient, event): eventSink2.append(event) o11 = OOCSI() o11.subscribe('testchannel', receiveEvent) o11.subscribe('OOCSI_events', receiveEvent2) o12 = OOCSI() o12.subscribe('testchannel', receiveEvent) o12.subscribe('OOCSI_events', receiveEvent2) o13 = OOCSI() o13.subscribe('testchannel', receiveEvent) o13.subscribe('OOCSI_events', receiveEvent2) o2 = OOCSI() message = {} message['burst'] = int(400) o2.send('testchannel', message) time.sleep(0.5) self.assertEquals(3, len(eventSink2)) self.assertEquals(3, len(eventSink)) o11.stop() o12.stop() o13.stop() o2.stop()
def test_call_response(self): def respondToEvent(response): # set data field in the response response['newColor'] = int(response['oldColor']) + 1 # start responder OOCSI client # responder = OOCSI('callResponseResponder', 'localhost') responder = OOCSI() # register responder responder.register('colorChannel', 'colorGenerator', respondToEvent) ### test colorGenerator with two calls # start caller OOCSI client #caller = OOCSI('callResponseSender', 'localhost') caller = OOCSI() self.assertTrue(caller.connected) # asynchronous call call1 = caller.call('colorChannel', 'colorGenerator', {'oldColor': 9}, 1) # wait for 500 ms time.sleep(0.5) self.assertEqual(10, call1['response']['newColor']) # blocking call call2 = caller.callAndWait('colorChannel', 'colorGenerator', {'oldColor': 19}, 1) self.assertEqual(20, call2['response']['newColor']) caller.stop() responder.stop()
def testChannelCommunication(self): eventSink = [] def receiveEvent(sender, recipient, event): eventSink.append(event) o1 = OOCSI() o1.subscribe('testchannel', receiveEvent) o2 = OOCSI() message = {} message['color'] = int(400) message['position'] = int(255) o2.send('testchannel', message) time.sleep(0.5) self.assertEquals(1, len(eventSink)) o1.stop() o2.stop()
for i, j in zip(a, b): if i == j: count = count+ i #print(count) #print(e, df_rec['recipe_name'].loc[e], count) if count>0: # print (df_rec['recipe_name'].loc[e], df_rec["family_favorites"].loc[e]) if (df_rec['family_favorites'].loc[e] ==1): #print(df_rec['recipe_name'].loc[e]) #print (df_rec['recipe_name'].loc[e], count) df_famfav =df_famfav.append({'recept': df_rec['recipe_name'].loc[e]}, ignore_index=True) # connect to OOCSI running on a webserver oocsi = OOCSI('Your_Unique_Handler', "oocsi.id.tue.nl") ing = oocsi.variable('RecipeRecommender', 'ingredients') filterVar = oocsi.variable('RecipeRecommender', 'filter') oldFilter= filterVar.get() filterVar.set("popular") ing.set('garlic') v1= ing.get() v1= ing.get() while True: if (v1 != ing.get()) or filterVar.get() != oldFilter: if filterVar.get() == "popular": pos_recipes(ing.get()) print(df_recipes['recept'][:10])
def __init__(self, strModuleName, strNaoIp): try: super(SpeechRecognitionModule, self).__init__("SpeechRecognition") naoqi.ALModule.__init__(self, strModuleName) # is these 2 line necessary? what do they do? # just copied them from the examples... self.BIND_PYTHON(self.getName(), "callback") self.strNaoIp = strNaoIp # declare event to ALMemory so other modules can subscribe self.memory = naoqi.ALProxy("ALMemory") #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ self.tts = ALProxy("ALTextToSpeech", self.strNaoIp, 9559) self.memory.subscribeToEvent( "ALTextToSpeech/Status", "SpeechRecognition", # module instance "on_tts_status") # callback name self.speaking = False #OOCSI initialize self.o = OOCSI('PEPPER', 'oocsi.id.tue.nl') #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ self.memory.declareEvent("SpeechRecognition") # flag to indicate if subscribed to audio events self.isStarted = False # flag to indicate if we are currently recording audio self.isRecording = False self.startRecordingTimestamp = 0 self.recordingDuration = RECORDING_DURATION # flag to indicate if auto speech detection is enabled self.isAutoDetectionEnabled = False self.autoDetectionThreshold = 10 # TODO: find a default value that works fine so we don't need to calibrate every time # flag to indicate if we are calibrating self.isCalibrating = False self.startCalibrationTimestamp = 0 # RMS calculation variables self.framesCount = 0 self.rmsSum = 0 # used to sum up rms results and calculate average self.lastTimeRMSPeak = 0 # audio buffer self.buffer = [] self.preBuffer = [] self.preBufferLength = 0 # length in samples (len(self.preBuffer) just counts entries) # init parameters self.language = DEFAULT_LANGUAGE self.idleReleaseTime = IDLE_RELEASE_TIME self.holdTime = HOLD_TIME self.lookaheadBufferSize = LOOKAHEAD_DURATION * SAMPLE_RATE # counter for wav file output self.fileCounter = 0 except BaseException, err: print("ERR: SpeechRecognitionModule: loading error: %s" % str(err))
#! /usr/bin/python3 from oocsi import OOCSI import sys if len(sys.argv) < 4: print("Usage:", sys.argv[0], "<channel> <message key> <message value>") exit() oocsi_inst = OOCSI('Testerinator', 'oocsi.id.tue.nl') message = {sys.argv[2] : sys.argv[3]} #message['weight'] = 666 oocsi_inst.send(sys.argv[1], message) oocsi_inst.stop()
# Copyright (c) 2017-2022 Mathias Funk # This software is released under the MIT License. # http://opensource.org/licenses/mit-license.php from oocsi import OOCSI def receiveEvent(sender, recipient, event): print('from ', sender, ' -> ', event) o = OOCSI('testreceiver', 'localhost', callback=receiveEvent)
# Copyright (c) 2017-2022 Mathias Funk # This software is released under the MIT License. # http://opensource.org/licenses/mit-license.php from oocsi import OOCSI import time from random import random o = OOCSI('testsender', 'localhost') while 1: message = {} message['color'] = int(random() * 400) message['position'] = int(random() * 255) o.send('testchannel', message) # wait and continue time.sleep(1)
#! /usr/bin/python3 from oocsi import OOCSI import sys if len(sys.argv) < 2: print('usage:', sys.argv[0], '<channel>') exit() oocsi = OOCSI('Testerinator', 'oocsi.id.tue.nl') def printMessage(sender, recipient, event): print('from', sender, '->', event) for channel in sys.argv[1:]: oocsi.subscribe(channel, printMessage)
# Copyright (c) 2017-2022 Mathias Funk # This software is released under the MIT License. # http://opensource.org/licenses/mit-license.php from oocsi import OOCSI import time from random import random # oocsiConnection o = OOCSI('testHeyOOCSI', 'localhost') # create OOCSIDevice ----------------------------------------------------------------------------- # default name for device = the client name "testHeyOOCSI" device = o.heyOOCSI() # alternative: named device (for multiple digital oocsiDevices): # device = o.heyOOCSI("my_first_device") # add example for location device.addLocation("kitchen") # create entities for the device: # a sensor with name, channel, type, unit and default value 100 device.addSensor("sensor_name", "sensor_channel", "sensor_type", "sensor_unit", 100) # a binary sensor with name, channel, type, default value, and icon name device.addBinarySensor("binary_sensor_name", "sensor_channel2", "sensor_type", False, "binary_icon") # a switch with name, channel, default value and icon name device.addSwitch("switch_name", "switch_channel", False, "switch_icon")
def main(): hours = int(time.strftime('%H')) # Section 1: Title st.title('Affective Foreteller') st.subheader('What is your name?') # Participant's randomly assigned identifier which will show in the app interface nickname = st.selectbox( 'Select your nickname.', ('--', 'Alex', 'Ben', 'Chris', 'Don', 'Eddie', 'Fem', 'Greta', 'Hans', 'Iris', 'Jon', 'Kim', 'Leo', 'Mark', 'Nora', 'Oz', 'Paul', 'Quinn', 'Roy', 'Sam', 'Tom')) if nickname != '--': st.write('Hello', nickname, '!') # Section 2: Mood selection st.subheader('How are you feeling right now?') mood_option = st.radio( 'Select an option of words that best describe your mood.', ('Excited, elated, ebullient', 'Happy, pleased, content', 'Calm, serene, tranquil', 'Tense, nervous, upset', 'Miserable, unhappy, discontent', 'Depressed, bored, lethargic') ) # Section 3: Additional question selection if hours in range(5, 11): # morning question st.subheader('How many hours did you sleep last night?') sleep_time = st.slider( label='', min_value=0.0, max_value=16.0, step=0.5, format='%1f' ) food_options = 'food_options' activity_options = 'activity_options' elif hours in range(11, 17): # afternoon question st.subheader('What was your last meal?') food_options = st.text_input('Type or use emojis to describe what you ate.', value='', max_chars=50) sleep_time = 'sleep_time' activity_options = 'activity_options' else: # evening question st.subheader('What were your activities today?') activity_options = st.multiselect( 'You can select multiple options.', ['⚽ sport️', '🧘️ meditation', '🎼 music', '🎨 hobbies', '🚗 commute', '📱 apps', '🛏 rest', '🛍 shopping', '📚 read', '💻 work', '🍽 meals', '🍻 drinks']) sleep_time = 'sleep_time' food_options = 'food_options' # send data to oocsi def send_data(): oocsi.send('Affective_Foretell_Self_Report', { 'name': nickname, 'mood': mood_option, 'sleep': sleep_time, 'food': food_options, 'activities':activity_options}) if st.button('Submit'): if nickname == '--': st.write('Please select your nickname.') else: st.write('Thank you for your submission!') oocsi = OOCSI('Affective_Foretell', 'oocsi.id.tue.nl') oocsi.subscribe('Affective_Foretell_Self_Report', send_data()) oocsi.stop() st.balloons()
# Copyright (c) 2017-2022 Mathias Funk # This software is released under the MIT License. # http://opensource.org/licenses/mit-license.php from oocsi import OOCSI import time from random import random o = OOCSI('testsender', 'localhost') while 1: message = {} message['color'] = int(random() * 400) message['position'] = int(random() * 255) o.send('testreceiver', message) print('to ', 'testreceiver', ' -> ', message) # wait and continue time.sleep(1)
Replace the input from participants by Raspberry Pi with DHT11 module References: https://data.id.tue.nl/documentation/usecase-ded-2 Platform: Raspberry Pi 3b Language: Python Module(s): DHT11 """ import sys import Adafruit_DHT import time import datetime from oocsi import OOCSI # connect to OOCSI # replace the 'unique_handler_name' as something unique # OOCSI host for the Data Foundry: oocsi.id.tue.nl oocsi = OOCSI('unique_handler_name', 'url_or_host_or_ip_address') mins = 0 arr = [] def sendLog(humidity, temperature): """ Send humidity and temperature to DataFoundry via OOCSI every 10 records and send notification to researchers by telegramBOt every 6 messages """ current = datetime.datetime.now() global mins if mins == 60: sendMsg = True
# This software is released under the MIT License. # http://opensource.org/licenses/mit-license.php import time from oocsi import OOCSI def respondToEvent(response): # set data field in the response response['newColor'] = int(response['oldColor']) + 1 # play with this delay to let the caller time out # time.sleep(4) # start responder OOCSI client # responder = OOCSI('callResponseResponder', 'localhost') responder = OOCSI() print(responder.handle) # register responder responder.register('colorChannel', 'colorGenerator', respondToEvent) ### test colorGenerator with two calls # start caller OOCSI client #caller = OOCSI('callResponseSender', 'localhost') caller = OOCSI() print(caller.handle) # asynchronous call call1 = caller.call('colorChannel', 'colorGenerator', {'oldColor': 9}, 1)
# Copyright (c) 2017-2022 Mathias Funk # This software is released under the MIT License. # http://opensource.org/licenses/mit-license.php from oocsi import OOCSI # use this function to change how the log output is printed # you can also switch logging off by providing a function that does not do anything def logFunction(msg): print('custom log: ' + msg) # initialize OOCSI connection with a custom logger oocsi = OOCSI('python_custom_logger', 'localhost', logger=logFunction)
from oocsi import OOCSI from NAO_Speak import NAO_Speak # (file name followed by class name) import unidecode ################################# IP = "IP_OF_PEPPER_ROBOT" text = "" my_nao = NAO_Speak(IP, 9559) ################################## def receiveEvent(sender, recipient, event): print('from ', sender, ' -> ', event) # this will convert unicode string to plain string msg = str(event['message']) sender = str(sender) x, y = sender.split('_') if x == 'webclient': my_nao.say_text(msg) if __name__ == "__main__": #o = OOCSI('abc', "oocsi.id.tue.nl", callback=receiveEvent) o = OOCSI('pepper_receiver', 'oocsi.id.tue.nl') o.subscribe('__test123__', receiveEvent)
#! /usr/bin/python3 from oocsi import OOCSI import sys if len(sys.argv) < 2: print('usage:', sys.argv[0], '<channel>') exit() oocsi = OOCSI('Testerinator', 'oocsi.id.tue.nl') def printMessage(sender, recipient, event): print('from', sender, '->', event) oocsi.subscribe(sys.argv[1], printMessage)
# Copyright (c) 2017-2022 Mathias Funk # This software is released under the MIT License. # http://opensource.org/licenses/mit-license.php from oocsi import OOCSI # use this function to change how the log output is printed # you can also switch logging off by providing a function that does not do anything def logFunction(msg): print('custom log: ' + msg) # initialize OOCSI connection with a custom logger oocsi = OOCSI('python_limited_reconnection_attempts', 'localhost', maxReconnectionAttempts=10)
# Copyright (c) 2017-2022 Mathias Funk # This software is released under the MIT License. # http://opensource.org/licenses/mit-license.php from oocsi import OOCSI import time # start responder OOCSI client responder = OOCSI('variable1', 'localhost') # create variable 'color' for first client v1 = responder.variable('colorChannel', 'color') # start caller OOCSI client caller = OOCSI('variable2', 'localhost') # create variable 'color' for second client v2 = caller.variable('colorChannel', 'color') # assign an int v1.set(100) print('value of first variable: ', v1.get()) time.sleep(0.1) print('value of second variable: ', v2.get()) # assign a float v2.set(200.1) print('value of second variable: ', v2.get()) time.sleep(0.1)
#! /usr/bin/python3 from oocsi import OOCSI from OOCSIListener import Listener from EventHandlers import * #from PressureSensor.pressure_sensor import PressureSensorThread from storage_state import StorageUnitState from cuttingboard_state import CuttingBoardState import time import RecipeStuff import command_thread as cmd # Obtain oocsi instance and connect to remote server oocsi = OOCSI('SmartStorageUnit', 'oocsi.id.tue.nl') # Initialize the global state global_state = StorageUnitState(oocsi) # Initialize the cuttingboard state cutting_board_state = CuttingBoardState() evt = EventHandler(global_state, cutting_board_state, None) # Dictionary of which channels to receive on and their event handlers receiver_channels = { 'cuttingVolumeChannel': evt.onCuttingVolume, 'soundSpectrumChannel': evt.onSoundSpectrum, 'boardWeightChannel': evt.onBoardWeight, 'cuttingSpeedChannel': evt.onCuttingSpeed, 'recipeChannel': evt.onRecipe }
# Copyright (c) 2017-2022 Mathias Funk # This software is released under the MIT License. # http://opensource.org/licenses/mit-license.php from oocsi import OOCSI def receiveEvent(sender, recipient, event): print('from ', sender, ' -> ', event) o = OOCSI('testreceiver', 'localhost') o.subscribe('testchannel', receiveEvent)