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
db393636
Commit
db393636
authored
Feb 04, 2020
by
Alexander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
loading and storing location and clusters in mongodb
parent
b57623ef
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
101 additions
and
40 deletions
+101
-40
repository.py
...hub/community-detection-microservice/app/db/repository.py
+26
-7
main.py
src/data-hub/community-detection-microservice/app/main.py
+7
-0
cluster.py
...-hub/community-detection-microservice/app/rest/cluster.py
+4
-5
location.py
...hub/community-detection-microservice/app/rest/location.py
+3
-2
deployment.yml
...ommunity-detection-microservice/deployment/deployment.yml
+41
-1
MongoRepositoryBase.py
src/modules/database/MongoRepositoryBase.py
+13
-14
MongoRepository.py
...ce-retrieval-microservice/app/database/MongoRepository.py
+6
-10
blockchain_trace.py
...trace-retrieval-microservice/app/rest/blockchain_trace.py
+1
-1
No files found.
src/data-hub/community-detection-microservice/app/db/repository.py
View file @
db393636
from
db.location_datastore
import
LocationDatastore
import
pymongo
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
import
json
from
db.agi.agi_repository
import
AgiRepository
from
db.entities
import
Location
,
UserCluster
,
PopularLocation
from
typing
import
List
from
db.agi.agi_repository
import
AgiRepository
class
Repository
:
class
Repository
(
MongoRepositoryBase
):
def
__init__
(
self
):
self
.
store
=
LocationDatastore
.
get_instance
()
super
()
.
__init__
(
netconst
.
COMMUNITY_DETECTION_DB_HOSTNAME
,
netconst
.
COMMUNITY_DETECTION_DB_PORT
,
'communityDetectionDb'
)
self
.
_location_collection
=
'location'
self
.
_cluster_collection
=
'cluster'
self
.
agi_repo
=
AgiRepository
()
def
add_location
(
self
,
location
:
Location
):
s
elf
.
store
.
add
(
location
)
s
uper
()
.
insert_entry
(
self
.
_location_collection
,
location
.
to_serializable_dict
()
)
def
get_locations
(
self
)
->
List
[
Location
]:
locations
=
super
()
.
get_entries
(
self
.
_location_collection
)
return
[
Location
(
l
)
for
l
in
locations
]
def
get_agi_locations
(
self
)
->
List
[
Location
]:
agi_locations
=
self
.
agi_repo
.
getLocations
()
return
[
Location
(
agi_loc
)
for
agi_loc
in
agi_locations
]
def
add_user_cluster
(
self
,
cluster
:
UserCluster
):
print
(
cluster
)
super
()
.
insert_entry
(
self
.
_cluster_collection
,
cluster
.
to_serializable_dict
(
for_db
=
True
))
def
get_user_clusters
(
self
)
->
List
[
UserCluster
]:
clusters
=
super
()
.
get_entries
(
self
.
_cluster_collection
)
return
[
UserCluster
(
c
[
'date'
],
int
(
c
[
'hour'
]),
json
.
loads
(
c
[
'clusters'
]))
for
c
in
clusters
]
def
add_popular_location
(
self
,
popular_location
:
PopularLocation
):
p
rint
(
popular_location
)
p
ass
src/data-hub/community-detection-microservice/app/main.py
View file @
db393636
# add modules folder to interpreter path
import
sys
import
os
modules_path
=
'../../../modules/'
if
os
.
path
.
exists
(
modules_path
):
sys
.
path
.
insert
(
1
,
modules_path
)
### init logging ###
import
logging
LOG_FORMAT
=
(
'
%(levelname) -5
s
%(asctime)
s
%(name)
s:
%(funcName) -35
s
%(lineno) -5
d:
%(message)
s'
)
...
...
src/data-hub/community-detection-microservice/app/rest/cluster.py
View file @
db393636
...
...
@@ -8,13 +8,12 @@ repo = Repository()
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
)
locations
=
repo
.
getLocations
()
fig
=
clusterer
.
draw_locations
(
locations
)
...
...
src/data-hub/community-detection-microservice/app/rest/location.py
View file @
db393636
from
flask
import
request
,
Response
from
db.repository
import
Repository
from
db.entities
import
Location
repo
=
Repository
()
def
post
():
body
=
request
.
json
repo
.
add
Location
(
body
)
repo
.
add
_location
(
Location
(
body
)
)
return
Response
(
status
=
201
)
def
get
():
return
repo
.
getLocations
()
return
[
l
.
to_serializable_dict
()
for
l
in
repo
.
get_locations
()]
src/data-hub/community-detection-microservice/deployment/deployment.yml
View file @
db393636
...
...
@@ -31,4 +31,44 @@ spec:
-
name
:
community-detection
image
:
alexx882/community-detection-microservice
ports
:
-
containerPort
:
5000
\ No newline at end of file
-
containerPort
:
5000
---
apiVersion
:
v1
kind
:
Service
metadata
:
name
:
community-detection-db
spec
:
type
:
LoadBalancer
selector
:
app
:
community-detection-db
ports
:
-
name
:
http
port
:
27017
targetPort
:
27017
nodePort
:
30110
protocol
:
TCP
---
apiVersion
:
apps/v1
kind
:
Deployment
metadata
:
name
:
community-detection-db
spec
:
replicas
:
1
selector
:
matchLabels
:
app
:
community-detection-db
template
:
metadata
:
labels
:
app
:
community-detection-db
spec
:
containers
:
-
name
:
community-detection-db
image
:
mongo
env
:
-
name
:
MONGO_INITDB_ROOT_USERNAME
value
:
root
-
name
:
MONGO_INITDB_ROOT_PASSWORD
value
:
root
ports
:
-
containerPort
:
27017
\ No newline at end of file
src/modules/database/MongoRepositoryBase.py
View file @
db393636
import
pymongo
from
pymongo
import
MongoClient
,
cursor
import
network_constants
as
netconst
class
MongoRepositoryBase
:
'''Base class to connect to, insert and read from a single MongoDB collection'''
'''Base class to connect to a MongoDB database'''
# TODO extract to docker env var
_username
=
'root'
_password
=
'root'
_collection
:
pymongo
.
collection
.
Collection
=
None
_mongo_client
:
pymongo
.
MongoClient
=
None
def
__init__
(
self
,
hostname
,
port
,
database_name
,
username
=
_username
,
password
=
_password
):
self
.
_mongo_client
=
MongoClient
(
f
"mongodb://{username}:{password}@{hostname}:{port}/"
)
self
.
_database
=
self
.
_mongo_client
[
database_name
]
def
__init__
(
self
,
database_name
,
collection_name
,
username
=
_username
,
password
=
_password
):
self
.
_mongo_client
=
pymongo
.
MongoClient
(
f
"mongodb://{username}:{password}@{netconst.MONGO_DB_HOSTNAME}:{netconst.MONGO_DB_PORT}/"
)
database
=
self
.
_mongo_client
[
database_name
]
self
.
_collection
=
database
[
collection_name
]
def
insert_entry
(
self
,
collection_name
,
content
:
dict
):
collection
=
self
.
_database
[
collection_name
]
collection
.
insert_one
(
content
)
def
insert_entry
(
self
,
content
:
dict
):
self
.
_collection
.
insert_one
(
content
)
def
get_entries
(
self
,
selection
:
dict
=
{},
projection
:
dict
=
{
'_'
:
0
})
->
pymongo
.
cursor
.
Cursor
:
return
self
.
_collection
.
find
(
selection
,
projection
)
def
get_entries
(
self
,
collection_name
,
selection
:
dict
=
{},
projection
:
dict
=
{
'_'
:
0
})
->
cursor
.
Cursor
:
collection
=
self
.
_database
[
collection_name
]
return
collection
.
find
(
selection
,
projection
)
def
close_connection
(
self
):
self
.
_mongo_client
.
close
()
self
.
_mongo_client
=
None
self
.
_collection
=
None
src/transaction-hub-in/trace-retrieval-microservice/app/database/MongoRepository.py
View file @
db393636
...
...
@@ -3,19 +3,15 @@ import network_constants as netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
class
MongoRepository
(
MongoRepositoryBase
):
# TODO extract to docker env var
_username
=
'root'
_password
=
'root'
_collection
:
pymongo
.
collection
.
Collection
=
None
_mongo_client
:
pymongo
.
MongoClient
=
None
def
__init__
(
self
,
username
=
_username
,
password
=
_password
):
super
()
.
__init__
(
'traceRetrievalDB'
,
'traces'
)
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
TRACE_RETRIEVAL_DB_HOSTNAME
,
netconst
.
TRACE_RETRIEVAL_DB_PORT
,
'traceRetrievalDB'
)
self
.
_collection_name
=
'traces'
def
insert_trace
(
self
,
content
:
dict
):
super
()
.
insert_entry
(
content
)
super
()
.
insert_entry
(
self
.
_collection_name
,
content
)
def
get_traces
(
self
,
selection
:
dict
=
{},
projection
:
dict
=
{
'_'
:
0
})
->
pymongo
.
cursor
.
Cursor
:
return
super
()
.
get_entries
(
selection
,
projection
)
return
super
()
.
get_entries
(
sel
f
.
_collection_name
,
sel
ection
,
projection
)
src/transaction-hub-in/trace-retrieval-microservice/app/rest/blockchain_trace.py
View file @
db393636
...
...
@@ -4,7 +4,7 @@ from database.MongoRepository import MongoRepository
mongo_repo
=
MongoRepository
()
def
post
():
return
Response
(
status
=
501
)
return
Response
(
response
=
'Use the RESTful Gateway instead'
,
status
=
405
)
def
get
():
return
list
(
mongo_repo
.
get_traces
(
projection
=
{
'_id'
:
0
}))
\ 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