def _send_request(text): try: response = requests.get( url="https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/" + config.microsoft_luis_app_key(), params={ "staging": "true", "verbose": "true", "timezoneOffset": "0", "subscription-key": config.microsoft_luis_subscription_key(), "q": text, }, ) log.debug(f'Response HTTP Status Code: {response.status_code}') log.debug(f'Response HTTP Response Body: {response.content}') if response.status_code != 200: log.error( f'HTTP Request NOK ({response.status_code}), Body: {response.content}' ) return json.loads(response.content) except requests.exceptions.RequestException: log.error('HTTP Request failed')
def _send_request(audio_file_path): try: response = requests.post( url= "https://westeurope.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1", params={ "format": "detailed", "cid": config.microsoft_speech_endpoint_id(), }, headers={ "Ocp-Apim-Subscription-Key": config.microsoft_speech_subscription_key(), "Content-Type": "audio/wav; codecs=audio/pcm;", }, data=open(audio_file_path, 'rb'), ) log.debug(f'Response HTTP Status Code: {response.status_code}') log.debug(f'Response HTTP Response Body: {response.content}') if response.status_code != 200: log.error( f'HTTP Request NOK ({response.status_code}), Body: {response.content}' ) return json.loads(response.content) except requests.exceptions.RequestException: log.error('HTTP Request failed')
def test_generate(self): grid = Grid() grid.init_generate_grid() self.assertEqual(len(grid.grid), 16) for cell in grid.grid: log.debug(str(cell)) log.debug(grid.type_count) grid.show_detail()
def synthesize_monster(self) -> []: self.check_eliminate() temp = [] for direct in self.direct_states: temp.extend(self.direct_states[direct]) if len(temp) == 0: return [] result = {} for state in temp: key = (state.ref_id, state.order) if key not in result: result[key] = state else: result[key].indexes.extend(state.indexes) final_index = [] remove_indexes = None for (ref_id, order) in result: if order == OrderType.A: log.warning('up the top order %s %s' % (ref_id, result[(ref_id, order)])) continue value = result[(ref_id, order)] indexes = set(value.indexes) target_index, target_level = self.get_synthesize_index_level(indexes) log.debug('synthesize unit: %s %s %s target_index %s' % (ref_id, order, indexes, target_index)) final_index.append(target_index) monster = Monster(target_index, ref_id, order.up(), level=target_level) self.grid[target_index] = monster self.record_soldier(ref_id, order, target_level) if remove_indexes is None: remove_indexes = indexes else: remove_indexes = indexes.union(remove_indexes) log.info('synthesize:%s remove:%s' % (final_index, remove_indexes)) if remove_indexes is None: return [] result = [] for index in remove_indexes: if index not in final_index: result.append(index) log.debug('remove=%s' % result) return result
def swap_monster(self, one_index, other_index) -> bool: log.debug('swap %s %s' % (one_index, other_index)) one = self.grid[one_index] other = self.grid[other_index] if one.get_type() != CellType.MONSTER or other.get_type() != CellType.MONSTER: return False if one.is_same(other): # log.warning('swap same %s<->%s' % (one, other)) return False other.index = one_index one.index = other_index self.grid[one_index] = other self.grid[other_index] = one return True
def calculate_swap_effect(self, index_one, index_other) -> int: effect = 0 swap_result = self.swap_monster(index_one, index_other) if not swap_result: log.debug('swap failed') return 0 self.check_eliminate() for direct in self.direct_states: for state in self.direct_states[direct]: effect += state.order.value ** 3 target_level = 0 for index in state.indexes: monster = self.grid[index] target_level += monster.level effect += (target_level - 3) * (state.order.value - 1) ** 3 log.debug('state %s effect=%s' % (state, effect)) self.swap_monster(index_one, index_other) return effect
def best_plan_to_swap(grid) -> (CellVO, CellVO): cells = grid.get_complex_swap_choice() log.debug('swap choice %s' % cells) if len(cells) == 0: monster = grid.get_simple_swap_choice() log.debug('the way of find by simple %s' % monster) if monster is None: log.info("can't find any swap") else: other_monster = grid.get_completion_one(monster) return monster, other_monster return () if len(cells) > 1: max_effect = 0 cell_tuple = () for i in range(len(cells)): for j in range(i + 1, len(cells) - 1): log.debug('%s <-> %s' % (cells[i], cells[j])) temp = grid.calculate_swap_effect(cells[i].index, cells[j].index) if max_effect < temp: max_effect = temp cell_tuple = cells[i], cells[j] if max_effect != 0: return cell_tuple first = cells[0] cell = grid.get_completion_one(first) log.debug('get one %s' % cell) if cell is not None: log.debug('random other to eliminate') return first, cell return ()
def process(self, connection, client_address): try: data = tool.recv_msg(connection) data_loaded = pickle.loads(data) log.debug('new connection from %s', client_address) log.debug("data received: %s", data_loaded) self.__operations(data_loaded['operation'])(self, data_loaded, connection) finally: log.debug('connection closed for %s', client_address) connection.close()
def process(self, connection, client_address): try: data = tool.recv_msg(connection) data_loaded = pickle.loads(data) log.debug('new connection from %s', client_address) log.debug("data received: %s", data_loaded) self.__operations(data_loaded['operation'])(self, data_loaded, connection) finally: # Clean up the connection log.debug('connection closed for %s', client_address) connection.close()
def _update_ini_conf(self, conf): log.debug('_update_ini_conf ') TestInputSingleton.ini_config = conf.servers
def _get_sys_conf(self): if self.argParser.options.sysconf: log.debug('sys conf is: %s' % self.argParser.options.sysconf) conf = SysConfig() conf.parse_from_config(self.argParser.options.sysconf) self._update_ini_conf(conf)