def main(self): parser = argparse.ArgumentParser() parser.add_argument("filename") args = parser.parse_args() try: d = BmpReader(args.filename) data = d.return_data() s = Trans(data) data1 = s.hsi() data2 = s.yiq() data3 = s.ycbcr() d.rebuild(data1, ".hsi") d.rebuild(data2, ".yiq") d.rebuild(data3, ".ycbcr") except Exception as e: print("ERROR:\n" + str(e))
def generate_queue(data, target, parts): q = queue.Queue() size = 1 / parts X_1, X_2, y_1, y_2 = train_test_split(data, target, test_size=size) d1 = Trans(data=X_2, target=y_2) q.put(d1) if parts == 2: q.put(Trans(data=X_1, target=y_1)) q.put(Trans(data=X_1, target=y_1)) data = X_1 target = y_1 parts = parts - 1 while parts >= 2: size = 1 / parts X_1, X_2, y_1, y_2 = train_test_split(data, target, test_size=size) q.put(Trans(data=X_2, target=y_2)) q.put(Trans(data=X_2, target=y_2)) if parts == 2: q.put(Trans(data=X_1, target=y_1)) q.put(Trans(data=X_1, target=y_1)) data = X_1 target = y_1 parts = parts - 1 q.put(d1) return q
parser.add_argument('-c', '--char', default='囧', metavar='CHAR', help='characters') parser.add_argument('-t', '--title', default='img2html by [email protected]', metavar='TITLE', help='html title') parser.add_argument('-f', '--font', default='monospace', metavar='FONT', help='html font') parser.add_argument('-i', '--input', metavar='IN', help='image to convert', required=True) parser.add_argument('-o', '--output', default=None, metavar='OUT', help='output file') args, text = parser.parse_known_args() trans = Trans(args.size, args.background, args.title, args.font) trans.trans(args.input, args.char, args.output)
class Cleaner(): account = Account() card = Card() client = Client() disp = Disp() district = District() loan = Loan() order = Order() trans = Trans() def cleanData(self): print("Error in district:") self.district.clean() self.district.output("cleaned_district.csv") print("Error in account:") self.account.clean(self.district.cur) print("Error in client:") self.client.clean(self.district.cur) print("Error in disp:") self.disp.clean(self.client.cur, self.account.cur) dat = [] i = 0 j = 0 k = 0 a_len = len(self.account.cleaned_data) d_len = len(self.disp.cleaned_data) c_len = len(self.client.cleaned_data) while True: a = self.account.cleaned_data[i] d = self.disp.cleaned_data[j] c = self.client.cleaned_data[k] a_a_id = a[0] c_c_id = c[0] d_a_id = d[2] d_c_id = d[1] if a_a_id != d_a_id: while a_a_id < d_a_id: account_id, district_id, frequency, date, time = a g = 'unknown' t = 'UNKNOWN' dat.append( [account_id, district_id, frequency, date, time, g, t]) i = i + 1 a = self.account.cleaned_data[i] a_a_id = a[0] if a_a_id > d_a_id: print("Sort error") break if (c_c_id != d_c_id): print("Sort error") break g = c[2] t = d[3] if (j != d_len - 1) and (k != c_len - 1): _d = self.disp.cleaned_data[j + 1] _c = self.client.cleaned_data[k + 1] _d_a_id = _d[2] if d_a_id == _d_a_id: _d_c_id = _d[1] _c_c_id = _c[0] if _c_c_id != _d_c_id: print("Sort error") break _g = _c[2] _t = _d[3] if g != _g: g = 'couple' if t != _t: t = 'DOUBLE' j = j + 1 k = k + 1 account_id, district_id, frequency, date, time = a dat.append([account_id, district_id, frequency, date, time, g, t]) i = i + 1 j = j + 1 k = k + 1 if (i == a_len) or (j == d_len) or (k == c_len): break self.account.cleaned_data = dat self.account.output("cleaned_account.csv") self.client.output("cleaned_client.csv") self.disp.output("cleaned_disp.csv") print("Error in card:") self.card.clean(self.disp.cur) self.card.output("cleaned_card.csv") print("Error in loan:") self.loan.clean(self.account.cur) self.loan.output("cleaned_loan.csv") print("Error in order:") self.order.clean(self.account.cur) self.order.output("cleaned_order.csv") print("Error in trans:") self.trans.clean(self.account.cur) self.trans.output("cleaned_trans.csv")
def handler_card_trans(self, data): if data: # >>>>>>>>>>>>>> 解密数据 # 接收到的数据格式为 "DES加密的数据" + 终端号 # 解密方式为: # 1.将接收到的数据分为两部分:DES加密的数据和终端号 # 2.去数据库中查询与此终端号对应的DES密钥 # 3.使用DES密钥解密 DES加密的数据 部分 print 'raw_data ->', data print 'len(raw_data) ->', len(data) terminal_no = data[-8:] data = base64.decodestring(data[:-8]) print terminal_no key = get_DES_key(terminal_no) k = des(key, ECB, key, None, PAD_PKCS5) data = k.decrypt(data) # 解密加密的数据 # 转换数据的编码 tmp_data = str(data).replace("'", '"') tmp_data = json.loads(tmp_data) data = {} for key in tmp_data.keys(): data[key.encode('iso8859-1').lower()] = tmp_data[key].encode('iso8859-1') print '========= log for test ========' for k in data.keys(): print k, '\t\t--->', data[k] print '===============================\n\n\n' trans_result = {} # 定义交易结果变量 trans = Trans(data) if data['action'] == 'singin': # 签到 trans_result = trans.signin() if data['action'] == 'payment': # 消费 trans_result = trans.payment() if data['action'] == 'deposit': # 充值 trans_result = trans.deposit() if data['action'] == 'cancel_trans': # 撤销 trans_result = trans.cancel_trans() if data['action'] == 'cancel_deposit': # 充值撤销 trans_result = trans.cancel_deposit() if data['action'] == 'cancel_payment': # 消费撤销 trans_result = trans.cancel_payment() if data['action'] == 'reversal': # 冲正 trans_result = trans.reversal() if data['action'] == 'new_card': # 卡启用 trans_result = trans.new_card() if data['action'] == 'check_balance': # 余额查询 trans_result = trans.check_balance() if data['action'] == 'change_overdue_date': # 改有效期 trans_result = trans.change_overdue_date() if data['action'] == 'change_card': # 换卡 trans_result = trans.change_card() if data['action'] == 'write_card': # 补磁 * trans_result = trans.write_card() if data['action'] == 'change_password': # 卡改密 trans_result = trans.change_password() if data['action'] == 'points_payment': # 积分消费 trans_result = trans.points_payment() if data['action'] == 'cancel_points_payment': # 积分消费撤销 trans_result = trans.cancel_points_payment() if data['action'] == 'check_points': # 查询积分 trans_result = trans.check_points() if data['action'] == 'points_deposit': # 积分充值 trans_result = trans.points_deposit() if data['action'] == 'cancel_points_deposit': # 积分充值撤销 trans_result = trans.cancel_points_deposit() if data['action'] == 'settlement': # 结算 trans_result = trans.settlement() if data['action'] == 'bind_member': # 绑定会员 trans_result = trans.bind_member() ###########返回信息########### print '========= log for test ========' for k in trans_result.keys(): print k, '\t\t<---', trans_result[k] print '===============================\n\n\n' data = str(trans_result) print 'returned data', data self.sendLine(data)
def handle_card_trans(self, data): print "server2.py data ->", data logger.debug(u'交易类型:' + data['action']) logger.debug(u'商户号:' + data['shop_no']) logger.debug(u'终端号:' + data['terminal_no']) logger.debug('card_no:' + data['card_no']) logger.debug('new_card_no:' + data['new_card_no']) trans_result = {} # 定义交易结果变量 trans = Trans(data) # if data['action'] == 'singin': # 签到 # trans_result = trans.signin() if data['action'] == '000010': # 消费 trans_result = trans.payment() if data['action'] == '000030': # 充值 trans_result = trans.deposit() if data['action'] == '000190': # 撤销 trans_result = trans.cancel_trans() # if data['action'] == '000040': # 充值撤销 # trans_result = trans.cancel_deposit() # if data['action'] == '000020': # 消费撤销 # trans_result = trans.cancel_payment() # if data['action'] == 'reversal': # 冲正 # trans_result = trans.reversal() if data['action'] == '000110': # 卡启用 trans_result = trans.new_card() if data['action'] == '000090': # 余额查询 trans_result = trans.check_balance() if data['action'] == '000150': # 改有效期 trans_result = trans.change_overdue_date() if data['action'] == '000120': # 换卡 trans_result = trans.change_card() # if data['action'] == 'write_card': # 补磁 * # trans_result = trans.write_card() if data['action'] == '000140': # 卡改密 trans_result = trans.change_password() if data['action'] == '000050': # 积分消费 trans_result = trans.points_payment() # if data['action'] == '000060': # 积分消费撤销 # trans_result = trans.cancel_points_payment() if data['action'] == 'check_points': # 查询积分 trans_result = trans.check_points() if data['action'] == '000070': # 积分充值 trans_result = trans.points_deposit() # if data['action'] == '000080': # 积分充值撤销 # trans_result = trans.cancel_points_deposit() # if data['action'] == 'settlement': # 结算 # trans_result = trans.settlement() # if data['action'] == 'bind_member': # 绑定会员 # trans_result = trans.bind_member() logger.debug(u'交易结果:' + trans_result['result_code']) data = str(trans_result) self.sendLine(data)
# cutoff_freq - Hz filtered_data = simple_filter_raw(signal.data, cutoff_freq, signal.frequency, type) return Signal(signal.info, filtered_data) # TODO: pretty sure the amplitude changes after filtering, # so the new info could be incorrect lowpass_filter_sig = ['cutoff_freq'] lowpass_default_params = m(cutoff_freq=10 * Hz) # lowpass_filter : (Signal, cutoff_freq: float) -> float lowpass_filter = part(simple_filter, type='low') lowpass_tr = Trans( 'Lowpass filter', lowpass_filter, lowpass_filter_sig, ) highpass_filter_sig = ['cutoff_freq'] highpass_default_params = m(cutoff_freq=0.05 * Hz) # highpass_filter : (Signal, float) -> float highpass_filter = part(simple_filter, type='high') highpass_tr = Trans('Highpass filter', highpass_filter, highpass_filter_sig) ###################################################################### # IMPORTANT - DON'T DELETE THESE CLASSES WITHOUT READING THE COMMENT # ###################################################################### class FiltersDict(OrderedDict):
logging.basicConfig( level=getattr(logging, LOG_LEVEL), format='%(asctime)s [%(levelname)s] %(module)s | %(message)s', datefmt='%Y/%m/%d %H:%M:%S', ) logger = logging.getLogger(__name__) argvs = sys.argv target_sentence = '' if len(argvs) != 2: logger.error('set analysis sentence') else: target_sentence = argvs[1] jp = JpParser(sys_dic_path='/usr/local/lib/mecab/dic/mecab-ipadic-neologd') trans = Trans() def eval_senti_score(words): score = 0 num_all_words = 0 for w in words: # TODO: multi words s = get_sentidic_score(w) num_all_words += 1 if s != 0: logger.info(w + str(s)) score += s # round=lambda x:(x*2+1)//2 return round(score / num_all_words, 2)
def setup_trans(self, trans_msg_map, trans_tag_map, hide_msg_list): self.trans = Trans(trans_msg_map, trans_tag_map, hide_msg_list)
class LogProcessor: hide_same_tags = None trans = None tag_keywords = None line_keywords = None separator = None regex_parser = None highlight_list = None # target_time = None # tmp last_msg_key = None last_tag = None pre_line_match = True def __init__(self, hide_same_tags): self.hide_same_tags = hide_same_tags def setup_trans(self, trans_msg_map, trans_tag_map, hide_msg_list): self.trans = Trans(trans_msg_map, trans_tag_map, hide_msg_list) def setup_separator(self, separator_rex_list): if separator_rex_list is not None: self.separator = LogSeparator(separator_rex_list) def setup_highlight(self, highlight_list): self.highlight_list = highlight_list def setup_condition(self, tag_keywords, line_keywords=None): self.tag_keywords = tag_keywords self.line_keywords = line_keywords def setup_regex_parser(self, regex_exp): self.regex_parser = LogRegex(regex_exp) def process(self, origin_line): origin_line = origin_line.decode('utf-8', 'replace').rstrip() if len(origin_line.strip()) <= 0: return None, None, False if self.regex_parser is None: return None, None, False date, time, level, tag, process, thread, message = self.regex_parser.parse( origin_line) if message is None: message = origin_line return self.process_decode_content(origin_line, time, level, tag, process, thread, message) # noinspection PyUnusedLocal def process_decode_content(self, line, time, level, tag, process, thread, message): match_condition = True # filter if self.tag_keywords is not None and tag is not None: if not keywords_regex(tag, self.tag_keywords): match_condition = False self.pre_line_match = False else: self.pre_line_match = True if self.line_keywords is not None: if not keywords_regex(line, self.line_keywords): match_condition = False self.pre_line_match = False else: self.pre_line_match = True if match_condition and tag is None and not self.pre_line_match: match_condition = False # if 'special world' in line: # match_precondition = True if not match_condition: return None, None, None msgkey = None # the handled current line linebuf = '' # time if time is not None: time = time[-TIME_WIDTH:].rjust(TIME_WIDTH) linebuf += time linebuf += ' ' elif self.regex_parser.is_contain_time(): linebuf += ' ' * TIME_WIDTH linebuf += ' ' # thread if thread is not None: thread = thread.strip() thread = thread[-THREAD_WIDTH:].rjust(THREAD_WIDTH) linebuf += thread linebuf += ' ' elif self.regex_parser.is_contain_thread(): linebuf += ' ' * THREAD_WIDTH linebuf += ' ' # tag if tag is not None and (not self.hide_same_tags or tag != self.last_tag): self.last_tag = tag tag = tag.strip() color = allocate_color(tag) tag = tag.strip() tag = tag[-TAG_WIDTH:].rjust(TAG_WIDTH) linebuf += colorize(tag, fg=color) linebuf += ' ' elif self.regex_parser.is_contain_tag(): linebuf += ' ' * TAG_WIDTH linebuf += ' ' # level if level is not None: if level in TAGTYPES: linebuf += TAGTYPES[level] else: linebuf += ' ' + level + ' ' linebuf += ' ' elif self.regex_parser.is_contain_level(): linebuf += ' ' linebuf += ' ' # message # -separator if self.separator is not None: msgkey = self.separator.process(message) # -trans if self.trans is not None: message = self.trans.trans_msg(message) message = self.trans.hide_msg(message) message = self.trans.trans_tag(tag, message) if self.highlight_list is not None: for highlight in self.highlight_list: if highlight in message: message = message.replace( highlight, termcolor(fg=BLACK, bg=allocate_color(highlight)) + highlight + RESET) linebuf += message return msgkey, linebuf, match_condition
def main(): tester = Trans() #Basic Tests #tester.run(3000, 0, "test.txt", False) #tester.run(3000, .1, "test.txt", False) #tester.run(3000, .2, "test.txt", False) #tester.run(3000, .5, "test.txt", False) #tester.run(10000, 0, "internet-architecture.pdf", False) #tester.run(10000, .1, "internet-architecture.pdf", False) #Fast Retransmit tester.run(10000, 0, "internet-architecture.pdf", True) tester.run(10000, .2, "internet-architecture.pdf", True) tester.run(10000, .2, "internet-architecture.pdf", False) #Experiments file_size = os.path.getsize("internet-architecture.pdf") data = [] time1 = tester.run(1000, 0, "internet-architecture.pdf", False) data.append((1000, file_size/time1)) time2 = tester.run(2000, 0, "internet-architecture.pdf", False) data.append((2000, file_size/time2)) time3 = tester.run(5000, 0, "internet-architecture.pdf", False) data.append((5000, file_size/time3)) time4 = tester.run(10000, 0, "internet-architecture.pdf", False) data.append((10000, file_size/time4)) time5 = tester.run(15000, 0, "internet-architecture.pdf", False) data.append((15000, file_size/time5)) time6 = tester.run(20000, 0, "internet-architecture.pdf", False) data.append((20000, file_size/time6)) segments = file_size / 1000 data2 = [] data2.append((1000, time1 - time6 / segments)) data2.append((2000, time2 - time6 / segments)) data2.append((5000, time3 - time6 / segments)) data2.append((10000, time4 - time6 / segments)) data2.append((15000, time5 - time6 / segments)) data2.append((20000, time6 - time6 / segments)) df = pd.DataFrame(data = data, columns=['Window Size', 'Throughput']).sort_values(by=['Window Size', 'Throughput'], ascending=[True, True]) plt.figure() ax = df.plot(x="Window Size",y="Throughput", color="green", label="Experimental") ax.set_ylabel("Throughput") ax.set_xlabel("Window Size") fig = ax.get_figure() fig.savefig('window_size.png') df = pd.DataFrame(data = data, columns=['Window Size', 'Queueing Delay']).sort_values(by=['Window Size', 'Queueing Delay'], ascending=[True, True]) plt.figure() ax = df.plot(x="Queueing Delay",y="Window Size", color="blue") ax.set_ylabel("Queueing Delay") ax.set_xlabel("Window Size") fig = ax.get_figure() fig.savefig('queueing_delay.png')
from trans import Trans rotate_obj = Trans() print("2d rotation:") print(rotate_obj.rotate_2d(30)) print("\n3d rotation (x):") print(rotate_obj.rotate_x_3d(45)) print("\n3d rotation (y):") print(rotate_obj.rotate_y_3d(45)) print("\n3d rotation (z):") print(rotate_obj.rotate_z_3d(45)) print("\n") print(rotate_obj.rotation_matrix(rotate_obj.rotate_x_3d(45),rotate_obj.rotate_y_3d(45)))