def __init__(self, topic): # setting up a tree with participants for testing, for a topic lkh = LKH() topic = Topic(topic, type_of_pub_sub_group=TypeOfPubSubGroupEnum.SOME_PUBSUB_SOME_PUB_SOME_SUB.value) participant1 = Participant(nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE), "001") participant1_sibling = Participant(nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE), "001s") participant2 = Participant(nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE), "002") participant3 = Participant(nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE), "003") pub_tree_size = {'no_of_children': 2, 'depth': 3, 'tree_type': 'pub'} sub_tree_size = {'no_of_children': 2, 'depth': 3, 'tree_type': 'sub'} pub_sub_tree_size = {'no_of_children': 2, 'depth': 3, 'tree_type': 'pub_sub'} tree_sizes = [pub_tree_size, sub_tree_size, pub_sub_tree_size] participants_permissions2 = [(participant1, 1), (participant2, 2), (participant3, 3), (participant1_sibling, 1)] KeyManager.setup_topic_trees(topic, participants_permissions2, tree_sizes) # trees generated successfully here # # print(RenderTree(topic.root_tree_publishers)) self.topic = topic
def __init__(self, topic, permission): # assuming registration process gives the following data done # -- think -- send participant id to registration process? # initialzing trees here testKeyManagerTopic = TestKeyManagerTopic("topic1") reg_data = Registration.register(topic) self.participant_id = reg_data[1] self.pairwise_key = reg_data[0] self.permission = permission initial_topic_anc = reg_data[3] initial_topic = reg_data[2] # make pairwise_key global for now, later save on a file or db # subscribing to the topic # first connect to broker, this should be done before # since its test we connect here client = paho.Client(userdata={'pairwise_key': self.pairwise_key}) client.connect("iot.eclipse.org") # connection done # now subscribe to initial topic client.on_subscribe = on_subscribe client.on_message = on_message client.subscribe(topic=initial_topic, qos=1) client.subscribe(topic=initial_topic_anc, qos=1) # callbacks for special subscriptions on initial topic client.message_callback_add(initial_topic, on_testing_initial_topic) client.message_callback_add(initial_topic_anc, on_testing_initial_topic_anc) client.loop_start() time.sleep(5) # ideally registration protocol should add clients to GCKS, # since this is test we call add client here client_participant = Participant(self.pairwise_key, self.participant_id) testKeyManagerTopic.add_client(client_participant, self.permission, initial_topic, initial_topic_anc) # time.sleep(10) # testKeyManagerTopic.add_client(client_participant, self.permission, initial_topic, initial_topic_anc) participant4 = Participant( nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE), "004") time.sleep(15) testKeyManagerTopic.add_client(participant4, 3, "testTopic", "testTopicAnc") # client.loop_forever() while True: time.sleep(1)
def buy_asset(self, manufacturer, main_queue, BREAK_ASSET_MANUALY_GPIO, service, GPIO_to_repair_for_demo): #global EMERGENCY self.Asset=Operator.readRFID(service, self,manufacturer.Catalog, main_queue, manufacturer, BREAK_ASSET_MANUALY_GPIO, main_queue, GPIO_to_repair_for_demo) print "bought "+str(self.Asset.RFID_Identifier) print str(manufacturer.Bulletin_at_manufacturers_campus) self.Asset_is_working=True self.Asset_not_on_RFID=0 #check if the asset is already boosted if GPIO.input(self.Pimp_GPIO)==0: print "setting pimped" self.Asset.Pimped=True Participant.asset_bought(self.Asset) #Participant.stop_blinking(blinker_Queue) GPIO.output(self.Service_Bulletin_GPIO_out, GPIO.LOW)
def get_inputs(self): """Gets user input for number of players and names of players.""" players = input("Enter the number of players: ") self.num_players = int(players) # If num players less than 3 if self.num_players < 3: print(players) print("Not enough players. Please enter 3-12.") self.get_inputs() # If num players more than 12 elif self.num_players > 12: print(players) print("That's too many players. Please enter 3-12.") self.get_inputs() else: # Loop through number of players for player in range(self.num_players): player += 1 # Input name for each player name = input(f"Player {player}'s Name: ") # Add participant to participants list self.participants.append(Participant(name))
def tree_from_json(json_tree): # write code to construct a tree from json data # create topic topic = None # first loop create all nodes and map ids to nodes id_to_node = {} for node in json_tree["node_details"]: if node["leaf_node"] == "false": if node["parent"] is None: tree_node = TreeNode(node["node_id"]) children_tree_node = Node(json_tree["topic"], tree_node=tree_node) id_to_node[node["node_id"]] = children_tree_node else: tree_node = TreeNode(node["node_id"]) children_tree_node = Node(node["node_id"], tree_node=tree_node) id_to_node[node["node_id"]] = children_tree_node else: if node["participant"] is None: leaf_node = LeafNode(node["node_id"]) children_tree_node = Node("empty", leaf_node=leaf_node) id_to_node[node["node_id"]] = children_tree_node else: participant = Participant( node["participant"]["pairwise_key"], node["participant"]["participant_id"]) leaf_node = LeafNode(node["node_id"], participant=participant) children_tree_node = Node(participant.participant_id, leaf_node=leaf_node) id_to_node[node["node_id"]] = children_tree_node participant.add_topic(json_tree["topic"]) parent_node = None for node in json_tree["node_details"]: if node["parent"] is None: id_to_node[node["node_id"]].parent = None parent_node = id_to_node[node["node_id"]] topic = Topic(json_tree["topic"], json_tree["tree_depth"], json_tree["tree_no_of_children"], root_node=parent_node) else: id_to_node[node["node_id"]].parent = id_to_node[node["parent"]] return parent_node, id_to_node
def make_bet_participant_OD(bet_data_name_list): candidate_participant_dict = {"Sanders": "Bart", "Warren": "Fransje", "Harris": "Koen", "Biden": "Rob"} b_P_OD = OD() for cnt, item in enumerate(sorted(candidate_participant_dict.items(), key=lambda x: bet_data_name_list.index(x[0]))): bet_prediction, name = item p = Participant(name, cnt) bp = BetParticipant(p, bet_prediction, 1) b_P_OD[name] = bp return b_P_OD
def make_part_list(qest_data, neded_keys=None): # qest_data = True flag = True part_list = {} scen_list = [] # ScenariosRader.scen_read("ScenariosFiles", "procData2", sourse_dir, 20, 20, 10, 20) uniqe_id = make_id_list("ParsedData") for files in listdir("ScenariosFiles2"): name_list = files scen_list.append(name_list) res = {} data = pandas.read_csv("ParsedData/" + files + ".csv") lst_len = data['out'].unique().shape[0] for un in uniqe_id: if flag: part_list[un] = Participant([], [], []) res[un] = {} # for con in data['con'].unique(): # res[un][con] = [0] * lst_len if flag: flag = False for i in range(data.shape[0]): if data['con'].ix[i] not in res[data['id'].ix[i]]: res[data['id'].ix[i]][data['con'].ix[i]] = [0] * lst_len res[data['id'].ix[i]][data['con'].ix[i]][data['out'].ix[i]] += 1 for key in res: part_list[key].add_scenario(res[key], name_list, lst_len) for key in part_list: part_list[key].normolise() quest_names = [] if qest_data: driver_data = pandas.read_csv("questionnaireData/preQuestionnaire.csv", index_col=0) quest_names = driver_data.drop(columns=['ID']).columns.values.tolist() driver_data = driver_data.fillna(0) driver_data = driver_data.replace({'gender': r'^[f|F].*'}, {'gender': 1}, regex=True) driver_data = driver_data.replace({'gender': r'^[m|M].*'}, {'gender': 2}, regex=True) driver_data = driver_data.replace({'gender': r'^h.*'}, {'gender': 0}, regex=True) for key in part_list: id_data = driver_data[driver_data.ID == key] id_data = id_data.drop(columns=['ID']) dct = id_data.to_dict(orient='index') dct = dct[dct.keys()[0]] need_val = {} if neded_keys: for n_key in neded_keys: need_val[n_key] = dct[n_key] part_list[key].set_data(need_val) else: part_list[key].set_data(dct) return {'data': part_list, 'scen': scen_list, 'quest': quest_names}
def __init__(self,topic): super(Subscriber,self).__init__() self.topic = topic self.participant = Participant.getInstance(topic.domainID,topic.participantID) self.receiveDataHandler=None self.filters = [] self.listeners = set() self.messageCallbacks = set() self.started = False
def repare_Asset(self, operator, service, manufacturer): if not operator.Asset is None: operator.Asset.Broken=False operator.Asset.set_next_break() operator.Asset_is_working=True Participant.stop_blinking(service.Blinker_queue) Participant.stop_blinking(operator.Blinker_queue) Participant.stop_blinking(manufacturer.Blinker_queue) #Participant.update_event(5) #Participant.speak("Service", "Congratulations, you repaired the Asset!") #update the time for the next break Participant.update_event(5)
def repare_Asset(self, operator, service, manufacturer): if not operator.Asset is None: operator.Asset.Broken = False operator.Asset.set_next_break() operator.Asset_is_working = True Participant.stop_blinking(service.Blinker_queue) Participant.stop_blinking(operator.Blinker_queue) Participant.stop_blinking(manufacturer.Blinker_queue) #Participant.update_event(5) #Participant.speak("Service", "Congratulations, you repaired the Asset!") #update the time for the next break Participant.update_event(5)
def addParticipant(self,ParticipantID): self.participant = shelve.open(self.ConfigPath['prefix']+self.ConfigPath['DB']+'/ParticipantDB') if not str(ParticipantID) in self.participant: self.participant[str(ParticipantID)] = Participant(str(ParticipantID),self.ConfigPath) self.participant.close() return True else: self.participant.close() return False
def importCSV(): people = {} path = os.getcwd()[0:-7] + 'matchdata' os.chdir(path) bignames = [] littlenames = [] otherfields = 5 with open('BigLittleQuestionnaire.csv') as csvfile: spamreader = csv.reader(csvfile, delimiter=',', quotechar='"') first = True for row in spamreader: if first: for elem in row[otherfields:]: if "If you're a little" in elem: bigname = elem[elem.index('[') + 1:elem.index(']')] bignames.append(bigname) if bigname not in people: people[bigname] = Participant(bigname) people[bigname].status = 'b' else: littlename = elem[elem.index('[') + 1:elem.index(']')] littlenames.append(littlename) if littlename not in people: people[littlename] = Participant(littlename) people[littlename].status = 'l' first = False else: name = None start = None end = None if row[1] == 'Big': name = row[2] start = otherfields end = otherfields + len(littlenames) arr = littlenames elif row[1] == 'Little': name = row[3] start = otherfields + len(littlenames) end = start + len(bignames) arr = bignames for i, elem in enumerate(row[start:end]): if elem != '': rank = int(elem[0]) people[name].add_preference(people[arr[i]], rank) return people
def unpimp_the_pump(self, service): self.Asset.Pimped=False Participant.update_event(7, self.Asset.RFID_Identifier) GPIO.output(service.GPIO_out, GPIO.HIGH) time.sleep(5) GPIO.output(service.GPIO_out, GPIO.LOW)
import json import os from utility import * from Participant import Participant from Message import Message participants = {} directory_prefix = "messages/" for file in os.listdir(directory_prefix): data = json.load(open(directory_prefix + file)) for participant in data["participants"]: name = participant["name"] generate_key(participants, name, Participant(name)) for message in data["messages"]: message = Message(message) participant = participants[message.sender] participant.parse_message(message) # y = -7643.51549 + 28.3723533 * x participants["Maheen Hoque"].noOfCharacters = 213746 for k, v in sorted(participants.items(), key=lambda p: p[1].calculate_points(), reverse=True): print(v.calculate_points()) v.pretty_print() print()
def pimp_the_pump(self): self.Asset.Pimped=True Participant.update_event(6, self.Asset.RFID_Identifier)
] if __name__ == "__main__": n = 2 # number of initiators m = 10 # number of participants i = 4 # number of items each initiator will buy participants_names = [] participants = [] initiators = [] # Create participants for j in range(m): name = "participant" + str(j) + "@localhost" participants_names.append(name) agent = Participant(random.choice(possible_items), name, "123") participants.append(agent) agent.start() # Create initiators for j in range(n): name = "initiator" + str(j) + "@localhost" agent = Initiator(name, "123") agent.possible_items = possible_items agent.list_of_sellers = participants_names agent.i = i initiators.append(agent) agent.start() while True: in_progress = False
def main(a, queue): try: import multiprocessing import threading from Webserver import WebSocketHandler from Webserver import MainHandler from Participant import Participant from Bulletin import Bulletin from Operator import Operator from Service import Service from Manufacturer import Manufacturer import Pump import time import json import datetime import RPi.GPIO as GPIO from PIL import Image import pygame from multiprocessing import Process, Queue import signal from random import randint import RFID GPIO.setmode(GPIO.BOARD) # CONSTANTS PIMP_GPIO = 13 #gpio 27 OUT_MANUFACTURER = 11 #gpio 17 OUT_SERVICE = 33 #gpio 13 ALARM_MANUFACTURER = 16 # gpio 23 ALARM_OPERATOR = 7 #gpio 4 ALARM_SERVICE = 38 #gpio 20 REPAIR_ASSET_GPIO = 40 # gpio 21 BREAK_ASSET_MANUALY_GPIO = 18 #gpio 24 SERVICE_BULLETIN_MANUFACTURER = 31 #gpio 6v SERVICE_BULLETIN_MANUFACTURER_MEASURE = 35 #gpio 19 SERVICE_BULLETIN_OPERATOR = 12 #gpio 18 SERVICE_BULLETIN_OPERATOR_MEASURRE = 15 #gpio 22 GPIO_to_repair_for_demo=40 # gpio 21 # CATALOG OF RFID CHIPS' IDs THAT ARE ASSIGNED TO THE ASSETS IN THE FRONEND CATALOG = { 215: {'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO}, 216: {'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO}, 98: {'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO}, 209: {'id': 209, 'repairGPIO': REPAIR_ASSET_GPIO}, 133: {'id': 133, 'repairGPIO': REPAIR_ASSET_GPIO} } GPIO.setup(GPIO_to_repair_for_demo, GPIO.IN) # CREATING PARTICIPANTS OBJECTS Manufacturer = Manufacturer(OUT_MANUFACTURER, service_bulletin_out=SERVICE_BULLETIN_MANUFACTURER, service_bullete_measure=SERVICE_BULLETIN_MANUFACTURER_MEASURE, alarm_out=ALARM_MANUFACTURER, bulletin=Bulletin(), catalog=CATALOG) Service = Service(OUT_SERVICE, alarm_out=ALARM_SERVICE) Operator = Operator(service_bulletin_out=SERVICE_BULLETIN_OPERATOR, service_bullete_measure=SERVICE_BULLETIN_OPERATOR_MEASURRE, alarm_out=ALARM_OPERATOR, pimp_gpio=PIMP_GPIO) # SETTING ALL OUTPUTS TO LOW GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.ALARM_out, GPIO.LOW) GPIO.output(Operator.ALARM_out, GPIO.LOW) GPIO.output(Service.ALARM_out, GPIO.LOW) global ASSET_INSTALLED ASSET_INSTALLED = True #variable for the emergency handling, if the pump is not discovered #global EMERGENCY ############################ ##SERVICE CAR HANDLING HELP-VARIABLES## #informed_to_remove_the_service_car = False ################################## GPIO.setup(BREAK_ASSET_MANUALY_GPIO, GPIO.IN) get_alife(Manufacturer.GPIO_out, Service.GPIO_out, Operator.Service_Bulletin_GPIO_out, BREAK_ASSET_MANUALY_GPIO) Participant.update_event(0) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) Operator.buy_asset(Manufacturer, queue, BREAK_ASSET_MANUALY_GPIO, Service, GPIO_to_repair_for_demo) while queue.empty(): # CHECKING IF THE ASSET IS ON THE RFID READER if not __builtin__.EMERGENCY: Operator.check_asset() #for the emergency case if __builtin__.EMERGENCY and not __builtin__.operator_connected: Participant.update_event(15) # IF NO ASSET ON THE RFID READER00 if not Operator.Has_asset and ASSET_INSTALLED: print "No Asset" if not Operator.User_informed_about_recent_update: Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer = False Manufacturer.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_MANUFACTURER, GPIO.LOW) Manufacturer.Next_asset_update = 0 GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Service.GPIO_out, GPIO.LOW) # ASSET_INSTALLED=False #Operator.Asset.Next_Pimp = 0 Operator.Asset.Next_Break = 0 GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) Participant.update_event(1) Operator.buy_asset(Manufacturer, queue, BREAK_ASSET_MANUALY_GPIO, Service, GPIO_to_repair_for_demo) ##BULLETIN HANDLING### #Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer=True when the bulletin has been activated by the manufacturer (first blinking after start) #Manufacturer.Bulletin.Activated_for_the_communication=True when the bulletin is installed on the operator's side for the first time if Operator.Has_asset and ASSET_INSTALLED and not Operator.Asset.Broken: #Next_asset_update is 0 only after the start of the demo if not Manufacturer.Next_asset_update == 0: #one time bulletin activation at the manufacturer's site for the furthere communication if datetime.datetime.now() > Manufacturer.Next_asset_update and not Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and __builtin__.operator_connected: GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) if GPIO.input(Manufacturer.Service_Bulletin_GPIO_Measure) == 0: Participant.update_event(9) print "setting blletin true" Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer = True Manufacturer.Bulletin_at_manufacturers_campus = True Manufacturer.bulletin_start_blinking(queue) else: #inform user to put the service bulletin to the manufacturer's site first to load the agreements Participant.update_event(14) else: #first update over the service bulletin after the demo has started Manufacturer.set_next_asset_update_time(22) #returning the activated bulletin to the manufacturer's site only causes the bulletin to blink signaling that it should be brought back to the operator's #if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input(Manufacturer.Service_Bulletin_GPIO_Measure) == 0 and not Manufacturer.Bulletin_at_manufacturers_campus: # Manufacturer.bulletin_start_blinking(queue) # Manufacturer.Bulletin_at_manufacturers_campus = True #Stoping blinking of the blue lamp at operator's site # Operator.bulletin_stop_blinking() if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input(Manufacturer.Service_Bulletin_GPIO_Measure) == 0 and __builtin__.operator_connected: if not Manufacturer.Blinker_queue_bulletin.empty() or Manufacturer.Blinker_queue_bulletin==None: Manufacturer.bulletin_start_blinking(queue) Manufacturer.Bulletin_at_manufacturers_campus = True if not Operator.Blinker_queue_bulletin==None and Operator.Blinker_queue_bulletin.empty: Operator.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_OPERATOR, GPIO.LOW) #The moment the bulleting is plugged of the manufacturer's site if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input(Manufacturer.Service_Bulletin_GPIO_Measure) == 1 and Manufacturer.Bulletin_at_manufacturers_campus and __builtin__.operator_connected: Manufacturer.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_MANUFACTURER, GPIO.LOW) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) Manufacturer.Bulletin_at_manufacturers_campus = False #start blinking operator Operator.bulletin_start_blinking(queue) if not Manufacturer.Next_asset_update == 0: if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input( Manufacturer.Service_Bulletin_GPIO_Measure) == 1 and GPIO.input(Operator.Service_Bulletin_GPIO_Measure)==0 and not Manufacturer.Bulletin_at_manufacturers_campus and __builtin__.operator_connected: Manufacturer.Bulletin.Activated_for_the_communication=True if Operator.Blinker_queue_bulletin.empty() and not Operator.Blinker_queue_bulletin is None: #Stoping blinking of the blue lamp at operator's site Operator.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_OPERATOR, GPIO.LOW) #when the service bulletin is intalled on the operator's site the updates are intalled periodically if datetime.datetime.now() > Manufacturer.Next_asset_update: print "Informing" if not Operator.User_informed_about_recent_update: # Informing user about the service bulletin functionality only once at the beggining of the demo Participant.update_event(4) Operator.User_informed_about_recent_update = True # install bulletin first time Operator.bulletin_stop_blinking() GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) time.sleep(4) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) Manufacturer.set_next_asset_update_time() #Operator.install_bulletin(Manufacturer) #Operator.Asset.set_next_break() else: Manufacturer.inform_operator_about_Update(Operator) ##END BULLETIN HANDLING### # ASSET BREAK #MANUAL BREAK # can be issued by the presenter any time after the serice bulletin is installed by pressing the dedicated button if not Operator.Asset.Broken and __builtin__.operator_connected: #print Operator.Asset.broken_asset_security if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 0: Operator.Asset.broken_asset_security = Operator.Asset.broken_asset_security + 1 if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 1: Operator.Asset.broken_asset_security = 0 if Operator.Asset.broken_asset_security > 3: Operator.Asset.broken_asset_security = 0 Operator.Asset_is_working = False #RANDOM BREAK - happens once when the power pack and pump are installed, bulletin is activated if Operator.Asset.Pimped and Operator.Has_asset and ASSET_INSTALLED and not Operator.Asset.Broken and Manufacturer.Bulletin.Activated_for_the_communication and __builtin__.operator_connected: # can happen only after the standard scenario is completed - after the booting part is installed if Operator.Asset.First_time_random_break: if Operator.Asset.Next_Break == 0: Operator.Asset.set_next_break() if not Operator.Asset.Next_Break == 0: if datetime.datetime.now() > Operator.Asset.Next_Break and Operator.Asset_is_working and not Operator.Asset.Broken and Operator.Has_asset: print "not working" Operator.Asset.First_time_random_break=False Operator.Asset_is_working = False if not Operator.Asset_is_working and not Operator.Asset.Broken and __builtin__.operator_connected: Participant.handle_break(Service, Manufacturer, Operator, queue) # END ASSET BREAK ##HANDLING THE SERVICE CAR AND REPAIRING THE ASSET# Participant.handle_reparing(Operator, Service, Manufacturer,GPIO_to_repair_for_demo) ### END HANDLING THE SERVICE CAR AND REPAIRING THE ASSET## ####HANDLING ASSET BOOSTING if ASSET_INSTALLED and not Operator.Asset.Broken and Operator.Has_asset and __builtin__.operator_connected: print Operator.Asset.pimping if GPIO.input(Operator.Pimp_GPIO) == 0 and Operator.Asset.pimping < 5: Operator.Asset.pimping += 1 if GPIO.input(Operator.Pimp_GPIO) == 1 and Operator.Asset.pimping > 0: Operator.Asset.pimping -= 1 # remind to pimp the asset if not Manufacturer.Bulletin_at_manufacturers_campus and GPIO.input( Operator.Service_Bulletin_GPIO_Measure) == 0 and not Operator.Asset.Pimped and Manufacturer.Bulletin.Activated_for_the_communication and Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer: if Operator.Asset.Next_Pimp == 0 and Manufacturer.Bulletin.Activated_for_the_communication: # FIRST REMINDER print "setting next pimp" print str(Manufacturer.Bulletin.Activated_for_the_communication) Operator.Asset.set_next_pimp_reminder(seconds_=8) else: if datetime.datetime.now() > Operator.Asset.Next_Pimp: # REMINDER EVENT print ("updating event 10") Participant.update_event(10) GPIO.output(Service.GPIO_out, GPIO.HIGH) Operator.Asset.set_next_pimp_reminder() ##BOOSTING THE ASSET # if pimping>4 and not Operator.Asset.Pimped and not INFORMED_BULLETIN: if Operator.Asset.pimping == 5 and not Operator.Asset.Pimped: Operator.pimp_the_pump() GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) GPIO.output(Service.GPIO_out, GPIO.HIGH) time.sleep(10) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Service.GPIO_out, GPIO.LOW) if Operator.Asset.pimping ==0 and Operator.Asset.Pimped and not Operator.Asset.Broken and Operator.Has_asset: Operator.unpimp_the_pump(Service) Operator.Asset.Next_Break = 0 Operator.Asset.set_next_pimp_reminder() ##END BOOSTING THE ASSET print "stoped" except KeyboardInterrupt: # here you put any code you want to run before the program # exits when pressing CTRL+C GPIO.cleanup() http_server.stop()
from Participant import Participant from availability import * from createTimeSlots import * # create new participants interv = Participant('Backend', "Philip", a1) inter2 = Participant('Backend', "Sarah", a2, a3) candidate = Participant('Backend', "Carl", a4, a5) candidate2 = Participant('Backend', "Carl2", a4, a5) # concat all the participants in one list participants = [interv, candidate, inter2] # call get_interview_slots function print(get_interview_slots(participants))
def test_calculate_empty_hand(self): hand = Participant() self.assertEqual(0, hand.calculate_hand())
def test_calculate_ace_card_in_hand(self): hand = Participant() hand._Participant__hand.append(self.ace_card) self.assertEqual(11, hand.calculate_hand())
def test_calculate_four_aces_in_hand(self): hand = Participant() for i in range(1, 5): hand._Participant__hand.append(self.ace_card) self.assertEqual(14, hand.calculate_hand())
def test_calculate_number_card_in_hand(self): hand = Participant() hand._Participant__hand.append(self.number_card) self.assertEqual(self.number_card.get_value(), hand.calculate_hand())
def test_calculate_face_card_queen_in_hand(self): hand = Participant() hand._Participant__hand.append(self.queen_card) self.assertEqual(10, hand.calculate_hand())
def __init__(self, coins): """Create player with some coins.""" Participant.__init__(self) self.__money = coins
# & what is the topic to subscribe to get direct messages from GCKS # for simplicity lets assume its participant ID here # example participant1 needs to subscribe to topic 001 - in order to receive direct messages from GCKS # GCKS publishes to 001 encrypts payload with pairwise key (12345) # on receiving message participant1 decrypts with pairwise key (12345) # this is used to send data such as what topics to subscribe to get key updates # also send key of the first parent # setting up a tree with participants for testing, for a topic lkh = LKH() topic = Topic("test", type_of_pub_sub_group=TypeOfPubSubGroupEnum. SOME_PUBSUB_SOME_PUB_SOME_SUB.value) participant1 = Participant("12345", "001") participant1_sibling = Participant("12345s", "001s") participant2 = Participant("123456", "002") participant3 = Participant("123457", "003") pub_tree_size = {'no_of_children': 2, 'depth': 3, 'tree_type': 'pub'} sub_tree_size = {'no_of_children': 2, 'depth': 3, 'tree_type': 'sub'} pub_sub_tree_size = {'no_of_children': 2, 'depth': 3, 'tree_type': 'pub_sub'} tree_sizes = [pub_tree_size, sub_tree_size, pub_sub_tree_size] participants_permissions2 = [(participant1, 1), (participant2, 2), (participant3, 3), (participant1_sibling, 1)] KeyManager.setup_topic_trees(topic, participants_permissions2, tree_sizes) # trees generated successfully here
import socket from Participant import Participant import pickle from Server.GroupController.GroupController import GroupController HOST = '127.0.0.1' # The server's hostname or IP address PORT = 65431 # The port used by the server with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) participant4 = Participant("12345", "004") s.sendall(pickle.dumps(participant4)) data = b"" while True: packet = s.recv(4096) if not packet: break data += packet print('Received', pickle.loads(data).group_keys) print('bye')
def readRFID(service, operator, catalog, main_queue, manufacturer, BREAK_ASSET_MANUALY_GPIO, queue, GPIO_to_repair_for_demo): #global EMERGENCY broken_asset_security=0 broken=False event_updated=False switch_to_event_0=datetime.datetime.now()+datetime.timedelta(seconds=10) #global util global rdr rdr=RFID.RFID() Asset=None last_uid=0 #util = rdr.util() while not operator.Has_asset: while True and main_queue.empty(): #Demonstrate the asset break even if there is no asset #print broken_asset_security if not broken and __builtin__.operator_connected: print broken_asset_security if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 0: broken_asset_security = broken_asset_security + 1 if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 1: broken_asset_security = 0 if broken_asset_security > 3: broken_asset_security = 0 broken=True Participant.handle_break(service, manufacturer, operator, queue) if broken: broken=Participant.handle_reparing(operator, service, manufacturer, GPIO_to_repair_for_demo) print broken if not broken: #to return to the event 0 switch_to_event_0=datetime.datetime.now()+datetime.timedelta(seconds=10) event_updated=False if __builtin__.EMERGENCY and __builtin__.operator_connected: print "Emergency Buy" Asset=Operator.emergancy_asset(GPIO_to_repair_for_demo) operator.Has_asset=True break break if __builtin__.EMERGENCY and not __builtin__.operator_connected: Participant.update_event(15) break break if not switch_to_event_0==0: if datetime.datetime.now()>switch_to_event_0 and not event_updated and not broken: event_updated=True GPIO.output(manufacturer.GPIO_out, GPIO.LOW) GPIO.output(operator.Service_Bulletin_GPIO_out, GPIO.HIGH) Participant.update_event(0) manufacturer.Bulletin.Activated_for_communication=False manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer = False print "bulletin "+ str(manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer) if not operator.Asset ==None: operator.Asset.Next_Pimp =0 try: manufacturer.Next_asset_update = 0 finally: operator.User_informed_about_recent_update=False switch_to_event_0=0 (error, tag_type) = rdr.request() if not error and not broken: #print "Tag detected" (error, uid) = rdr.anticoll() if not error: #print "UID: " + str(uid[1]) try: asset=catalog[uid[1]] Asset=Pump.Pump(rfid_identifier=asset['id'], gpio_in_to_repair=asset['repairGPIO']) GPIO.output(manufacturer.GPIO_out, GPIO.LOW) operator.Has_asset=True except KeyError, e: if not uid[1]==last_uid: print "The asset is not in the manufacturer's catalog, please try another asset" last_uid=uid[1] break
def test_calculate_hand_with_different_cards(self): hand = Participant() hand._Participant__hand.append(self.ace_card) hand._Participant__hand.append(self.number_card) hand._Participant__hand.append(self.queen_card) self.assertEqual(21, hand.calculate_hand())
from Topic import Topic from Group import Group from anytree.exporter import JsonExporter from TreeNode import TreeNode from anytree import Node, RenderTree, findall_by_attr, findall, Resolver from CustomEnums import TypeOfPubSubGroupEnum, PermissionTypesEnum from PubSubKeyManagerTreeType import KeyManager test_lkh = LKH() from KeyManagerGKMP import KeyManagerGKMP import math #test_tree = test_lkh.setup_tree_no_participants(3, 2, "test")[0] #print(findall_by_attr(test_tree, "3")[0].tree_node.node_key) #print(RenderTree(test_tree)) participant1 = Participant("12345", "001") participant2 = Participant("12345", "002") participant3 = Participant("12345", "003") #participant5 = Participant("12345", "003") participants = [participant1, participant2, participant3] # print(type(participants)) # print(type(participant3)) # dict_test = {participant1: participants, # participant2: participants} # print(dict_test) participants_permissions = [(participant1, 3), (participant2, 3), (participant3, 3)] # tree sizes
def main(a, queue): try: import multiprocessing import threading from Webserver import WebSocketHandler from Webserver import MainHandler from Participant import Participant from Bulletin import Bulletin from Operator import Operator from Service import Service from Manufacturer import Manufacturer import Pump import time import json import datetime import RPi.GPIO as GPIO from PIL import Image import pygame from multiprocessing import Process, Queue import signal from random import randint import RFID GPIO.setmode(GPIO.BOARD) # CONSTANTS PIMP_GPIO = 13 #gpio 27 OUT_MANUFACTURER = 11 #gpio 17 OUT_SERVICE = 33 #gpio 13 ALARM_MANUFACTURER = 16 # gpio 23 ALARM_OPERATOR = 7 #gpio 4 ALARM_SERVICE = 38 #gpio 20 REPAIR_ASSET_GPIO = 40 # gpio 21 BREAK_ASSET_MANUALY_GPIO = 18 #gpio 24 SERVICE_BULLETIN_MANUFACTURER = 31 #gpio 6v SERVICE_BULLETIN_MANUFACTURER_MEASURE = 35 #gpio 19 SERVICE_BULLETIN_OPERATOR = 12 #gpio 18 SERVICE_BULLETIN_OPERATOR_MEASURRE = 15 #gpio 22 GPIO_to_repair_for_demo = 40 # gpio 21 # CATALOG OF RFID CHIPS' IDs THAT ARE ASSIGNED TO THE ASSETS IN THE FRONEND CATALOG = { 215: { 'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO }, 216: { 'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO }, 98: { 'id': 215, 'repairGPIO': REPAIR_ASSET_GPIO }, 209: { 'id': 209, 'repairGPIO': REPAIR_ASSET_GPIO }, 133: { 'id': 133, 'repairGPIO': REPAIR_ASSET_GPIO } } GPIO.setup(GPIO_to_repair_for_demo, GPIO.IN) # CREATING PARTICIPANTS OBJECTS Manufacturer = Manufacturer( OUT_MANUFACTURER, service_bulletin_out=SERVICE_BULLETIN_MANUFACTURER, service_bullete_measure=SERVICE_BULLETIN_MANUFACTURER_MEASURE, alarm_out=ALARM_MANUFACTURER, bulletin=Bulletin(), catalog=CATALOG) Service = Service(OUT_SERVICE, alarm_out=ALARM_SERVICE) Operator = Operator( service_bulletin_out=SERVICE_BULLETIN_OPERATOR, service_bullete_measure=SERVICE_BULLETIN_OPERATOR_MEASURRE, alarm_out=ALARM_OPERATOR, pimp_gpio=PIMP_GPIO) # SETTING ALL OUTPUTS TO LOW GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.ALARM_out, GPIO.LOW) GPIO.output(Operator.ALARM_out, GPIO.LOW) GPIO.output(Service.ALARM_out, GPIO.LOW) global ASSET_INSTALLED ASSET_INSTALLED = True #variable for the emergency handling, if the pump is not discovered #global EMERGENCY ############################ ##SERVICE CAR HANDLING HELP-VARIABLES## #informed_to_remove_the_service_car = False ################################## GPIO.setup(BREAK_ASSET_MANUALY_GPIO, GPIO.IN) get_alife(Manufacturer.GPIO_out, Service.GPIO_out, Operator.Service_Bulletin_GPIO_out, BREAK_ASSET_MANUALY_GPIO) Participant.update_event(0) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) Operator.buy_asset(Manufacturer, queue, BREAK_ASSET_MANUALY_GPIO, Service, GPIO_to_repair_for_demo) while queue.empty(): # CHECKING IF THE ASSET IS ON THE RFID READER if not __builtin__.EMERGENCY: Operator.check_asset() #for the emergency case if __builtin__.EMERGENCY and not __builtin__.operator_connected: Participant.update_event(15) # IF NO ASSET ON THE RFID READER00 if not Operator.Has_asset and ASSET_INSTALLED: print "No Asset" if not Operator.User_informed_about_recent_update: Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer = False Manufacturer.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_MANUFACTURER, GPIO.LOW) Manufacturer.Next_asset_update = 0 GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Service.GPIO_out, GPIO.LOW) # ASSET_INSTALLED=False #Operator.Asset.Next_Pimp = 0 Operator.Asset.Next_Break = 0 GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) Participant.update_event(1) Operator.buy_asset(Manufacturer, queue, BREAK_ASSET_MANUALY_GPIO, Service, GPIO_to_repair_for_demo) ##BULLETIN HANDLING### #Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer=True when the bulletin has been activated by the manufacturer (first blinking after start) #Manufacturer.Bulletin.Activated_for_the_communication=True when the bulletin is installed on the operator's side for the first time if Operator.Has_asset and ASSET_INSTALLED and not Operator.Asset.Broken: #Next_asset_update is 0 only after the start of the demo if not Manufacturer.Next_asset_update == 0: #one time bulletin activation at the manufacturer's site for the furthere communication if datetime.datetime.now( ) > Manufacturer.Next_asset_update and not Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and __builtin__.operator_connected: GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) if GPIO.input(Manufacturer. Service_Bulletin_GPIO_Measure) == 0: Participant.update_event(9) print "setting blletin true" Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer = True Manufacturer.Bulletin_at_manufacturers_campus = True Manufacturer.bulletin_start_blinking(queue) else: #inform user to put the service bulletin to the manufacturer's site first to load the agreements Participant.update_event(14) else: #first update over the service bulletin after the demo has started Manufacturer.set_next_asset_update_time(22) #returning the activated bulletin to the manufacturer's site only causes the bulletin to blink signaling that it should be brought back to the operator's #if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input(Manufacturer.Service_Bulletin_GPIO_Measure) == 0 and not Manufacturer.Bulletin_at_manufacturers_campus: # Manufacturer.bulletin_start_blinking(queue) # Manufacturer.Bulletin_at_manufacturers_campus = True #Stoping blinking of the blue lamp at operator's site # Operator.bulletin_stop_blinking() if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input( Manufacturer.Service_Bulletin_GPIO_Measure ) == 0 and __builtin__.operator_connected: if not Manufacturer.Blinker_queue_bulletin.empty( ) or Manufacturer.Blinker_queue_bulletin == None: Manufacturer.bulletin_start_blinking(queue) Manufacturer.Bulletin_at_manufacturers_campus = True if not Operator.Blinker_queue_bulletin == None and Operator.Blinker_queue_bulletin.empty: Operator.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_OPERATOR, GPIO.LOW) #The moment the bulleting is plugged of the manufacturer's site if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input( Manufacturer.Service_Bulletin_GPIO_Measure ) == 1 and Manufacturer.Bulletin_at_manufacturers_campus and __builtin__.operator_connected: Manufacturer.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_MANUFACTURER, GPIO.LOW) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) Manufacturer.Bulletin_at_manufacturers_campus = False #start blinking operator Operator.bulletin_start_blinking(queue) if not Manufacturer.Next_asset_update == 0: if Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer and GPIO.input( Manufacturer.Service_Bulletin_GPIO_Measure ) == 1 and GPIO.input( Operator.Service_Bulletin_GPIO_Measure ) == 0 and not Manufacturer.Bulletin_at_manufacturers_campus and __builtin__.operator_connected: Manufacturer.Bulletin.Activated_for_the_communication = True if Operator.Blinker_queue_bulletin.empty( ) and not Operator.Blinker_queue_bulletin is None: #Stoping blinking of the blue lamp at operator's site Operator.bulletin_stop_blinking() GPIO.output(SERVICE_BULLETIN_OPERATOR, GPIO.LOW) #when the service bulletin is intalled on the operator's site the updates are intalled periodically if datetime.datetime.now( ) > Manufacturer.Next_asset_update: print "Informing" if not Operator.User_informed_about_recent_update: # Informing user about the service bulletin functionality only once at the beggining of the demo Participant.update_event(4) Operator.User_informed_about_recent_update = True # install bulletin first time Operator.bulletin_stop_blinking() GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) time.sleep(4) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) Manufacturer.set_next_asset_update_time() #Operator.install_bulletin(Manufacturer) #Operator.Asset.set_next_break() else: Manufacturer.inform_operator_about_Update( Operator) ##END BULLETIN HANDLING### # ASSET BREAK #MANUAL BREAK # can be issued by the presenter any time after the serice bulletin is installed by pressing the dedicated button if not Operator.Asset.Broken and __builtin__.operator_connected: #print Operator.Asset.broken_asset_security if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 0: Operator.Asset.broken_asset_security = Operator.Asset.broken_asset_security + 1 if GPIO.input(BREAK_ASSET_MANUALY_GPIO) == 1: Operator.Asset.broken_asset_security = 0 if Operator.Asset.broken_asset_security > 3: Operator.Asset.broken_asset_security = 0 Operator.Asset_is_working = False #RANDOM BREAK - happens once when the power pack and pump are installed, bulletin is activated if Operator.Asset.Pimped and Operator.Has_asset and ASSET_INSTALLED and not Operator.Asset.Broken and Manufacturer.Bulletin.Activated_for_the_communication and __builtin__.operator_connected: # can happen only after the standard scenario is completed - after the booting part is installed if Operator.Asset.First_time_random_break: if Operator.Asset.Next_Break == 0: Operator.Asset.set_next_break() if not Operator.Asset.Next_Break == 0: if datetime.datetime.now( ) > Operator.Asset.Next_Break and Operator.Asset_is_working and not Operator.Asset.Broken and Operator.Has_asset: print "not working" Operator.Asset.First_time_random_break = False Operator.Asset_is_working = False if not Operator.Asset_is_working and not Operator.Asset.Broken and __builtin__.operator_connected: Participant.handle_break(Service, Manufacturer, Operator, queue) # END ASSET BREAK ##HANDLING THE SERVICE CAR AND REPAIRING THE ASSET# Participant.handle_reparing(Operator, Service, Manufacturer, GPIO_to_repair_for_demo) ### END HANDLING THE SERVICE CAR AND REPAIRING THE ASSET## ####HANDLING ASSET BOOSTING if ASSET_INSTALLED and not Operator.Asset.Broken and Operator.Has_asset and __builtin__.operator_connected: print Operator.Asset.pimping if GPIO.input(Operator.Pimp_GPIO ) == 0 and Operator.Asset.pimping < 5: Operator.Asset.pimping += 1 if GPIO.input(Operator.Pimp_GPIO ) == 1 and Operator.Asset.pimping > 0: Operator.Asset.pimping -= 1 # remind to pimp the asset if not Manufacturer.Bulletin_at_manufacturers_campus and GPIO.input( Operator.Service_Bulletin_GPIO_Measure ) == 0 and not Operator.Asset.Pimped and Manufacturer.Bulletin.Activated_for_the_communication and Manufacturer.Bulletin.Agreement_loaded_on_bulletin_by_the_manufacturer: if Operator.Asset.Next_Pimp == 0 and Manufacturer.Bulletin.Activated_for_the_communication: # FIRST REMINDER print "setting next pimp" print str(Manufacturer.Bulletin. Activated_for_the_communication) Operator.Asset.set_next_pimp_reminder(seconds_=8) else: if datetime.datetime.now() > Operator.Asset.Next_Pimp: # REMINDER EVENT print("updating event 10") Participant.update_event(10) GPIO.output(Service.GPIO_out, GPIO.HIGH) Operator.Asset.set_next_pimp_reminder() ##BOOSTING THE ASSET # if pimping>4 and not Operator.Asset.Pimped and not INFORMED_BULLETIN: if Operator.Asset.pimping == 5 and not Operator.Asset.Pimped: Operator.pimp_the_pump() GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.HIGH) GPIO.output(Manufacturer.GPIO_out, GPIO.HIGH) GPIO.output(Service.GPIO_out, GPIO.HIGH) time.sleep(10) GPIO.output(Operator.Service_Bulletin_GPIO_out, GPIO.LOW) GPIO.output(Manufacturer.GPIO_out, GPIO.LOW) GPIO.output(Service.GPIO_out, GPIO.LOW) if Operator.Asset.pimping == 0 and Operator.Asset.Pimped and not Operator.Asset.Broken and Operator.Has_asset: Operator.unpimp_the_pump(Service) Operator.Asset.Next_Break = 0 Operator.Asset.set_next_pimp_reminder() ##END BOOSTING THE ASSET print "stoped" except KeyboardInterrupt: # here you put any code you want to run before the program # exits when pressing CTRL+C GPIO.cleanup() http_server.stop()