def test_stats(self): data = [(50, 0), (-50, 0), (0, -50), (0, 50)] data = [pgh.encode(lat, lon) for lat, lon in data] # mean mean = pgh.mean(data) self.assertEqual(mean, '7zzzzzzzzzzz') # north north = pgh.northern(data) self.assertEqual(north, 'gbzurypzpgxc') # south south = pgh.southern(data) self.assertEqual(south, '5zpgxczbzury') # east east = pgh.eastern(data) self.assertEqual(east, 'mpgxczbzuryp') # west west = pgh.western(data) self.assertEqual(west, '6zurypzpgxcz') var = pgh.variance(data) self.assertAlmostEqual(var, 30910779278721.996, places=2) std = pgh.std(data) self.assertAlmostEqual(std, 5559746.332227937, places=4)
def get_loacl_map(self, ghash1, ghash2): itr = (ghash1, ghash2) latu, *_ = decode_exactly(northern(itr)) latl, *_ = decode_exactly(southern(itr)) _, lonr, *_ = decode_exactly(eastern(itr)) _, lonl, *_ = decode_exactly(western(itr)) lonr += 0.2 lonl -= 0.2 latu += 0.2 latl -= 0.2 plogen = Path([(lonl, latl), (lonl, latu), (lonr, latu), (lonr, latl)]) allow = set() for i in self.d_gHash: info = decode_exactly(i) if plogen.contains_point((info[1], info[0])): allow.update(self.d_gHash[i]) nodes, adj_map = {}, {} for n in allow: if n not in nodes: nodes[n] = self.nodes[n] adj_map[n] = self.adj_map[n] for to_node, _ in self.adj_map[n]: if to_node not in nodes: nodes[to_node] = self.nodes[n] adj_map[to_node] = self.adj_map[to_node][:] for i, (tt, _) in enumerate(self.adj_map[to_node]): if tt not in allow: adj_map[to_node].remove((tt, _)) # return self.adj_map,self.nodes,self.records return adj_map, nodes, self.records
def test_stats(self): data = [(50, 0), (-50, 0), (0, -50), (0, 50)] data = [pgh.encode(lat, lon) for lat, lon in data] # mean mean = pgh.mean(data) self.assertEqual(mean, '7zzzzzzzzzzz') # north north = pgh.northern(data) self.assertEqual(north, 'gbzurypzpgxc') # south south = pgh.southern(data) self.assertEqual(south, '5zpgxczbzury') # east east = pgh.eastern(data) self.assertEqual(east, 'mpgxczbzuryp') # west west = pgh.western(data) self.assertEqual(west, '6zurypzpgxcz')