def setUp(self): super(RegionTest, self).setUp() self.uplaces = list() with open('place/samples/lonLat.txt') as f: for line in f.readlines(): uplace = UserPlace() uplace.lonLat = GEOSGeometry(line) uplace.value = uplace.lonLat uplace.timestamp = 1 self.uplaces.append(uplace)
def helper(vd, uplaces=None): if not uplaces: if not vd: raise NotImplementedError uplaces = list(get_proper_uplaces_qs(vd).exclude(lonLat=None)) for uplace in uplaces: uplace.value = uplace.lonLat uplace.timestamp = uplace.modified if len(uplaces) == 0: return None group0 = Group() group0.members = uplaces m_value = group0.lonLat from place.models import RADIUS_LOCAL_RANGE cluster = RegionClustering(group0, RADIUS_LOCAL_RANGE, distance_geography, m_value, True) cluster.run() elements = cluster.result for e in elements: e.type = 'lonLat' for i in [6, 5, 4]: group0 = Group() group0.members = elements m_value = group0.lonLat cluster = RegionClustering(group0, i*1000, distance_geography, m_value, True) cluster.run() cluster.result.sort(key=lambda g: g.count, reverse=True) for r in cluster.result: uplace = UserPlace(lonLat=r.lonLat) uplace.value = uplace.lonLat uplace.timestamp = 0 g = Group([uplace]) g.type = 'lonLat' elements.append(g) result = [member for member in cluster.result if member.count > 0] result.sort(key=lambda g: g.count, reverse=True) for g in result: g.distance = distance_geography return result