Commit 62768e5d authored by Alexander's avatar Alexander

loading agi clusters from mongodb in swagger endpoint

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