def test_two_assign_participants_by_rssi(self): rssis = [[ 0.65389872, 0.13733707, 0.1226876, 0.73320961, 0.64940965, 0.12463234, 0.12296994, 0.68053716, 0.66020358, 0.12428901, 0.12312815, 0.69160986, 0.65582329, 0.12536003, 0.12587067, 0.66315573, 0.66313261, 0.12816505, 0.13491708, 0.66950738, 0.14047238 ], [ 0.26651502, 0.2073856, 0.13547869, 0.25948182, 0.28204739, 0.13716124, 0.13526952, 0.24828221, 0.25431305, 0.13681877, 0.13650328, 0.28083691, 0.25550124, 0.13498682, 0.13611424, 0.2629154, 0.26388499, 0.13780586, 0.13561584, 0.27228078, 0.1356563 ]] proto1 = ProtocolAnalyzer(None) proto2 = ProtocolAnalyzer(None) for i in range(0, len(rssis[0])): message = copy.deepcopy(self.protocol.messages[i]) message.participant = None proto1.messages.append(message) proto1.messages[i].rssi = rssis[0][i] self.assertEqual(len(proto1.messages), 21) for i in range(0, len(rssis[1])): message = copy.deepcopy(self.protocol.messages[21 + i]) message.participant = None proto2.messages.append(message) proto2.messages[i].rssi = rssis[1][i] self.assertEqual(len(proto2.messages), 21) alice = Participant(name="Alice", shortname="A") alice.relative_rssi = 1 bob = Participant(name="Bob", shortname="B") bob.relative_rssi = 0 excpected_partis = [[ alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, bob ], [ alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, bob ]] AutoAssigner.auto_assign_participants(proto1.messages, [alice, bob]) for i, message in enumerate(proto1.messages): self.assertEqual(message.participant, excpected_partis[0][i]) AutoAssigner.auto_assign_participants(proto2.messages, [alice, bob]) for i, message in enumerate(proto2.messages): self.assertEqual(message.participant, excpected_partis[1][i])
def on_btn_add_participant_clicked(self): used_shortnames = {p.shortname for p in self.participants} used_colors = set(p.color_index for p in self.participants) avail_colors = set(range(0, len( constants.PARTICIPANT_COLORS))) - used_colors if len(avail_colors) > 0: color_index = avail_colors.pop() else: color_index = random.choice( range(len(constants.PARTICIPANT_COLORS))) num_chars = 0 participant = None while participant is None: num_chars += 1 for c in string.ascii_uppercase: shortname = num_chars * str(c) if shortname not in used_shortnames: participant = Participant("Device " + shortname, shortname=shortname, color_index=color_index) break self.participants.append(participant) participant.relative_rssi = len(self.participants) - 1 self.__set_relative_rssi_delegate() self.participant_table_model.update() self.ui.btnRemoveParticipant.setEnabled(True) self.open_editors()
def test_two_assign_participants_by_rssi(self): rssis = [[0.65389872, 0.13733707, 0.1226876, 0.73320961, 0.64940965, 0.12463234, 0.12296994, 0.68053716, 0.66020358, 0.12428901, 0.12312815, 0.69160986, 0.65582329, 0.12536003, 0.12587067, 0.66315573, 0.66313261, 0.12816505, 0.13491708, 0.66950738, 0.14047238], [0.26651502, 0.2073856, 0.13547869, 0.25948182, 0.28204739, 0.13716124, 0.13526952, 0.24828221, 0.25431305, 0.13681877, 0.13650328, 0.28083691, 0.25550124, 0.13498682, 0.13611424, 0.2629154, 0.26388499, 0.13780586, 0.13561584, 0.27228078, 0.1356563]] proto1 = ProtocolAnalyzer(None) proto2 = ProtocolAnalyzer(None) for i in range(0, len(rssis[0])): message = copy.deepcopy(self.protocol.messages[i]) message.participant = None proto1.messages.append(message) proto1.messages[i].rssi = rssis[0][i] self.assertEqual(len(proto1.messages), 21) for i in range(0, len(rssis[1])): message = copy.deepcopy(self.protocol.messages[21 + i]) message.participant = None proto2.messages.append(message) proto2.messages[i].rssi = rssis[1][i] self.assertEqual(len(proto2.messages), 21) alice = Participant(name="Alice", shortname="A") alice.relative_rssi = 1 bob = Participant(name="Bob", shortname="B") bob.relative_rssi = 0 excpected_partis = [[alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, bob], [alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, alice, bob, bob, alice, bob]] proto1.auto_assign_participants([alice, bob]) for i, message in enumerate(proto1.messages): self.assertEqual(message.participant, excpected_partis[0][i]) proto2.auto_assign_participants([alice, bob]) for i, message in enumerate(proto2.messages): self.assertEqual(message.participant, excpected_partis[1][i])
def add_participant(self): used_colors = set(p.color_index for p in self.participants) avail_colors = set(range(0, len(constants.PARTICIPANT_COLORS))) - used_colors if len(avail_colors) > 0: color_index = avail_colors.pop() else: color_index = random.choice(range(len(constants.PARTICIPANT_COLORS))) name, shortname = self.__get_initial_name() participant = Participant(name, shortname=shortname, color_index=color_index) self.participants.append(participant) participant.relative_rssi = len(self.participants) - 1 self.update() self.participant_edited.emit()
def add_participant(self): used_colors = set(p.color_index for p in self.participants) avail_colors = set(range(0, len( constants.PARTICIPANT_COLORS))) - used_colors if len(avail_colors) > 0: color_index = avail_colors.pop() else: color_index = random.choice( range(len(constants.PARTICIPANT_COLORS))) name, shortname = self.__get_initial_name() participant = Participant(name, shortname=shortname, color_index=color_index) self.participants.append(participant) participant.relative_rssi = len(self.participants) - 1 self.update() self.participant_edited.emit()