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
e2deb911
Commit
e2deb911
authored
Nov 10, 2020
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RoleStage] Implemented selection for fetching and clustering scripts
parent
b028f0df
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
22 deletions
+25
-22
fetching.py
...iscovery-microservice/app/processing/fetching/fetching.py
+8
-4
read_json_layers.py
...role-stage-discovery-microservice/app/read_json_layers.py
+3
-8
run_clustering.py
...b/role-stage-discovery-microservice/app/run_clustering.py
+12
-8
run_node_fetching.py
...ole-stage-discovery-microservice/app/run_node_fetching.py
+1
-1
add_smart_energy.py
..._use_case_scripts/smart-energy/tables/add_smart_energy.py
+1
-1
No files found.
src/data-hub/role-stage-discovery-microservice/app/processing/fetching/fetching.py
View file @
e2deb911
...
...
@@ -86,20 +86,23 @@ def _fetch_nodes(use_case: str, table: str, layer_name: str) -> List[Dict]:
return
response
.
json
()
def
fetch_nodes_from_semantic_linking
():
def
fetch_nodes_from_semantic_linking
(
selected_use_cases
:
List
[
str
]
=
None
,
selected_use_case_tables
:
List
[
str
]
=
None
):
'''Empties the db and inserts layers and nodes from BusinessLogic and SemanticLinking'''
repository
=
Repository
()
# please dont delete all layers/ nodes anymore @10.11.2020
# repository.delete_all_layers()
# repository.delete_all_nodes()
use_cases
=
_fetch_use_cases
()
for
use_case
in
use_cases
:
if
selected_use_cases
is
not
None
and
use_case
not
in
selected_use_cases
:
continue
print
(
f
"Fetching for use-case {use_case}"
)
tables
=
_fetch_tables
(
use_case
)
for
table
in
tables
:
if
table
!=
'bank-app'
:
if
selected_use_case_tables
is
not
None
and
table
not
in
selected_use_case_tables
:
continue
layers
=
_fetch_layers
(
use_case
,
table
)
...
...
@@ -107,6 +110,7 @@ def fetch_nodes_from_semantic_linking():
try
:
print
(
f
"Fetching nodes for layer {use_case}//{table}//{layer.layer_name}."
)
# check if layer already exists in DB, add it if not
reference_layer
=
repository
.
get_layer_by_name
(
use_case
,
table
,
layer
.
layer_name
)
if
reference_layer
==
None
:
...
...
src/data-hub/role-stage-discovery-microservice/app/
convert
_layers.py
→
src/data-hub/role-stage-discovery-microservice/app/
read_json
_layers.py
View file @
e2deb911
...
...
@@ -9,9 +9,11 @@ from db.entities import Cluster
from
typing
import
List
from
db.repository
import
Repository
LAYER_FILES
=
[
'User_Demand_Layer.json'
]
repo
=
Repository
()
def
get_clusters
(
layer_file
)
->
List
[
Cluster
]:
with
open
(
layer_file
,
'r'
)
as
file
:
clusters
=
json
.
loads
(
file
.
read
())
...
...
@@ -19,10 +21,6 @@ def get_clusters(layer_file) -> List[Cluster]:
def
store_generic_clusters
(
clusters
:
List
[
Cluster
],
layer
):
print
([
c
.
label
for
c
in
clusters
][
0
:
10
])
return
try
:
with
open
(
f
'{layer}.json'
,
'w'
)
as
file
:
cluster_dicts
=
[
c
.
to_serializable_dict
(
for_db
=
False
)
for
c
in
clusters
]
...
...
@@ -37,9 +35,6 @@ def store_generic_clusters(clusters: List[Cluster], layer):
print
(
f
"failed uploading {layer}"
)
layers
=
[
'User_Demand_Layer.json'
]
for
layer
in
layers
:
for
layer
in
LAYER_FILES
:
clusts
:
List
[
Cluster
]
=
get_clusters
(
layer
)
# print(len(clusts))
store_generic_clusters
(
clusts
,
layer
)
\ No newline at end of file
src/data-hub/role-stage-discovery-microservice/app/run_clustering.py
View file @
e2deb911
...
...
@@ -14,17 +14,20 @@ from processing.clustering import Clusterer, ClusterResult
repo
=
Repository
()
def
run_generic_clustering
():
def
run_generic_clustering
(
selected_use_cases
:
List
[
str
]
=
None
,
selected_use_case_tables
:
List
[
str
]
=
None
,
selected_layer_names
:
List
[
str
]
=
None
):
'''Runs the clustering for all layers found in the repository.'''
all_layers
:
List
[
Layer
]
=
repo
.
get_layers
()
all_layers
=
[
l
for
l
in
all_layers
if
l
.
layer_name
in
[
'User_Demand_Layer'
]
and
l
.
use_case
==
'smart-energy'
]
layers
=
[
l
for
l
in
all_layers
if
(
selected_use_cases
is
None
or
l
.
use_case
in
selected_use_cases
)
and
(
selected_use_case_tables
is
None
or
l
.
use_case_table
in
selected_use_case_tables
)
and
(
selected_layer_names
is
None
or
l
.
layer_name
in
selected_layer_names
)
]
for
layer
in
all_layers
:
for
layer
in
layers
:
print
(
f
"Clustering {layer.use_case}//{layer.use_case_table}//{layer.layer_name}."
)
if
layer
.
properties
is
None
or
len
(
layer
.
properties
)
==
0
:
print
(
"skipping"
)
print
(
"skipping
, no properties to cluster
"
)
continue
try
:
...
...
@@ -54,15 +57,16 @@ def store_generic_clusters(clusters: List[Cluster], layer):
cluster_dicts
=
[
c
.
to_serializable_dict
(
for_db
=
False
)
for
c
in
clusters
]
file
.
write
(
json
.
dumps
(
cluster_dicts
))
except
:
p
ass
p
rint
(
f
"Error while writing json for {layer}"
)
try
:
for
cluster
in
clusters
:
repo
.
add_cluster
(
cluster
)
except
:
p
ass
p
rint
(
f
"Error while storing cluster in db for {layer}"
)
if
__name__
==
"__main__"
:
# please dont delete all clusters anymore @10.11.2020
# repo.delete_all_clusters()
run_generic_clustering
()
run_generic_clustering
(
selected_use_cases
=
[],
selected_use_case_tables
=
[],
selected_layer_names
=
[]
)
src/data-hub/role-stage-discovery-microservice/app/run_node_fetching.py
View file @
e2deb911
...
...
@@ -11,4 +11,4 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import
processing.fetching.fetching
as
f
if
__name__
==
"__main__"
:
f
.
fetch_nodes_from_semantic_linking
()
\ No newline at end of file
f
.
fetch_nodes_from_semantic_linking
(
selected_use_cases
=
[],
selected_use_case_tables
=
[])
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/_add_use_case_scripts/smart-energy/tables/add_smart_energy.py
View file @
e2deb911
...
...
@@ -166,7 +166,7 @@ def add_layers(use_case:str, table_name: str):
print
(
url
+
": "
+
str
(
response
.
status_code
))
def
main
(
use_case
:
str
=
"smart-energy"
,
table_name
:
str
=
"smart-energy
-paper
"
):
def
main
(
use_case
:
str
=
"smart-energy"
,
table_name
:
str
=
"smart-energy"
):
print
(
"SMART-ENERGY"
)
add_table
(
use_case
,
table_name
)
...
...
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