def get_all_articles(self): files = [os.path.join(self.source_path, f) for f in os.listdir( self.source_path) if f.endswith('.md')] # http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python # it's better to use basename: # make sure that same key in windows and linux maps = {os.path.basename(f): os.path.getctime(f) for f in files} persistence.persistence(maps, flag=True) func = lambda f: persistence.get(f, default=os.path.getctime(f)) files.sort(key=func, reverse=True) articles = [] for f in files: article = model.Article(*self._get_by_names(f)) articles.append(article) last = len(articles) - 1 for idx, article in enumerate(articles): if idx != 0: article.prev = articles[idx - 1] if idx != last: article.next = articles[idx + 1] return articles
def test_persistence(): assert persistence.persistence(39) == 3 assert persistence.persistence(4) == 0 assert persistence.persistence(25) == 2 assert persistence.persistence(999) == 4 assert persistence.persistence(-25) == 2 assert persistence.persistence(25.5) == 'Error: Input must be an integer'
def get_all_articles(self): files = [ os.path.join(self.source_path, f) for f in os.listdir(self.source_path) if f.endswith('.md') ] # http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python # it's better to use basename: # make sure that same key in windows and linux maps = {os.path.basename(f): os.path.getctime(f) for f in files} persistence.persistence(maps, flag=True) func = lambda f: persistence.get(f, default=os.path.getctime(f)) files.sort(key=func, reverse=True) articles = [] for f in files: article = model.Article(*self._get_by_names(f)) articles.append(article) last = len(articles) - 1 for idx, article in enumerate(articles): if idx != 0: article.prev = articles[idx - 1] if idx != last: article.next = articles[idx + 1] return articles
def run(f_name,path,save_path): data = np.load(path+f_name) tri_array = data['tri_array'] coord_array = data['coord_array'] data.close() # Calculate HKS steps = 0.001 iters = 1000 HKS = generate_hks.generate_hks(coord_array, tri_array, steps, iters) # Calculate persistence v = persistence.persistence(HKS) # get the connection matrix of points, and save in file 'connection_matrix_points.npy' adjpts = connection_matrix_point.connection_matrix(coord_array,tri_array) save_name = f_name[:-4] np.savez_compressed(save_path+save_name, persistence = v,adjpts=adjpts)
def __init__(self, entrance): if not os.path.exists(config.outputdir): os.mkdir(config.outputdir) self.__persistence = persistence.persistence("picpath/", "docpath/", "videopath/", "urlpath/", "datapath/") self.__useset = set() self.__usedset = set() self.__allurlset = set() # save domain all url self.__imgurlset = set() # save img url self.__entrance = entrance matchresule = re.compile(r'.\w*').search(self.__entrance) if matchresule: self.__domain = matchresule.group() self.__access_cnt = 0 self.__img_index = 0 socket.setdefaulttimeout(5)
def test_rand(self): for _ in range(50): n = randint(1, 500000) self.assertEqual(persistence(n), soluce(n), 'Random inputs should work too')
def test(self): self.assertEqual(persistence(39), 3, 'Basic test') self.assertEqual(persistence(4), 0, 'Basic test') self.assertEqual(persistence(25), 2, 'Basic test') self.assertEqual(persistence(999), 4, 'Basic test') self.assertEqual(persistence(444), 3, 'Basic test')
(f_name, np.shape(coord_array)[0], np.shape(tri_array)[0])) # Plot mesh to check #plot_mesh.plot_mesh(coord_array, tri_array) # Calculate HKS steps = 0.001 iters = 1000 HKS = generate_hks.generate_hks(coord_array, tri_array, steps, iters) # Plot HKS if required at iter n #n = [0, 10, 50, 299, 799] #plot_hks.plot_hks(coord_array, tri_array, HKS, n) # Calculate persistence v = persistence.persistence(HKS) # # Plot persistence value #plot_persistence.plot_persistence(coord_array, tri_array, v, 'value') #plot_persistence.plot_persistence(coord_array, tri_array, v, 'level') # get the connection matrix of points, and save in file 'connection_matrix_points.npy' connection_matrix_point.connection_matrix(coord_array, tri_array) # Find clusters #simil = [0.7, 0.75, 0.8, 0.85, 0.9] # Similarity percentages simil = 0.9 adjm = np.array([]) while adjm.shape[0] < 10: clusters = cluster.cluster(coord_array, tri_array, v, simil) cluster_adjmap = cluster.get_attributed_cluster_adj_matrix(
def test_persistence(): assert persistence(39) == 3 assert persistence(4) == 0 assert persistence(25) == 2 assert persistence(999) == 4 assert persistence(444) == 3
def test_2(self): result = persistence(4) self.assertEqual(result, 0)
def test_1(self): result = persistence(39) self.assertEqual(result, 3)