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
9a50d2ec
Commit
9a50d2ec
authored
Feb 10, 2020
by
Alexander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup and updated swagger docu
parent
1d90011e
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
113 additions
and
115 deletions
+113
-115
swagger.yml
.../community-detection-microservice/app/configs/swagger.yml
+63
-44
location_datastore.py
...unity-detection-microservice/app/db/location_datastore.py
+0
-24
repository.py
...hub/community-detection-microservice/app/db/repository.py
+14
-11
insert_agi_locations.py
...munity-detection-microservice/app/insert_agi_locations.py
+14
-0
agi_cluster.py
.../community-detection-microservice/app/rest/agi_cluster.py
+0
-24
cluster.py
...-hub/community-detection-microservice/app/rest/cluster.py
+19
-2
location.py
...hub/community-detection-microservice/app/rest/location.py
+3
-3
run_clustering.py
...ub/community-detection-microservice/app/run_clustering.py
+0
-7
No files found.
src/data-hub/community-detection-microservice/app/configs/swagger.yml
View file @
9a50d2ec
...
...
@@ -78,57 +78,57 @@ paths:
400
:
description
:
"
Invalid
input"
/clusters
:
/
location-
clusters
:
get
:
operationId
:
"
rest.cluster.get"
operationId
:
"
rest.cluster.get
_locations
"
tags
:
-
"
Clusters"
summary
:
"
Get
user
communities
per
date
per
hour
"
summary
:
"
Get
user
communities
clustered
by
location
"
parameters
:
[]
responses
:
200
:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/
User
ClusterCollection"
$ref
:
"
#/definitions/
Location
ClusterCollection"
/clusters/cluster.png
:
get
:
operationId
:
"
rest.cluster.get_image"
tags
:
-
"
Clusters"
summary
:
"
Get
user
communities
per
date
per
hour
as
image"
parameters
:
[]
produces
:
-
"
image/png"
responses
:
200
:
description
:
"
Successful
operation"
#
/clusters/cluster.png:
#
get:
#
operationId: "rest.cluster.get_image"
#
tags:
#
- "Clusters"
#
summary: "Get user communities per date per hour as image"
#
parameters: []
#
produces:
#
- "image/png"
#
responses:
#
200:
#
description: "Successful operation"
/
agi/
clusters
:
/
time-
clusters
:
get
:
operationId
:
"
rest.
agi_cluster.get
"
operationId
:
"
rest.
cluster.get_times
"
tags
:
-
"
Clusters"
summary
:
"
Get
user
communities
per
date
per
hour
from
agi
data
"
summary
:
"
Get
user
communities
clustered
by
time
per
hour
"
parameters
:
[]
responses
:
200
:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/
User
ClusterCollection"
$ref
:
"
#/definitions/
Time
ClusterCollection"
/agi/clusters/cluster.png
:
get
:
operationId
:
"
rest.agi_cluster.get_image"
tags
:
-
"
Clusters"
summary
:
"
Get
user
communities
per
date
per
hour
from
agi
data
as
image"
parameters
:
[]
produces
:
-
"
image/png"
responses
:
200
:
description
:
"
Successful
operation"
#
/agi/clusters/cluster.png:
#
get:
#
operationId: "rest.agi_cluster.get_image"
#
tags:
#
- "Clusters"
#
summary: "Get user communities per date per hour from agi data as image"
#
parameters: []
#
produces:
#
- "image/png"
#
responses:
#
200:
#
description: "Successful operation"
definitions
:
Location
:
...
...
@@ -152,8 +152,27 @@ definitions:
items
:
$ref
:
"
#/definitions/Location"
UserCluster
:
type
:
"
object"
LocationCluster
:
type
:
object
properties
:
id
:
type
:
string
cluster_label
:
type
:
number
clusters
:
type
:
array
items
:
$ref
:
"
#/definitions/Location"
# example:
# 0: [1dc61b1a0602de0eaee9dba7eece9279c2844202, b4b31bbe5e12f55737e3a910827c81595fbca3eb]
LocationClusterCollection
:
type
:
array
items
:
$ref
:
"
#/definitions/LocationCluster"
TimeCluster
:
type
:
object
properties
:
id
:
type
:
string
...
...
@@ -161,16 +180,16 @@ definitions:
type
:
string
hour
:
type
:
number
cluster_label
:
type
:
number
clusters
:
type
:
object
additionalProperties
:
type
:
array
items
:
type
:
string
example
:
0
:
[
1dc61b1a0602de0eaee9dba7eece9279c2844202
,
b4b31bbe5e12f55737e3a910827c81595fbca3eb
]
$ref
:
"
#/definitions/Location"
#
example:
#
0: [1dc61b1a0602de0eaee9dba7eece9279c2844202, b4b31bbe5e12f55737e3a910827c81595fbca3eb]
User
ClusterCollection
:
Time
ClusterCollection
:
type
:
array
items
:
$ref
:
"
#/definitions/UserCluster"
\ No newline at end of file
$ref
:
"
#/definitions/TimeCluster"
\ No newline at end of file
src/data-hub/community-detection-microservice/app/db/location_datastore.py
deleted
100644 → 0
View file @
1d90011e
from
__future__
import
annotations
class
LocationDatastore
:
'''This Singelton simulates a location database'''
_instance
=
None
@
staticmethod
def
get_instance
()
->
LocationDatastore
:
if
LocationDatastore
.
_instance
==
None
:
LocationDatastore
.
_instance
=
LocationDatastore
()
return
LocationDatastore
.
_instance
def
__init__
(
self
):
if
LocationDatastore
.
_instance
!=
None
:
raise
Exception
(
"This class is a singleton!"
)
self
.
locations
=
[]
def
add
(
self
,
location
):
self
.
locations
.
append
(
location
)
def
get
(
self
):
return
self
.
locations
\ No newline at end of file
src/data-hub/community-detection-microservice/app/db/repository.py
View file @
9a50d2ec
...
...
@@ -10,14 +10,16 @@ from typing import List
class
Repository
(
MongoRepositoryBase
):
'''This repository stores and loads locations and clusters with MongoDb.'''
def
__init__
(
self
,
agi_data
=
False
):
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
COMMUNITY_DETECTION_DB_HOSTNAME
,
netconst
.
COMMUNITY_DETECTION_DB_PORT
,
'communityDetectionDb'
)
netconst
.
COMMUNITY_DETECTION_DB_PORT
,
'communityDetectionDb'
)
self
.
_location_collection
=
'location
_agi'
if
agi_data
else
'location
'
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
.
_location_collection
=
'location'
self
.
_location_cluster_collection
=
'location_cluster'
self
.
_time_cluster_collection
=
'time_cluster'
self
.
agi_repo
=
AgiRepository
()
...
...
@@ -33,16 +35,17 @@ class Repository(MongoRepositoryBase):
return
[
Location
(
agi_loc
)
for
agi_loc
in
agi_locations
]
def
add_location_cluster
(
self
,
cluster
:
LocationCluster
):
super
()
.
insert_entry
(
self
.
_location_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_location_clusters
(
self
)
->
List
[
LocationCluster
]:
clusters
=
super
()
.
get_entries
(
self
.
_location_cluster_collection
)
return
[
LocationCluster
(
c
[
'cluster_label'
],
json
.
loads
(
c
[
'clusters'
])
)
for
c
in
clusters
]
return
[
LocationCluster
(
location_dict
=
c
,
from_db
=
True
)
for
c
in
clusters
]
def
add_time_cluster
(
self
,
cluster
:
TimeCluster
):
super
()
.
insert_entry
(
self
.
_time_cluster_collection
,
cluster
.
to_serializable_dict
(
for_db
=
True
))
super
()
.
insert_entry
(
self
.
_time_cluster_collection
,
cluster
.
to_serializable_dict
(
for_db
=
True
))
def
get_time_clusters
(
self
)
->
List
[
TimeCluster
]:
clusters
=
super
()
.
get_entries
(
self
.
_time_cluster_collection
)
return
[
TimeCluster
(
c
[
'cluster_label'
],
json
.
loads
(
c
[
'clusters'
]))
for
c
in
clusters
]
return
[
TimeCluster
(
time_dict
=
c
,
from_db
=
True
)
for
c
in
clusters
]
src/data-hub/community-detection-microservice/app/insert_agi_locations.py
0 → 100644
View file @
9a50d2ec
import
sys
import
os
modules_path
=
'../../../modules/'
if
os
.
path
.
exists
(
modules_path
):
sys
.
path
.
insert
(
1
,
modules_path
)
from
db.repository
import
Repository
if
__name__
==
"__main__"
:
repo
=
Repository
()
locs
=
repo
.
get_agi_locations
()
for
l
in
locs
:
repo
.
add_location
(
l
)
src/data-hub/community-detection-microservice/app/rest/agi_cluster.py
deleted
100644 → 0
View file @
1d90011e
import
io
from
flask
import
request
,
Response
from
db.repository
import
Repository
from
processing.clusterer
import
Clusterer
from
matplotlib.backends.backend_agg
import
FigureCanvasAgg
as
FigureCanvas
repo
=
Repository
(
agi_data
=
True
)
clusterer
=
Clusterer
()
def
get
():
clusters
=
repo
.
get_location_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
)
output
=
io
.
BytesIO
()
FigureCanvas
(
fig
)
.
print_png
(
output
)
return
Response
(
output
.
getvalue
(),
mimetype
=
"image/png"
)
\ No newline at end of file
src/data-hub/community-detection-microservice/app/rest/cluster.py
View file @
9a50d2ec
...
...
@@ -7,11 +7,28 @@ from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
repo
=
Repository
()
clusterer
=
Clusterer
()
def
get
():
def
get
_locations
():
clusters
=
repo
.
get_location_clusters
()
return
[
c
.
to_serializable_dict
()
for
c
in
clusters
]
def
get_image
():
def
get_times
():
clusters
=
repo
.
get_time_clusters
()
return
[
c
.
to_serializable_dict
()
for
c
in
clusters
]
def
get_image_1
():
return
Response
(
status
=
501
)
# todo
locations
=
repo
.
getLocations
()
fig
=
clusterer
.
draw_locations
(
locations
)
output
=
io
.
BytesIO
()
FigureCanvas
(
fig
)
.
print_png
(
output
)
return
Response
(
output
.
getvalue
(),
mimetype
=
"image/png"
)
def
get_image_2
():
return
Response
(
status
=
501
)
# todo
...
...
src/data-hub/community-detection-microservice/app/rest/location.py
View file @
9a50d2ec
...
...
@@ -6,17 +6,17 @@ repo = Repository()
def
post
():
body
=
request
.
json
insert_location
(
body
)
_
insert_location
(
body
)
return
Response
(
status
=
201
)
def
post_many
():
body
=
request
.
json
for
location
in
body
:
insert_location
(
location
)
_
insert_location
(
location
)
return
Response
(
status
=
201
)
def
get
():
return
[
l
.
to_serializable_dict
()
for
l
in
repo
.
get_locations
()]
def
insert_location
(
location_data
:
dict
):
def
_
insert_location
(
location_data
:
dict
):
repo
.
add_location
(
Location
(
location_data
))
src/data-hub/community-detection-microservice/app/run_clustering.py
View file @
9a50d2ec
...
...
@@ -14,13 +14,6 @@ DEBUG = False
repo
=
Repository
()
# locs = repo.get_agi_locations()
# for l in locs:
# repo.add_location(l)
# exit()
def
run_location_clustering
():
user_clusterer
=
Clusterer
()
...
...
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