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
class AddTest(unittest.TestCase): #每一条用例执行之前都要做的操作可放到setUp def setUp(self): self.c = Count() print("start test") #每条用例执行之后的要做的操作放到tearDown def tearDown(self): print("end test") # 测试方法必须以test开头 def test_add_3_5(self): result = self.c.add(3, 5) # 断言结果是否=8 self.assertEqual(result, 8) # 预期结果和实际结果不符,会报failure(失败) def test_add_22_33(self): result = self.c.add(2.2, 3.3) self.assertEqual(result, 5) # 自己代码问题,会报失败,Error def test_add_hello(self): result = self.c.add() self.assertEqual(result, 5)
class TestCount(unittest.TestCase): def setUp(self): self.j = Count(2, 3) def test_add(self): '''This will be the description of the TestCase--test_add.''' self.add = self.j.add() self.assertEqual(self.add,5) print "Test is OK !" def test_add2(self): '''This will be the description of the TestCase--test_add2.''' self.add = self.j.add() self.assertEqual(self.add,2) print "Test is ERROR !" @unittest.skip("skip") def test_add3(self): '''This will be the description of the TestCase--test_add3.''' self.add = self.j.add() self.assertEqual(self.add,2) print "Test is ERROR !" def tearDown(self): pass
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 test_add(self): try: j = Count(2, 4) add = j.add() assert (add == 6), 'Integer addition result error!' except AssertionError, msg: print msg
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, 3) add = j.add() assert (add == 6), 'ERROR' except AssertionError as msg: print(msg) else: print('Pass!')
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, 4) add = j.add() assert (add == 6), 'Integer addition result error!' except AssertionError as msg: print(msg) else: print('test pass!')
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_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_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_sub1(self): #测试步骤 count = Count() result = count.sub(3,1) #实际结果 actual_result = result #预期结果 expect_result = 2 #断言 self.assertEqual(actual_result,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)
class TestCount(unittest.TestCase): def setUp(self): self.j = Count(2, 5) def test_add(self): self.add = self.j.add() self.assertEqual(self.add, 8) def test_sub(self): self.sub = self.j.sub() self.assertEqual(self.sub, -2) def tearDown(self): pass
class TestAdd(unittest.TestCase): def setUp(self): self.obj = Count() def tearDown(self): self.obj = None def add_test(self): print 'run add_test' print self.obj.add(10, 20) == 30 def sub_test(self): print 'run sub_test' print self.obj.sub(10, 5) == 5
class subTest(unittest.TestCase): def setUp(self): self.c = Count() print("start test") def tearDown(self): print("end test") def test_sub_3_5(self): result = self.c.sub(3, 5) self.assertEqual(result, -2) def test_sub_5_3(self): result = self.c.sub(5, 3) self.assertEqual(result, 2)
class TestSubtraction(unittest.TestCase): def setUp(self): pass #测试整数相减 def test_subtraction(self): self.j = Count(2,3) self.sub = self.j.subtraction() self.assertEqual(self.sub,-1) #测试小数相减 def test_subtraction2(self): self.j = Count(4.2,2.2) self.sub = self.j.subtraction() self.assertEqual(self.sub,2) def tearDown(self): pass
def from_array(cls, ar, number, boozedir): if len(ar)==0 or len(ar[0])==0 or ar[0][0].lower()!="bar": raise MildErr("Missing 'bar' title") if len(ar)==1 or len(ar[1])<6: raise MildErr("Incomplete/missing header") # header: # pricelist; date ; counter ; shift# ; # startbal ; endbal [; mutation ] # # Here: mutation the amount transferred to the # cash register during the shift. For istance, # an "afroming" during a shift would lower this number. header = ar[1] pricelist_str = header[0] pricelist = boozedir.pricelistdir[pricelist_str] date = parse_moment(header[1]) counter = header[2] shift = Shift.from_str(header[3]) startbal = parse_decimal(header[4]) endbal = parse_decimal(header[5]) mutation = parse_decimal(header[6]) if len(header)>6 \ else Decimal(0) # below, to translate "product@pricelist" to a commodity commodity_view = boozedir.commoditydir.get_view(pricelist) sell_count = Count.from_array(ar[2:], commodity_view, parse_amount) event = boozedir.eventdir[date] return cls(event=event, counter=counter, shift=shift, startbal=startbal, endbal=endbal, sell_count=sell_count, number=number, pricelist=pricelist, mutation=mutation)
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 from_array(cls, ar, name, boozedir): if len(ar)==0 or len(ar[0])==0 or \ ar[0][0].lower()!="prijslijst": raise MildErr("Missing 'prijslijst' title") prices = Count.from_array(ar[1:], boozedir.productdir, parse_amount) return cls(name=name,prices=prices)
class Test_add(unittest.TestCase): def setUp(self): print('test start') def testadd(self): self.j = Count(2, 3) self.add = self.j.add() return self.assertEqual(self.add, 5) def testadd2(self): self.j = Count(45, 13) self.add = self.j.add() return self.assertEqual(self.add, 58) def tearDown(self): print('test end')
class Test_sub(unittest.TestCase): def setUp(self): print('test start') def testsub(self): self.j = Count(2, 3) self.sub = self.j.sub() return self.assertEqual(self.sub, -1) def testsub2(self): self.j = Count(21, 13) self.sub = self.j.sub() return self.assertEqual(self.sub, 8) def tearDown(self): print('test end')
class TestSubtraction(unittest.TestCase): def setUp(self): pass def test_sub(self): self.j = Count(2,3) self.sub = self.j.sub() self.assertEqual(self.sub,-1) def test_sub2(self): self.j = Count(2.5,1.5) self.sub = self.j.sub() self.assertEqual(self.sub,1.0) def tearDown(self): pass
class TestCount(unittest.TestCase): def setUp(self): #pass self.j = Count(2, 3) def test_add(self): #self.j=Count(2,3) self.add = self.j.add() self.assertEqual(self.add, 5, msg='相加不等于5') def test_add2(self): self.j = Count(2.3, 2.5) self.add = self.j.add() self.assertEqual(self.add, 6, msg='小数相加不等于6') def tearDown(self): pass
class TestCount(unittest.TestCase): def setUp(self): self.j = Count(2, 3) def test_add(self): self.add = self.j.add() self.assertAlmostEqual(self.add, 5) def tearDown(self): pass
class TestCount(unittest.TestCase): def setUp(self): pass #测试整数相加 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) #测试字符串相加 def test_add3(self): self.j = Count("hello"," world") self.add = self.j.add() self.assertEqual(self.add,"hello world") def tearDown(self): pass
def _load_btc_from_array(cls, ar, boozedir): if len(ar)==0: raise MildErr("beertankcount.csv has no header") if len(ar[0])==0 or ar[0][0].lower()!="tap": raise MildErr("beertankcount.csv has faulty header: " "%s" % ar[0]) count = Count.from_array(ar[1:], boozedir.eventdir, parse_amount) for event in count.countlets.iterkeys(): event.register_btc(count[event]) return count
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()
class TestCount(unittest.TestCase): def setup(self): pass 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.5,3.5) self.add = self.j.add() self.assertEqual(self.add,6.0) def test_add3(self): self.j = Count('hello','world') self.add = self.j.add() self.assertEqual(self.add,'helloworld') def teardown(self): pass
class MyTest(unittest.TestCase) : def tearDown(self): print('test end') def setUp(self): print('test start') @classmethod def tearDownClass(cls): print('all down') @classmethod def setUpClass(cls): print('all start') def test_add(self): self.Count = Count(2,4) self.assertEqual(self.Count.add(),6) def test_sub(self): self.Count = Count(6, 4) self.assertEqual(self.Count.sub(), 2)
def from_array(cls, ar, code, boozedir): if len(ar)==0 or len(ar[0])==0: raise MildErr("no title") if ar[0][0].lower()!="voorraadtelling": raise MildErr("title is not 'voorraadtelling'") if len(ar)==1 or len(ar[1])==0: raise MildErr("header is too small") header = ar[1] date = parse_moment(header[0]) event = boozedir.eventdir[date] count = Count.from_array(ar[2:], boozedir.productdir, parse_amount) return cls(code, event, count)
class Main_run(object): def __init__(self, city): self.req = Html_request(city) self.info = Html_parse() self.count = Count() self.mysql = Connent_mysql() def find(self, search_key, page, city, lat, lng, first, second, third, fouth, sign, price, sort): city_id = self.req.get_city_id() url_s = quote(search_key) # link 由 城市id 与 搜索关键词 组成 if sign == 4: price1 = int(price) - 20 price2 = int(price) + 20 link = "https://www.dianping.com/search/keyword/" + city_id + "/0_" + url_s + '/p' + str( page) + 'x' + str(price1) + 'y' + str(price2) elif sign == 1: link = "https://www.dianping.com/search/keyword/" + city_id + "/0_" + url_s + '/p' + str( page) else: link = "https://www.dianping.com/search/keyword/" + city_id + "/0_" + url_s + '/o' + sort + 'p' + str( page) #print(link) response = self.req.get_search_result(link) #title,address,score,comment_hack,price_hack,img_src title, address, score, comment_hack, price_hack, img_src = self.info.info_parse( response) # 获取 点评数量和评价的最大最小值 m_comment = [min(comment_hack), max(comment_hack)] m_score = [min(score), max(score)] # 加权计算 total_score = [] distance_list = [] for i in range(0, len(title)): t_score, distance = self.count.get_result( city, score[i], comment_hack[i], price_hack[i], address[i], lat, lng, first, second, third, fouth, price, m_comment, m_score) total_score.append(t_score) distance_list.append(distance) # 存储到数据库↓ for i in range(0, len(title)): self.mysql.mysql_insert(title[i], address[i], str(score[i]), str(comment_hack[i]), price_hack[i], img_src[i], total_score[i], distance_list[i])
def from_array(cls, ar, code, boozedir, board): if len(ar)==0 or len(ar[0])==0: raise MildErr("no title") if ar[0][0].lower()!="levering": raise MildErr("title is not 'levering'") if len(ar)==1 or len(ar[1])<2: raise MildErr("header is too small") header = ar[1] try: pricelist = boozedir.pricelistdir[header[0]] except ObjDirErr: raise MildErr("could not find pricelist") date = parse_moment(header[1]) event = boozedir.eventdir[date] description = header[2].lower() if len(header)>=3 \ else None view = boozedir.commoditydir.get_view(pricelist) count = Count.from_array(ar[2:], view, parse_amount) return cls(code, event, description, count, board)
def test_add1(self): count = Count(1.2, 2.3) add = count.add() self.assertEqual(add, 3.5)
def test1(self): count = Count(2, 3) self.add = count.add() self.assertEqual(self.add, 5)
def count(self): """Collect results from rebuilt bug history. """ count = Count(config=self.config, cache=self.cache) # All count.run() count.run(all=True) for series in self.series_of_filters: for fil_type in series.keys(): for filter in series[fil_type]: count.add_filter(fil_type, filter) count.run() count.run(all=True) count.flush_filters()
def total_factors(self): if self._total_factors==None: self._total_factors = sum([bf.total_factors for bf in self.delivs.itervalues()], Count.zero(parse_amount)) return self._total_factors
def fdelivered(self): return sum(map(lambda dl: dl.total_factors, self.delivs), Count.zero(parse_amount))
def test_add2(self): count = Count("hello", " world") add = count.add() self.assertEqual(add, "hello world")
def setUp(self): self.j = Count(2, 3)
def ftallied(self): return sum(map(lambda bf: bf.total_factors, self.barforms), Count.zero(parse_amount))
def total_sold(self): if self._total_sold==None: self._total_sold = sum([bf.sell_count for bf in self.all_barforms], Count.zero(parse_amount)) return self._total_sold
def total_factors(self): if self._total_factors==None: self._total_factors = sum([bf.total_factors for bf in self.barforms.values()], Count.zero(int)) return self._total_factors