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 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 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()
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()
#! /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()
### 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) # wait for 1 sec time.sleep(1) # check response in call object if 'response' in call1: print(call1['response']) else: print('response not found') # blocking call call2 = caller.callAndWait('colorChannel', 'colorGenerator', {'oldColor': 19}, 1) # check response in call object directly if 'response' in call2: print(call2['response']) else: print('response not found') caller.stop() responder.stop()
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()
family_recipes(ing.get()) print(df_famfav['recept'][:10]) message = {} if len(df_famfav['recept']) >10: for i in range(10): try: message['Recipe'+ str(i)] = df_famfav['recept'].loc[i] except: print("No recipes") else: for i in range(len(df_famfav['recept'])): message['Recipe'+ str(i)] = df_famfav['recept'].loc[i] oocsi.send('RecipeRecommender', message) # print(ing.get(), df_recipes['recept'].loc[0]) v1= ing.get() oldFilter= filterVar.get() time.sleep(1) try: if keyboard.is_pressed('esc'): oocsi.stop() break except: break