def word_vector(self, strx, stry): NVframe = DataFrame(self.data_oversam,columns=[strx, stry]) NVframe[u'case']= NVframe[strx]+'_'+NVframe[stry] casecounts = NVframe[u'case'].value_counts() NVframe = NVframe.reset_index() del NVframe[u'index'] Count_ob = Count() count = Count_ob.casecount(NVframe, casecounts) NVframe[u'count']= count NVframe = NVframe[NVframe[u'case'].notnull()] NVframe = NVframe.drop_duplicates() NVframe=NVframe.set_index([strx, stry]) del NVframe[u'case'] NVframe = NVframe.unstack() NVframe = NVframe.fillna(0) NVframe.columns = NVframe.columns.get_level_values(1) NVframe = NVframe.div(NVframe.sum(1),axis=0) #NVframeが共起頻度行列 #標準化処理 SVD_ob = SVD() Uframe,Vframe,Sframe = SVD_ob.SVD_run(NVframe) Sframe.plot() plt.plot( Sframe, 'o') #print Sframe #print Vframe m = Uframe.mean(0) s = Uframe.std(0) nd = Uframe nd = Uframe.sub(m,axis=1).div(s,axis=1) SN = SVD_ob.sf(Sframe) return nd, SN
def test_add(self): try: j = Count(2, 4) add = j.add() assert (add == 6), 'Integer addition result error!' except AssertionError, msg: print msg
def __init__(self, param=None): self.HOME_PATH = param self.mct = MCTS(5, MCTconfig()) self.gr = GR() self.gcnt = Count() self.epsilon = 0.3 # epsilon greedy self.mem = BrainMemory(50, self.HOME_PATH)
def countXY(feature_num): lisan=1000 #离散区间 dotnum=500 #打点人数 limitPersent=0.99; count=Count() file=FileDeal(); file.load('./line_road.txt'); list = file.getRow() allrow=file.getCol(list,feature_num+1,','); # ret,mapnum = count.changenum(allrow,lisan) # ret=count.lisan(ret,0,100000); res=count.countList(allrow) # res=count.sortedDictValues(res); xlist,ylist,xdot,ydot,dotstr=count.dictChange(res,dotnum) msg=count.getcacluate(xlist,ylist); # xlist,ylist,xdot,ydot,dotstr=count.returnXY(res,dotnum) # print xlist,ylist; # num,index,msgold=count.countpersen(xlist,ylist,limitPersent,mapnum)#百分比mapnum plot=Plot(); # msg=msgold # msg.insert(0,'limit'+str(limitPersent)+'--'+str(index)+'--'+str(num)) # msg=plot.arrToString(msgold) plot.setXY(xlist,ylist) name='feature_'+str(feature_num) plot.setTitle(name) plot.setdot(xdot,ydot,dotstr); # plot.printRight(msg) """
def test_add(self): try: j = Count(2, 4) add = j.add() assert (add == 6), 'Integer addition result error!' except AssertionError as msg: print(msg) else: print('test pass!')
def test_add(self): try: j = Count(2, 3) add = j.add() assert (add == 6), 'ERROR' except AssertionError as msg: print(msg) else: print('Pass!')
def test_a_add2(self): #测试步骤 count = Count() result = count.add(1.1, 2.13) #实际结果 actual_result = float(result) #预期结果 expect_reuslt = 3.23 #断言 self.assertEqual(expect_reuslt, actual_result)
def test_b_add1(self): #测试步骤 count = Count() result = count.add(1, 2) #实际结果 actual_result = result #预期结果 expect_result = 3 #断言 self.assertEqual(expect_result, actual_result)
def test_sub1(self): #测试步骤 count = Count() result = count.sub(3,1) #实际结果 actual_result = result #预期结果 expect_result = 2 #断言 self.assertEqual(actual_result,expect_result)
def test_sub2(self): #测试步骤 count = Count() result = count.sub(3.1,2.1) #实际结果 actual_reuslt = result #预期结果 expect_result = 1 #断言 self.assertEqual(actual_reuslt,expect_result)
def test_add2(self): #测试步骤 count = Count() result = count.add(1.1, 3) #实际结果 actual_result = float(result) #预期结果 expect_result = 4.1 #断言 self.assertEqual(actual_result, expect_result)
def __init__(self): self.gcnt = Count() self.status = 1 # 1 init, -1 thinking, 0 need action self.turn = 1 # white move global globalsig self.oldsig = globalsig self.ui = ChessBoard() self.HOME_PATH = copy.deepcopy(self.ui.HOME_PATH) self.brain = Brain(copy.deepcopy(self.HOME_PATH)) self.checkStatus() self.ui.mainloop()
def generate_words(self): c = Count(len(self.word)) if self.mode == UPTO_LENGTH: for i in range(1, self.length + 1): c.feed_zeroes(i) l = c.get_digits() for j in range(len(self.word)**i): self.words.append([self.word[k] for k in l]) l = c.increment_by(1) else: c.feed_zeroes(self.length) l = c.get_digits() for i in range(len(self.word)**self.length): self.words.append([self.word[k] for k in l]) l = c.increment_by(1) return self.words
def test1(self): count = Count(2, 3) self.add = count.add() self.assertEqual(self.add, 5)
def test_add1(self): count = Count(1.2, 2.3) add = count.add() self.assertEqual(add, 3.5)
def test_sub(self): self.Count = Count(6, 4) self.assertEqual(self.Count.sub(), 2)
def setUp(self): self.j = Count(2, 3)
def test_subtraction2(self): self.j = Count(4.2, 2.2) self.sub = self.j.subtraction() self.assertEqual(self.sub, 2)
def test_add(self): self.Count = Count(2,4) self.assertEqual(self.Count.add(),6)
def testsub2(self): '''测试30-50=-20 可以在html文件中显示''' j = Count(30, 50) self.assertEqual(j.sub(), -20)
def test_add3(self): self.j = Count("hello"," world") self.add = self.j.add() self.assertEqual(self.add,"hello world")
def test_sub1(self): k = Count(5.0, 3.0) sub = k.sub() self.assertEqual(sub, 2.0)
def testsub1(self): '''测试2-3=-1 可以在html文件中显示''' j = Count(2, 3) self.assertEqual(j.sub(), -1)
def test_sub2(self): k = Count(5, 3) sub = k.sub() self.assertEqual(sub, 2)
def main(): # get the size of the terminal (number of rows and columns) row, col = shutil.get_terminal_size() # the exception list of counting keys in the log exception_list = config['exception_elements'] # format [style, fg_color, bg_color] color = [ config['chart']['bar']['text_style'], config['chart']['bar']['fg_color'], config['chart']['bar']['bg_color'] ] # argument parser parser = argparse.ArgumentParser( description='The Apache access.log file parser') parser.add_argument('-f', '--file', metavar='[PATH_to_FILE]', required=True, help='[Required] Path to the Apache log file') parser.add_argument( '-l', '--line', metavar='[No_of_LINES]', type=int, help= '[Optional] Set the number of the lines to be parsed from the begining of the file.' ) parser.add_argument( '-e', '--element', metavar='[ELEMENT_NAME]', required=True, help= '[Required] Report based on the selected element. Separate multiple elements with comma (",") and no space.' ) parser.add_argument( '-c', '--chart', metavar='[YES|NO]', default='yes', help='[Optional] Draw charts or just show the statistics.') parser.add_argument( '-ne', '--number_element', metavar='[No_of_ELEMENTS]', type=int, default=10, help='[Optional] Show the number of top elements. Default: 10') parser.add_argument( '-nm', '--number_month', metavar='[No_of_MONTH]', type=int, default=3, help= '[Optional] Show the number of top months. Any minus number means not categorization by month. Default: 3' ) parser.add_argument( '-se', '--sort_element', metavar='[ASC|DES]', default='des', help='[Optional] Sort data ascendingly or desendingly. Default: des') parser.add_argument( '-sm', '--sort_month', metavar='[ASC|DES]', default='asc', help= '[Optional] Sort monthly-based data (just months) ascendingly or desendingly. Default: asc' ) # # initiate variables args = parser.parse_args() print('\n{0}\n'.format(args)) if not args.file: print("Please set the file path; the app won't work without it.") # set the maximum line of the file if args.line: max_line = args.line elif int(config['lines_to_parse']) > 0: max_line = int(config['lines_to_parse']) else: # max_line = sum(1 for line in open(args.file)) max_line = -1 # parse the log file log = data_parser(args, max_line, exception_list) # set a variable for the Count and DrawChart classes count = Count(log, exception_list) chart = DrawChart(color, config['chart']['bar']['tick'], args.chart, row, col) # iterate over elements defined by the user for element in args.element.split(','): # draw charts for the top defined number of months # or ignore categorizing by months if args.number_month > 0: # count log items counted_data = count.by_month() # sort counted data based on months sorted_data = count.sort(counted_data, args.sort_month, 'key', args.number_month) # if it is going to give data related to visitors (total and unique) if element in ['visitor']: # # draw the chart chart.bar_visitor(counted_data, element) else: sorted_data_element = {} # sort inner data based on selected element for month in sorted_data.keys(): sorted_data_element[month] = count.sort( counted_data[month][element], args.sort_element, 'value', args.number_element) # draw the chart print( '\n\n\033[0;30;43m Statistics of "{0}" (Unique: {1} ({2}%) | All: {3}) \033[0;0;0m' .format( element, len(counted_data[month][element].keys()), round( len(counted_data[month][element].keys()) * 100 / sum(counted_data[month][element].values()), 2), sum(counted_data[month][element].values()))) chart.bar_by_month(sorted_data_element, element) else: # shows the error if there is inconsistency if (args.number_month <= 0) and (element == 'hits'): print( 'Number of hits will be shown only in the monthly format. So, the value of "-mn" or "--number_month" should be higher than 0.' ) continue # count log items counted_data = count.total() # sort inner data based on selected element sorted_data = count.sort(counted_data[element], args.sort_element, 'value', args.number_element) # draw the chart print( '\n\n\033[0;30;43m Statistics of "{0}" (Unique: {1} ({2}%) | All: {3}) \033[0;0;0m' .format( element, len(counted_data[element].keys()), round( len(counted_data[element].keys()) * 100 / sum(counted_data[element].values()), 2), sum(counted_data[element].values()))) chart.bar(sorted_data, element) # print some lines to make some space print('\n\n\n')
def testAdd2(self): a2 = Count(1, 9) self.assertEqual(a2.add(), 10)
def test_add2(self): count = Count("hello", " world") add = count.add() self.assertEqual(add, "hello world")
def test_subtraction(self): self.j = Count(2, 3) self.sub = self.j.subtraction() self.assertEqual(self.sub, -1)
def test_add(self): self.j = Count(2,3) self.add = self.j.add() self.assertEqual(self.add,5)
def test_add2(self): self.j = Count(2.3,4.2) self.add = self.j.add() self.assertEqual(self.add,6.5)