Commit cc03bae0 authored by Alex's avatar Alex

Added rest route to individual layers and clustersets

parent 37cf0a63
......@@ -29,6 +29,8 @@ paths:
200:
description: "Successful echo of request data"
# Locations
# TODO remove
/locations:
post:
operationId: "routes.location.post"
......@@ -78,6 +80,7 @@ paths:
400:
description: "Invalid input"
# Layers
/layers:
post:
operationId: "routes.layers.post"
......@@ -90,7 +93,7 @@ paths:
description: "The layer data to be added"
required: true
schema:
$ref: "#/definitions/Layer"
$ref: "#/definitions/Layer-UpperCase"
responses:
201:
description: "Successful operation"
......@@ -106,8 +109,45 @@ paths:
200:
description: "Successful operation"
schema:
$ref: "#/definitions/Layer-pythonicCollection"
$ref: "#/definitions/LayerCollection"
/layers/names:
get:
operationId: "routes.layers.get_names"
tags:
- "Layers"
summary: "Get all layer names"
parameters: []
responses:
200:
description: "Successful operation"
schema:
type: array
items:
type: string
/layers/{name}:
get:
operationId: "routes.layers.get_by_name"
tags:
- "Layers"
summary: "Get layer data for layer-name"
parameters:
- name: "name"
in: "path"
description: "Name of the layer to return"
required: true
type: "string"
responses:
200:
description: "Successful operation"
schema:
$ref: "#/definitions/Layer"
404:
description: "Layer not found"
# Clusters
# TODO remove partially
/location-clusters:
get:
operationId: "routes.cluster.get_locations"
......@@ -160,6 +200,55 @@ paths:
# 200:
# description: "Successful operation"
/clustersets:
get:
operationId: "routes.clustersets.get"
tags:
- "Clusters"
summary: "Get clustersets for all layers"
parameters: []
responses:
200:
description: "Successful operation"
schema:
$ref: "#/definitions/ClusterSetCollection"
/clustersets/names:
get:
operationId: "routes.clustersets.get_names"
tags:
- "Clusters"
summary: "Get clusterset names for all layers"
parameters: []
responses:
200:
description: "Successful operation"
schema:
type: array
items:
type: string
/clustersets/{name}:
get:
operationId: "routes.clustersets.get_by_name"
tags:
- "Clusters"
summary: "Get clusterset for layer-name"
parameters:
- name: "name"
in: "path"
description: "Name of the layer to return the clusterset for"
required: true
type: "string"
responses:
200:
description: "Successful operation"
schema:
$ref: "#/definitions/ClusterSet"
404:
description: "Clusterset not found"
# TODO remove
/user-cluster-graphs:
get:
operationId: "routes.user_cluster.get"
......@@ -173,6 +262,7 @@ paths:
schema:
$ref: "#/definitions/UserClusterGraphCollection"
# Function Calls
/rfc/run:
post:
operationId: "routes.functions.run_agi_clustering_and_graph_creation"
......@@ -184,6 +274,7 @@ paths:
204:
description: "Successful operation"
definitions:
Location:
type: "object"
......@@ -206,6 +297,24 @@ definitions:
items:
$ref: "#/definitions/Location"
Cluster:
type: object
properties:
cluster_label:
type: number
nodes:
type: array
items:
type: object
example:
"Finished_time": 1576631193265951
"Latitude_Destination": -5.973257
"Longitude_Destination": 37.416316
"TravelID": "5e57ec9159bc0668543f156a"
"TravelPrice": 15
"UniqueID": "a95075f5042b1b27060080156d87fe34ec7e712c5e57ec9159bc0668543f156a"
"UserID": "a95075f5042b1b27060080156d87fe34ec7e712c"
LocationCluster:
type: object
properties:
......@@ -267,7 +376,7 @@ definitions:
items:
$ref: "#/definitions/UserClusterGraph"
Layer:
Layer-UpperCase:
type: object
properties:
LayerName:
......@@ -281,7 +390,7 @@ definitions:
items:
type: string
Layer-pythonic:
Layer:
type: object
properties:
layer_name:
......@@ -295,7 +404,22 @@ definitions:
items:
type: string
Layer-pythonicCollection:
LayerCollection:
type: array
items:
$ref: "#/definitions/Layer"
ClusterSet:
type: object
properties:
layer_name:
type: string
clusters:
type: array
items:
$ref: "#/definitions/Cluster"
ClusterSetCollection:
type: array
items:
$ref: "#/definitions/Layer-pythonic"
\ No newline at end of file
$ref: "#/definitions/ClusterSet"
\ No newline at end of file
......@@ -26,6 +26,7 @@ class Repository(MongoRepositoryBase):
self.agi_repo = AgiRepository()
#region Location
def add_location(self, location: Location):
super().insert_entry(self._location_collection, location.to_serializable_dict())
......@@ -36,7 +37,9 @@ class Repository(MongoRepositoryBase):
def get_agi_locations(self) -> List[Location]:
agi_locations = self.agi_repo.getLocations()
return [Location(agi_loc) for agi_loc in agi_locations]
#endregion
#region Specific Clusters
def add_location_cluster(self, cluster: LocationCluster):
super().insert_entry(self._location_cluster_collection,
cluster.to_serializable_dict(for_db=True))
......@@ -52,7 +55,9 @@ class Repository(MongoRepositoryBase):
def get_time_clusters(self) -> List[TimeCluster]:
clusters = super().get_entries(self._time_cluster_collection)
return [TimeCluster(time_dict=c, from_db=True) for c in clusters]
#endregion
#region Cluster Graph
def add_user_cluster_graph(self, user_graph: UserClusterGraph):
super().insert_entry(self._user_cluster_graph_collection,
user_graph.to_serializable_dict(for_db=True))
......@@ -60,7 +65,9 @@ class Repository(MongoRepositoryBase):
def get_user_cluster_graphs(self) -> List[UserClusterGraph]:
user_graphs = super().get_entries(self._user_cluster_graph_collection)
return [UserClusterGraph(dict_=u, from_db=True) for u in user_graphs]
#endregion
#region Layers
def add_layer(self, layer: Layer):
super().insert_entry(self._layer_collection, layer.to_serializable_dict())
......@@ -68,9 +75,38 @@ class Repository(MongoRepositoryBase):
entries = super().get_entries(self._layer_collection)
return [Layer(e) for e in entries]
def get_layer_names(self) -> List[str]:
entries = super().get_entries(self._layer_collection, projection={'layer_name': 1})
return [e['layer_name'] for e in entries]
def get_layer(self, layer_name) -> Layer:
entries = super().get_entries(self._layer_collection, selection={'layer_name': layer_name})
entries = [Layer(e) for e in entries]
if entries is not None and len(entries) > 0:
return entries[0]
else:
return None
#endregion
#region ClusterSet
def add_clusterset(self, cluster_set: ClusterSet):
super().insert_entry(self._clusterset_collection, cluster_set.to_serializable_dict())
def get_clustersets(self) -> List[ClusterSet]:
entries = super().get_entries(self._clusterset_collection)
return [ClusterSet(cluster_set_dict=e) for e in entries]
def get_clusterset_names(self) -> List[str]:
entries = super().get_entries(self._clusterset_collection, projection={'layer_name': 1})
return [e['layer_name'] for e in entries]
def get_clusterset(self, layer_name) -> ClusterSet:
entries = super().get_entries(self._clusterset_collection, selection={'layer_name': layer_name})
entries = [ClusterSet(cluster_set_dict=e) for e in entries]
if entries is not None and len(entries) > 0:
return entries[0]
else:
return None
#endregion
from flask import request, Response
from db.repository import Repository
from db.entities import ClusterSet
repo = Repository()
def get():
return [c.to_serializable_dict() for c in repo.get_clustersets()]
def get_names():
return repo.get_clusterset_names()
def get_by_name(name):
res = repo.get_clusterset(name)
if res is not None:
return res.to_serializable_dict()
else:
return Response(status=404)
\ No newline at end of file
......@@ -9,9 +9,6 @@ def post():
_insert_layer(body)
return Response(status=201)
def get():
return [l.to_serializable_dict() for l in repo.get_layers()]
def _insert_layer(layer_data: dict):
# convert object keys from ext source
layer_data['layer_name'] = layer_data.pop('LayerName')
......@@ -19,3 +16,16 @@ def _insert_layer(layer_data: dict):
layer_data['properties'] = layer_data.pop('Properties')
repo.add_layer(Layer(layer_data))
def get():
return [l.to_serializable_dict() for l in repo.get_layers()]
def get_names():
return repo.get_layer_names()
def get_by_name(name):
res = repo.get_layer(name)
if res is not None:
return res.to_serializable_dict()
else:
return Response(status=404)
\ 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