Commit 8287b767 authored by Alexander's avatar Alexander

storing location and time clusters independently

parent c94aba76
...@@ -16,7 +16,8 @@ class Repository(MongoRepositoryBase): ...@@ -16,7 +16,8 @@ class Repository(MongoRepositoryBase):
netconst.COMMUNITY_DETECTION_DB_PORT, 'communityDetectionDb') netconst.COMMUNITY_DETECTION_DB_PORT, 'communityDetectionDb')
self._location_collection = 'location_agi' if agi_data else 'location' self._location_collection = 'location_agi' if agi_data else 'location'
self._cluster_collection = 'cluster_agi' if agi_data else 'cluster' self._location_cluster_collection = 'location_cluster_agi' if agi_data else 'location_cluster'
self._time_cluster_collection = 'time_cluster_agi' if agi_data else 'time_cluster'
self.agi_repo = AgiRepository() self.agi_repo = AgiRepository()
...@@ -31,12 +32,19 @@ class Repository(MongoRepositoryBase): ...@@ -31,12 +32,19 @@ class Repository(MongoRepositoryBase):
agi_locations = self.agi_repo.getLocations() agi_locations = self.agi_repo.getLocations()
return [Location(agi_loc) for agi_loc in agi_locations] return [Location(agi_loc) for agi_loc in agi_locations]
def add_user_cluster(self, cluster: UserCluster): def add_location_cluster(self, cluster: UserCluster):
super().insert_entry(self._cluster_collection, cluster.to_serializable_dict(for_db=True)) super().insert_entry(self._location_cluster_collection, cluster.to_serializable_dict(for_db=True))
def get_user_clusters(self) -> List[UserCluster]: def get_location_clusters(self) -> List[UserCluster]:
clusters = super().get_entries(self._cluster_collection) clusters = super().get_entries(self._location_cluster_collection)
return [UserCluster(c['date'], int(c['hour']), json.loads(c['clusters'])) for c in clusters] return [UserCluster(c['cluster_label'], json.loads(c['clusters'])) for c in clusters]
def add_time_cluster(self, cluster: UserCluster):
super().insert_entry(self._time_cluster_collection, cluster.to_serializable_dict(for_db=True))
def get_time_clusters(self) -> List[UserCluster]:
clusters = super().get_entries(self._time_cluster_collection)
return [UserCluster(c['cluster_label'], json.loads(c['clusters'])) for c in clusters]
def add_popular_location(self, popular_location: PopularLocation): def add_popular_location(self, popular_location: PopularLocation):
pass pass
...@@ -8,7 +8,7 @@ repo = Repository(agi_data=True) ...@@ -8,7 +8,7 @@ repo = Repository(agi_data=True)
clusterer = Clusterer() clusterer = Clusterer()
def get(): def get():
clusters = repo.get_user_clusters() clusters = repo.get_location_clusters()
return [c.to_serializable_dict() for c in clusters] return [c.to_serializable_dict() for c in clusters]
def get_image(): def get_image():
......
...@@ -8,7 +8,7 @@ repo = Repository() ...@@ -8,7 +8,7 @@ repo = Repository()
clusterer = Clusterer() clusterer = Clusterer()
def get(): def get():
clusters = repo.get_user_clusters() clusters = repo.get_location_clusters()
return [c.to_serializable_dict() for c in clusters] return [c.to_serializable_dict() for c in clusters]
def get_image(): def get_image():
......
...@@ -39,7 +39,8 @@ def run_time_clustering(): ...@@ -39,7 +39,8 @@ def run_time_clustering():
clusters = [UserCluster(key, value) clusters = [UserCluster(key, value)
for key, value in cluster_result.items()] for key, value in cluster_result.items()]
store_user_clusters(clusters) for c in clusters:
repo.add_time_cluster(c)
def store_user_clusters(user_clusters: List[UserCluster]): def store_user_clusters(user_clusters: List[UserCluster]):
...@@ -48,7 +49,7 @@ def store_user_clusters(user_clusters: List[UserCluster]): ...@@ -48,7 +49,7 @@ def store_user_clusters(user_clusters: List[UserCluster]):
return return
for c in user_clusters: for c in user_clusters:
repo.add_user_cluster(c) repo.add_location_cluster(c)
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment