Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
cc03bae0
Commit
cc03bae0
authored
Mar 31, 2020
by
Alex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added rest route to individual layers and clustersets
parent
37cf0a63
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
199 additions
and
11 deletions
+199
-11
swagger.yml
.../community-detection-microservice/app/configs/swagger.yml
+131
-7
repository.py
...hub/community-detection-microservice/app/db/repository.py
+37
-1
clustersets.py
...ommunity-detection-microservice/app/routes/clustersets.py
+18
-0
layers.py
...hub/community-detection-microservice/app/routes/layers.py
+13
-3
No files found.
src/data-hub/community-detection-microservice/app/configs/swagger.yml
View file @
cc03bae0
...
@@ -29,6 +29,8 @@ paths:
...
@@ -29,6 +29,8 @@ paths:
200
:
200
:
description
:
"
Successful
echo
of
request
data"
description
:
"
Successful
echo
of
request
data"
# Locations
# TODO remove
/locations
:
/locations
:
post
:
post
:
operationId
:
"
routes.location.post"
operationId
:
"
routes.location.post"
...
@@ -78,6 +80,7 @@ paths:
...
@@ -78,6 +80,7 @@ paths:
400
:
400
:
description
:
"
Invalid
input"
description
:
"
Invalid
input"
# Layers
/layers
:
/layers
:
post
:
post
:
operationId
:
"
routes.layers.post"
operationId
:
"
routes.layers.post"
...
@@ -90,7 +93,7 @@ paths:
...
@@ -90,7 +93,7 @@ paths:
description
:
"
The
layer
data
to
be
added"
description
:
"
The
layer
data
to
be
added"
required
:
true
required
:
true
schema
:
schema
:
$ref
:
"
#/definitions/Layer"
$ref
:
"
#/definitions/Layer
-UpperCase
"
responses
:
responses
:
201
:
201
:
description
:
"
Successful
operation"
description
:
"
Successful
operation"
...
@@ -106,8 +109,45 @@ paths:
...
@@ -106,8 +109,45 @@ paths:
200
:
200
:
description
:
"
Successful
operation"
description
:
"
Successful
operation"
schema
:
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
:
/location-clusters
:
get
:
get
:
operationId
:
"
routes.cluster.get_locations"
operationId
:
"
routes.cluster.get_locations"
...
@@ -160,6 +200,55 @@ paths:
...
@@ -160,6 +200,55 @@ paths:
# 200:
# 200:
# description: "Successful operation"
# 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
:
/user-cluster-graphs
:
get
:
get
:
operationId
:
"
routes.user_cluster.get"
operationId
:
"
routes.user_cluster.get"
...
@@ -172,7 +261,8 @@ paths:
...
@@ -172,7 +261,8 @@ paths:
description
:
"
Successful
operation"
description
:
"
Successful
operation"
schema
:
schema
:
$ref
:
"
#/definitions/UserClusterGraphCollection"
$ref
:
"
#/definitions/UserClusterGraphCollection"
# Function Calls
/rfc/run
:
/rfc/run
:
post
:
post
:
operationId
:
"
routes.functions.run_agi_clustering_and_graph_creation"
operationId
:
"
routes.functions.run_agi_clustering_and_graph_creation"
...
@@ -184,6 +274,7 @@ paths:
...
@@ -184,6 +274,7 @@ paths:
204
:
204
:
description
:
"
Successful
operation"
description
:
"
Successful
operation"
definitions
:
definitions
:
Location
:
Location
:
type
:
"
object"
type
:
"
object"
...
@@ -206,6 +297,24 @@ definitions:
...
@@ -206,6 +297,24 @@ definitions:
items
:
items
:
$ref
:
"
#/definitions/Location"
$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
:
LocationCluster
:
type
:
object
type
:
object
properties
:
properties
:
...
@@ -267,7 +376,7 @@ definitions:
...
@@ -267,7 +376,7 @@ definitions:
items
:
items
:
$ref
:
"
#/definitions/UserClusterGraph"
$ref
:
"
#/definitions/UserClusterGraph"
Layer
:
Layer
-UpperCase
:
type
:
object
type
:
object
properties
:
properties
:
LayerName
:
LayerName
:
...
@@ -281,7 +390,7 @@ definitions:
...
@@ -281,7 +390,7 @@ definitions:
items
:
items
:
type
:
string
type
:
string
Layer
-pythonic
:
Layer
:
type
:
object
type
:
object
properties
:
properties
:
layer_name
:
layer_name
:
...
@@ -295,7 +404,22 @@ definitions:
...
@@ -295,7 +404,22 @@ definitions:
items
:
items
:
type
:
string
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
type
:
array
items
:
items
:
$ref
:
"
#/definitions/Layer-pythonic"
$ref
:
"
#/definitions/ClusterSet"
\ No newline at end of file
\ No newline at end of file
src/data-hub/community-detection-microservice/app/db/repository.py
View file @
cc03bae0
...
@@ -26,6 +26,7 @@ class Repository(MongoRepositoryBase):
...
@@ -26,6 +26,7 @@ class Repository(MongoRepositoryBase):
self
.
agi_repo
=
AgiRepository
()
self
.
agi_repo
=
AgiRepository
()
#region Location
def
add_location
(
self
,
location
:
Location
):
def
add_location
(
self
,
location
:
Location
):
super
()
.
insert_entry
(
self
.
_location_collection
,
location
.
to_serializable_dict
())
super
()
.
insert_entry
(
self
.
_location_collection
,
location
.
to_serializable_dict
())
...
@@ -36,7 +37,9 @@ class Repository(MongoRepositoryBase):
...
@@ -36,7 +37,9 @@ class Repository(MongoRepositoryBase):
def
get_agi_locations
(
self
)
->
List
[
Location
]:
def
get_agi_locations
(
self
)
->
List
[
Location
]:
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
]
#endregion
#region Specific Clusters
def
add_location_cluster
(
self
,
cluster
:
LocationCluster
):
def
add_location_cluster
(
self
,
cluster
:
LocationCluster
):
super
()
.
insert_entry
(
self
.
_location_cluster_collection
,
super
()
.
insert_entry
(
self
.
_location_cluster_collection
,
cluster
.
to_serializable_dict
(
for_db
=
True
))
cluster
.
to_serializable_dict
(
for_db
=
True
))
...
@@ -52,7 +55,9 @@ class Repository(MongoRepositoryBase):
...
@@ -52,7 +55,9 @@ class Repository(MongoRepositoryBase):
def
get_time_clusters
(
self
)
->
List
[
TimeCluster
]:
def
get_time_clusters
(
self
)
->
List
[
TimeCluster
]:
clusters
=
super
()
.
get_entries
(
self
.
_time_cluster_collection
)
clusters
=
super
()
.
get_entries
(
self
.
_time_cluster_collection
)
return
[
TimeCluster
(
time_dict
=
c
,
from_db
=
True
)
for
c
in
clusters
]
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
):
def
add_user_cluster_graph
(
self
,
user_graph
:
UserClusterGraph
):
super
()
.
insert_entry
(
self
.
_user_cluster_graph_collection
,
super
()
.
insert_entry
(
self
.
_user_cluster_graph_collection
,
user_graph
.
to_serializable_dict
(
for_db
=
True
))
user_graph
.
to_serializable_dict
(
for_db
=
True
))
...
@@ -60,7 +65,9 @@ class Repository(MongoRepositoryBase):
...
@@ -60,7 +65,9 @@ class Repository(MongoRepositoryBase):
def
get_user_cluster_graphs
(
self
)
->
List
[
UserClusterGraph
]:
def
get_user_cluster_graphs
(
self
)
->
List
[
UserClusterGraph
]:
user_graphs
=
super
()
.
get_entries
(
self
.
_user_cluster_graph_collection
)
user_graphs
=
super
()
.
get_entries
(
self
.
_user_cluster_graph_collection
)
return
[
UserClusterGraph
(
dict_
=
u
,
from_db
=
True
)
for
u
in
user_graphs
]
return
[
UserClusterGraph
(
dict_
=
u
,
from_db
=
True
)
for
u
in
user_graphs
]
#endregion
#region Layers
def
add_layer
(
self
,
layer
:
Layer
):
def
add_layer
(
self
,
layer
:
Layer
):
super
()
.
insert_entry
(
self
.
_layer_collection
,
layer
.
to_serializable_dict
())
super
()
.
insert_entry
(
self
.
_layer_collection
,
layer
.
to_serializable_dict
())
...
@@ -68,9 +75,38 @@ class Repository(MongoRepositoryBase):
...
@@ -68,9 +75,38 @@ class Repository(MongoRepositoryBase):
entries
=
super
()
.
get_entries
(
self
.
_layer_collection
)
entries
=
super
()
.
get_entries
(
self
.
_layer_collection
)
return
[
Layer
(
e
)
for
e
in
entries
]
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
):
def
add_clusterset
(
self
,
cluster_set
:
ClusterSet
):
super
()
.
insert_entry
(
self
.
_clusterset_collection
,
cluster_set
.
to_serializable_dict
())
super
()
.
insert_entry
(
self
.
_clusterset_collection
,
cluster_set
.
to_serializable_dict
())
def
get_clustersets
(
self
)
->
List
[
ClusterSet
]:
def
get_clustersets
(
self
)
->
List
[
ClusterSet
]:
entries
=
super
()
.
get_entries
(
self
.
_clusterset_collection
)
entries
=
super
()
.
get_entries
(
self
.
_clusterset_collection
)
return
[
ClusterSet
(
cluster_set_dict
=
e
)
for
e
in
entries
]
return
[
ClusterSet
(
cluster_set_dict
=
e
)
for
e
in
entries
]
\ No newline at end of file
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
src/data-hub/community-detection-microservice/app/routes/clustersets.py
0 → 100644
View file @
cc03bae0
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
src/data-hub/community-detection-microservice/app/routes/layers.py
View file @
cc03bae0
...
@@ -9,9 +9,6 @@ def post():
...
@@ -9,9 +9,6 @@ def post():
_insert_layer
(
body
)
_insert_layer
(
body
)
return
Response
(
status
=
201
)
return
Response
(
status
=
201
)
def
get
():
return
[
l
.
to_serializable_dict
()
for
l
in
repo
.
get_layers
()]
def
_insert_layer
(
layer_data
:
dict
):
def
_insert_layer
(
layer_data
:
dict
):
# convert object keys from ext source
# convert object keys from ext source
layer_data
[
'layer_name'
]
=
layer_data
.
pop
(
'LayerName'
)
layer_data
[
'layer_name'
]
=
layer_data
.
pop
(
'LayerName'
)
...
@@ -19,3 +16,16 @@ def _insert_layer(layer_data: dict):
...
@@ -19,3 +16,16 @@ def _insert_layer(layer_data: dict):
layer_data
[
'properties'
]
=
layer_data
.
pop
(
'Properties'
)
layer_data
[
'properties'
]
=
layer_data
.
pop
(
'Properties'
)
repo
.
add_layer
(
Layer
(
layer_data
))
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment