def getMinMaxExchange(self, symbol): max_exchange = self.exchanges[0] min_exchange = self.exchanges[0] avg_price = 0 min_price = 1000000 prices = 0 avg_count = 0 for e in self.exchanges: price = e.get_last_price(symbol) if price <= 0: continue avg_count += 1 prices += price if price > avg_price: avg_price = price max_exchange = e if price < min_price: min_price = price min_exchange = e if min_price == 1000000: min_price = 0 if avg_count == 0: print('%s没有价格' % symbol) return None # avg_price -= avg_price * 0.003 profit = (avg_price - min_price) * self.rate avg = prices / avg_count rate_price = avg_price / 100 * 0.1 * self.rate # print('%s 最高价格交易所:%s 价格:%f,最低:%s 价格:%f,均价:%f, 差价:%f, 按手续费:%f,两次手续费:%f, 纯利润:%f' % # (symbol, max_exchange.Name, avg_price, min_exchange.Name, min_price, avg, # profit, rate_price, rate_price * 2, profit - rate_price * 2)) # print('\033[1;32m' + 'green' + '\033[0m') if avg_price == min_price: print_blue('%s 只在一个交易所发行, 无差价' % symbol) # print('\033[1;34m %s 只在一个交易所发行, 无差价 \033[0m' % symbol) else: if profit - rate_price * 2 >= 0: print_green( '%s 人民币单价:%f, 纯利润:%f元, 差价:%f元, 按手续费:%f元,两次手续费:%f元' % ( symbol, avg * self.rate, profit - rate_price * 2, profit, rate_price, rate_price * 2, )) else: print_red('%s 人民币单价:%f, 纯利润:%f元, 差价:%f元, 按手续费:%f元,两次手续费:%f元' % ( symbol, avg * self.rate, profit - rate_price * 2, profit, rate_price, rate_price * 2, )) return max_exchange, min_exchange, avg_price, min_price, prices / avg_count
def load_info(mesh_file): basename, ext = os.path.splitext(mesh_file) info_file = basename + ".info" info = {} if os.path.exists(info_file): with open(info_file, 'r') as fin: try: info = json.load(fin) except ValueError: print_red("Cannot parse {}, overwriting it".format(info_file)) return info
def load_info(mesh_file): basename, ext = os.path.splitext(mesh_file); info_file = basename + ".info"; info = {}; if os.path.exists(info_file): with open(info_file, 'r') as fin: try: info = json.load(fin); except ValueError: print_red("Cannot parse {}, overwriting it".format(info_file)); return info;
def print_bbox(mesh, info): print_section_header("Boundding box") if mesh.num_vertices == 0: print_red("Cannot compute bbox on empty mesh.") return bbox_min, bbox_max = mesh.bbox if mesh.dim == 3: print_format = "[{v[0]:^10.6g} {v[1]:^10.6g} {v[2]:^10.6g}]" elif mesh.dim == 2: print_format = "[{v[0]:^10.6g} {v[1]:^10.6g}]" print("bbox_min: " + print_format.format(v=bbox_min)) print("bbox_max: " + print_format.format(v=bbox_max)) print("bbox_size: " + print_format.format(v=bbox_max - bbox_min)) info["bbox_min"] = bbox_min.tolist() info["bbox_max"] = bbox_max.tolist()
def print_bbox(mesh, info): print_section_header("Boundding box"); if mesh.num_vertices == 0: print_red("Cannot compute bbox on empty mesh."); return; bbox_min, bbox_max = mesh.bbox; if mesh.dim == 3: print_format = "[{v[0]:^10.6g} {v[1]:^10.6g} {v[2]:^10.6g}]"; elif mesh.dim == 2: print_format = "[{v[0]:^10.6g} {v[1]:^10.6g}]"; print("bbox_min: " + print_format.format(v=bbox_min)); print("bbox_max: " + print_format.format(v=bbox_max)); print("bbox_size: " + print_format.format(v=bbox_max - bbox_min)); info["bbox_min"] = bbox_min.tolist(); info["bbox_max"] = bbox_max.tolist();
def quantile_breakdown(data, name, info, title=None, with_total=True): if title is None: title = "{} info".format(name.capitalize()) print_section_header(title) if len(data) == 0: print_red("Empty") return # Filter out inf/nan values. is_valid = np.isfinite(data) data = data[is_valid] num_bad_values = len(is_valid) - len(data) info["bad_{}".format(name)] = num_bad_values if not np.all(is_valid): print_red("Skipping {} non-finite values".format(num_bad_values)) ave = np.mean(data) ave_text = "ave: {:.6g}".format(ave) print("{: <27}".format(ave_text), end="") if with_total: total = np.sum(data) total_text = "total: {:.6g}".format(total) print("{: >28}".format(total_text)) else: print() p0, p25, p50, p75, p90, p95, p100 =\ np.percentile(data, [0, 25, 50, 75, 90, 95, 100]) table_format = "{:^7.3} {:^7.3} {:^7.3} {:^7.3} {:^7.3} {:^7.3} {:^7.3}" print(table_format.format("min", "25%", "50%", "75%", "90%", "95%", "max")) print(table_format.format(p0, p25, p50, p75, p90, p95, p100)) info["ave_{}".format(name)] = ave info["min_{}".format(name)] = p0 info["p25_{}".format(name)] = p25 info["median_{}".format(name)] = p50 info["p75_{}".format(name)] = p75 info["p90_{}".format(name)] = p90 info["p95_{}".format(name)] = p95 info["max_{}".format(name)] = p100 if with_total: info["total_{}".format(name)] = total
def quantile_breakdown(data, name, info, title=None, with_total=True): if title is None: title = "{} info".format(name.capitalize()); print_section_header(title); if len(data) == 0: print_red("Empty"); return; # Filter out inf/nan values. is_valid = np.isfinite(data); data = data[is_valid]; num_bad_values = len(is_valid) - len(data); info["bad_{}".format(name)] = num_bad_values; if not np.all(is_valid): print_red("Skipping {} non-finite values".format(num_bad_values)); ave = np.mean(data); ave_text = "ave: {:.6g}".format(ave); print("{: <27}".format(ave_text), end=""); if with_total: total = np.sum(data); total_text = "total: {:.6g}".format(total); print("{: >28}".format(total_text)); else: print(); p0, p25, p50, p75, p90, p95, p100 =\ np.percentile(data, [0, 25, 50, 75, 90, 95, 100]); table_format = "{:^7.3} {:^7.3} {:^7.3} {:^7.3} {:^7.3} {:^7.3} {:^7.3}"; print(table_format.format("min", "25%", "50%", "75%", "90%", "95%", "max")); print(table_format.format(p0, p25, p50, p75, p90, p95, p100)); info["ave_{}".format(name)] = ave; info["min_{}".format(name)] = p0; info["p25_{}".format(name)] = p25; info["median_{}".format(name)] = p50; info["p75_{}".format(name)] = p75; info["p90_{}".format(name)] = p90; info["p95_{}".format(name)] = p95; info["max_{}".format(name)] = p100; if with_total: info["total_{}".format(name)] = total;
def print_bbox(mesh, info): print_section_header("Boundding box") if mesh.num_vertices == 0: print_red("Cannot compute bbox on empty mesh.") return bbox_min, bbox_max = mesh.bbox if mesh.dim == 3: print_format = "[{v[0]:^10.6g} {v[1]:^10.6g} {v[2]:^10.6g}]" elif mesh.dim == 2: print_format = "[{v[0]:^10.6g} {v[1]:^10.6g}]" diag = np.linalg.norm(bbox_max - bbox_min) radii = [0.0125, 0.025, 0.05, 0.1] print("bbox_min: " + print_format.format(v=bbox_min)) print("bbox_max: " + print_format.format(v=bbox_max)) print("bbox_size: " + print_format.format(v=bbox_max - bbox_min)) print("bbox_diag: {:^10.6g}".format(diag)) print("radii: " + ' '.join("{:^10.6g}".format(r * diag) for r in radii)) info["bbox_min"] = bbox_min.tolist() info["bbox_max"] = bbox_max.tolist()
def print_self_intersection_info(mesh, info): if mesh.vertex_per_face == 4: print_red("Converting quad to tri for self-intersection check.") mesh = pymesh.quad_to_tri(mesh) if mesh.num_vertices == 0 or mesh.num_faces == 0: num_intersections = 0 num_coplanar_intersecting_faces = 0 else: intersecting_faces = pymesh.detect_self_intersection(mesh) num_intersections = len(intersecting_faces) intersect_and_coplanar = coplanar_analysis(mesh, intersecting_faces) num_coplanar_intersecting_faces = len(intersect_and_coplanar) info["self_intersect"] = num_intersections > 0 info["num_self_intersections"] = num_intersections info["num_coplanar_intersecting_faces"] = num_coplanar_intersecting_faces print_property("self intersect", info["self_intersect"], False) if num_intersections > 0: print_property("num self intersections", num_intersections, 0) print_property("num coplanar intersecting faces", num_coplanar_intersecting_faces, 0)
def print_self_intersection_info(mesh, info): if mesh.vertex_per_face == 4: print_red("Converting quad to tri for self-intersection check."); mesh = pymesh.quad_to_tri(mesh); if mesh.num_vertices == 0 or mesh.num_faces == 0: num_intersections = 0; num_coplanar_intersecting_faces = 0; else: intersecting_faces = pymesh.detect_self_intersection(mesh); num_intersections = len(intersecting_faces); intersect_and_coplanar = coplanar_analysis(mesh, intersecting_faces); num_coplanar_intersecting_faces = len(intersect_and_coplanar); info["self_intersect"] = num_intersections > 0; info["num_self_intersections"] = num_intersections; info["num_coplanar_intersecting_faces"] = num_coplanar_intersecting_faces; print_property("self intersect", info["self_intersect"], False); if num_intersections > 0: print_property("num self intersections", num_intersections, 0); print_property("num coplanar intersecting faces", num_coplanar_intersecting_faces, 0);
def print_property(name, val, expected=None): if expected is not None and val != expected: print_red("{:-<48}: {}".format(name, val)) else: print("{:-<48}: {}".format(name, val))
def print_property(name, val, expected=None): if expected is not None and val != expected: print_red("{:-<48}: {}".format(name, val)); else: print("{:-<48}: {}".format(name, val));