Commit 62768e5d authored by Alexander's avatar Alexander

loading agi clusters from mongodb in swagger endpoint

parent db393636
...@@ -29,7 +29,7 @@ paths: ...@@ -29,7 +29,7 @@ paths:
200: 200:
description: "Successful echo of request data" description: "Successful echo of request data"
/location: /locations:
post: post:
operationId: "rest.location.post" operationId: "rest.location.post"
tags: tags:
...@@ -59,25 +59,25 @@ paths: ...@@ -59,25 +59,25 @@ paths:
schema: schema:
$ref: "#/definitions/Location" $ref: "#/definitions/Location"
/cluster: /clusters:
get: get:
operationId: "rest.cluster.get" operationId: "rest.cluster.get"
tags: tags:
- "Clusters" - "Clusters"
summary: "Get clustered data" summary: "Get user communities per date per hour"
parameters: [] parameters: []
responses: responses:
200: 200:
description: "Successful operation" description: "Successful operation"
schema: schema:
$ref: "#/definitions/ClusterValue" $ref: "#/definitions/UserCluster"
/cluster/cluster.png: /clusters/cluster.png:
get: get:
operationId: "rest.cluster.get_image" operationId: "rest.cluster.get_image"
tags: tags:
- "Clusters" - "Clusters"
summary: "Get clustered data as image" summary: "Get user communities per date per hour as image"
parameters: [] parameters: []
produces: produces:
- "image/png" - "image/png"
...@@ -85,26 +85,25 @@ paths: ...@@ -85,26 +85,25 @@ paths:
200: 200:
description: "Successful operation" description: "Successful operation"
/agi/clusters:
/agi/cluster:
get: get:
operationId: "rest.agi_cluster.get" operationId: "rest.agi_cluster.get"
tags: tags:
- "Clusters" - "Clusters"
summary: "Get clustered data" summary: "Get user communities per date per hour from agi data"
parameters: [] parameters: []
responses: responses:
200: 200:
description: "Successful operation" description: "Successful operation"
schema: schema:
$ref: "#/definitions/ClusterValue" $ref: "#/definitions/UserCluster"
/agi/cluster/cluster.png: /agi/clusters/cluster.png:
get: get:
operationId: "rest.agi_cluster.get_image" operationId: "rest.agi_cluster.get_image"
tags: tags:
- "Clusters" - "Clusters"
summary: "Get clustered data as image" summary: "Get user communities per date per hour from agi data as image"
parameters: [] parameters: []
produces: produces:
- "image/png" - "image/png"
...@@ -118,29 +117,32 @@ definitions: ...@@ -118,29 +117,32 @@ definitions:
properties: properties:
id: id:
type: string type: string
format: uuid username:
user:
type: "string" type: "string"
latitude: latitude:
type: "number" type: "number"
format: float
longitude: longitude:
type: "number" type: "number"
format: float
timestamp: timestamp:
type: "number" type: "number"
ClusterValue:
UserCluster:
type: "object" type: "object"
properties: properties:
id: id:
type: string type: string
format: uuid date:
cluster_label:
type: number
latitude:
type: number
longitude:
type: number
timestamp:
type: number
user:
type: string type: string
hour:
type: number
clusters:
type: object
additionalProperties:
type: array
items:
type: string
example:
0: [1dc61b1a0602de0eaee9dba7eece9279c2844202, b4b31bbe5e12f55737e3a910827c81595fbca3eb]
\ No newline at end of file
...@@ -3,7 +3,7 @@ from typing import List, Dict ...@@ -3,7 +3,7 @@ from typing import List, Dict
import hashlib import hashlib
class AgiRepository: class AgiRepository:
def getLocations(self) -> List: def getLocations(self) -> List[Dict]:
locations = [] locations = []
travels = self.readDataFromFile() travels = self.readDataFromFile()
......
...@@ -11,12 +11,12 @@ from typing import List ...@@ -11,12 +11,12 @@ from typing import List
class Repository(MongoRepositoryBase): class Repository(MongoRepositoryBase):
def __init__(self): def __init__(self, agi_data=False):
super().__init__(netconst.COMMUNITY_DETECTION_DB_HOSTNAME, super().__init__(netconst.COMMUNITY_DETECTION_DB_HOSTNAME,
netconst.COMMUNITY_DETECTION_DB_PORT, 'communityDetectionDb') netconst.COMMUNITY_DETECTION_DB_PORT, 'communityDetectionDb')
self._location_collection = 'location' self._location_collection = 'location_agi' if agi_data else 'location'
self._cluster_collection = 'cluster' self._cluster_collection = 'cluster_agi' if agi_data else 'cluster'
self.agi_repo = AgiRepository() self.agi_repo = AgiRepository()
......
import io import io
from flask import request, Response from flask import request, Response
from db.agi.agi_repository import AgiRepository from db.repository import Repository
from processing.clusterer import Clusterer from processing.clusterer import Clusterer
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
repo = AgiRepository() repo = Repository(agi_data=True)
clusterer = Clusterer() clusterer = Clusterer()
def get(): def get():
locations = repo.getLocations() clusters = repo.get_user_clusters()
return [c.to_serializable_dict() for c in clusters]
clusters = clusterer.run(locations)
return clusters
def get_image(): def get_image():
return Response(status=501)
# todo
locations = repo.getLocations() locations = repo.getLocations()
fig = clusterer.draw_locations(locations) fig = clusterer.draw_locations(locations)
......
...@@ -13,6 +13,7 @@ def get(): ...@@ -13,6 +13,7 @@ def get():
def get_image(): def get_image():
return Response(status=501) return Response(status=501)
# todo
locations = repo.getLocations() locations = repo.getLocations()
......
import sys
import os
modules_path = '../../../modules/'
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
from processing.clusterer import Clusterer from processing.clusterer import Clusterer
from db.repository import Repository from db.repository import Repository
from datetime import datetime, timedelta from datetime import datetime, timedelta
...@@ -17,10 +23,10 @@ user_clusterer = Clusterer() ...@@ -17,10 +23,10 @@ user_clusterer = Clusterer()
time_slices = list(range(24)) time_slices = list(range(24))
repo = Repository() repo = Repository(agi_data=True)
def run_clustering(): def run_location_clustering():
user_clusters: List[UserCluster] = [] user_clusters: List[UserCluster] = []
popular_locations: List[PopularLocation] = [] popular_locations: List[PopularLocation] = []
...@@ -135,4 +141,4 @@ def store_popular_locations(popular_locations: List[PopularLocation]): ...@@ -135,4 +141,4 @@ def store_popular_locations(popular_locations: List[PopularLocation]):
if __name__ == "__main__": if __name__ == "__main__":
run_clustering() run_location_clustering()
### inside k8s ## Rabbit MQ
RABBIT_MQ_HOSTNAME = 'rabbit-mq' RABBIT_MQ_HOSTNAME = 'rabbit-mq'
RABBIT_MQ_PORT = 5672 RABBIT_MQ_PORT = 5672
# RABBIT_MQ_HOSTNAME = 'articonf1.itec.aau.at'
# RABBIT_MQ_PORT = 30302
MONGO_DB_HOSTNAME = 'trace-retrieval-db' ## Trace Retrieval
MONGO_DB_PORT = 27017
TRACE_RETRIEVAL_HOSTNAME = 'trace-retrieval' TRACE_RETRIEVAL_HOSTNAME = 'trace-retrieval'
TRACE_RETRIEVAL_REST_PORT = 80 TRACE_RETRIEVAL_REST_PORT = 80
TRACE_RETRIEVAL_DB_HOSTNAME = 'trace-retrieval-db'
TRACE_RETRIEVAL_DB_PORT = 27017
# TRACE_RETRIEVAL_DB_HOSTNAME = 'articonf1.itec.aau.at'
# TRACE_RETRIEVAL_DB_PORT = 30003
### outside k8s ## Community Detection
# HOST_IP = '143.205.173.102' COMMUNITY_DETECTION_HOSTNAME = 'community-detection'
COMMUNITY_DETECTION_REST_PORT = 80
# RABBIT_MQ_HOSTNAME = HOST_IP COMMUNITY_DETECTION_DB_HOSTNAME = 'community-detection-db'
# RABBIT_MQ_PORT = 30302 COMMUNITY_DETECTION_DB_PORT = 27017
# COMMUNITY_DETECTION_DB_HOSTNAME = 'localhost'
# MONGO_DB_HOSTNAME = HOST_IP # COMMUNITY_DETECTION_DB_PORT = 30110
# MONGO_DB_PORT = 30003 \ No newline at end of file
# TRACE_RETRIEVAL_HOSTNAME = HOST_IP
# TRACE_RETRIEVAL_REST_PORT = 30001
\ No newline at end of file
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