def calculate(const_hl: dict, transitions_: dict, matrix: list, seq: str) -> tuple: """ Calculates matrix, HL sequence and result probability """ best = [] result_value = None for idx, elem in enumerate(seq): if idx == 0: h_value = transitions_['start'] + const_hl['H'][elem] l_value = transitions_['start'] + const_hl['L'][elem] else: h_value = const_hl['H'][elem] + max( matrix[0][idx - 1] + transitions_['HH'], matrix[1][idx - 1] + transitions_['LH']) l_value = const_hl['L'][elem] + max( matrix[0][idx - 1] + transitions_['HL'], matrix[1][idx - 1] + transitions_['LL']) matrix[0][idx] = h_value matrix[1][idx] = l_value if to_decimal(h_value) > to_decimal(l_value): best.append('H') elif to_decimal(h_value) == to_decimal(l_value): best.append(best[-1]) else: best.append('L') result_value = max(h_value, l_value) return matrix, best, 2**result_value
def buy(coin_type, price, amount, trade_password=None, trade_id=None): price = to_decimal(price, 2) amount = to_decimal(amount, 2) extra_data = { 'trade_password': trade_password, 'trade_id': trade_id, } return post('buy', price=price, coin_type=coin_type, amount=amount, extra_data=extra_data)
def buy_market(coin_type, amount, trade_password=None, trade_id=None): amount = to_decimal(amount, 2) # amount的单位是元 extra_data = { 'trade_password': trade_password, 'trade_id': trade_id, } return post('buy_market', coin_type=coin_type, amount=amount, extra_data=extra_data)
def sell_market(coin_type, amount, trade_password=None, trade_id=None): amount = to_decimal(amount, 4) # amount的单位是数字货币个数 extra_data = { 'trade_password': trade_password, 'trade_id': trade_id, } return post('sell_market', coin_type=coin_type, amount=amount, extra_data=extra_data)
def next_ip(broadcast): tinit = "" for x in broadcast: tinit = tinit + x tdec = to_decimal(int(tinit)) tbin = binary_fixed(to_binary(tdec + 1), 32) tinit = "" tmp = "" for i in range(0, len(tbin)): if (i % 8) == 0 and i != 0: tinit = tinit + str(to_decimal(int(tmp))) + "." tmp = "" tmp = tmp + tbin[i] tinit = tinit + str(to_decimal(int(tmp))) return tinit
def test_to_decimal(self): samples = [ (2, '2.00'), (2.1, '2.10'), (2.114, '2.11'), (2.115, '2.12'), ('2.11', '2.11'), ] for p, d in samples: self.assertEqual(utils.to_decimal(p, 2), d)
def get_data(self, content=None): if content is None: d = pq(url=self.url, opener=self.opener) else: d = pq(content) # Product name product_name = d("h1").text() # Product image incomplete_link = d("img[class=imgproducto]").attr("src") clean_link = "http://" + urlparse(self.url).hostname + incomplete_link # Product categories categories = d(".barnavega").text().split("/")[1:-1] categories = [a.strip() for a in categories] # Product price price_with_currency = d('h1').parent().find("span").eq(1).text() # Precio se obtiene "$U 33.00" price_str = price_with_currency.strip().split(" ")[1] assert is_number(price_str) price = to_decimal(price_str) return {'name': product_name, "price": price, "image_url": clean_link, "categories": categories}
def get_data(self, content=None): if content is None: d = pq(url=self.url, opener=self.opener) else: d = pq(content) # Product name product_name = d(".prod:first").find("h2").text() # Product image dirty_link = d(".contenedor_foto_producto>a").attr("href") clean_link = re.search("\(\'(?P<url>https?://[^\s]+)\',", dirty_link).group("url") # Product categories categories = d(".btn_navegacion").find("td:nth-child(2)").find(".link_nav")[1:-1] categories = [d(a).text().strip() for a in categories] # Product price price_with_currency = d('.precio_producto').find("span").text() #Precio se obtiene "$ 33.00" price_str = price_with_currency.strip().split(" ")[1] assert is_number(price_str) price = to_decimal(price_str) return {'name': product_name, "price": price, "image_url": clean_link, "categories": categories}
def test_feedback_control_v(k_p, k_i, V_expected, u_expected): # verified x_d = np.array( to_decimal([[0, 0, 1, .5], [0, 1, 0, 0], [-1, 0, 0, .5], [0, 0, 0, 1]])) x_d_next = np.array( to_decimal([[0, 0, 1, .6], [0, 1, 0, 0], [-1, 0, 0, .3], [0, 0, 0, 1]])) x = np.array( to_decimal([[.170, 0, .985, .387], [0, 1, 0, 0], [-.985, 0, .170, .570], [0, 0, 0, 1]])) configuration = [0, 0, 0, 0, 0, 0, 0, 0, .2, -1.6, 0, 0, 0] configuration = to_decimal(configuration) t_b0 = np.array( to_decimal([[1, 0, 0, .1662], [0, 1, 0, 0], [0, 0, 1, .0026], [0, 0, 0, 1]])) M = np.array( to_decimal([[1, 0, 0, .033], [0, 1, 0, 0], [0, 0, 1, .6546], [0, 0, 0, 1]])) b_list = np.array( to_decimal([[0, 0, 1, 0, .033, 0], [0, -1, 0, -.5076, 0, 0], [0, -1, 0, -.3526, 0, 0], [0, -1, 0, -.2176, 0, 0], [0, 0, 1, 0, 0, 0]])).T controller = Controller(k_p, k_i, .01) # end verified v, x_err = controller.feedback_control(x_d, x_d_next, x) u, x_err = controller.commanded_joint_vels(x_d, x_d_next, x, configuration, t_b0, M, b_list) print(v) print(u) assert np.allclose(u, u_expected, rtol=1e-2)
def get_data(self, content=None): if content is None: d = pq(url=self.url, opener=self.opener) else: d = pq(content) # Product name product_name = d("h1:first").text() product_name = re.sub(' +', ' ', product_name) # if d("#ctl00_ContentPlaceHolder1_lblUnitType").text().lower() == 'kg': # product_name += " 1 Kg" # Product image incomplete_link = d("#ctl00_ContentPlaceHolder1_imgProductImage").attr("src") clean_link = urljoin(self.url, incomplete_link[1:]) # Product categories categorias = d("#ctl00_ContentPlaceHolder1_lblMap").text().split(" -> ")[1:-1] # Product price price_with_currency = d('#ctl00_ContentPlaceHolder1_lblPrecioMA').text() #Precio se obtiene "$ 33.00" price_str = price_with_currency.strip().split(" ")[1] assert is_number(price_str) price = to_decimal(price_str) return {'name': product_name, "price": price, "image_url": clean_link, "categories": categorias}
def two_complement(binary): sign = binary[0] binary = substract_binary(binary, "1") my_binary = "".join(["1" if bit == "0" else "0" for bit in binary]) number = to_decimal(my_binary) return number if sign == "0" else number * -1
def __unicode__(self): return '{0} ({1})'.format(self.description, to_decimal(self.amount))
def excess(binary): number = to_decimal(binary) return number - 127
def one_complement(binary): sign = binary[0] binary = ''.join(['1' if bit == '0' else '0' for bit in binary]) number = to_decimal(binary[1:]) return number if sign == '0' else number * -1
def signed(binary): sign = binary[0] number = to_decimal(binary[1:]) return number if sign == '0' else number * -1