Commit b56119fa authored by Manuel's avatar Manuel

adjustments

- changed definition of "Node" in roleStageDiscover
- added layer- and node-storage in roleStageDiscover
parent 088d8d87
......@@ -295,12 +295,14 @@ definitions:
Node:
type: object
example:
"UniqueID": "4437d98b4516e899fb7d93cef0bea6111574473703f0aab9d8c2f02aaa673f5c"
"use_case": "string"
"layer_name": "some_layer_name"
"Finished_time": 1576631193265951
"Latitude_Destination": -5.973257
"Longitude_Destination": 37.416316
"TravelID": "5e57ec9159bc0668543f156a"
"TravelPrice": 15
"UniqueID": "a95075f5042b1b27060080156d87fe34ec7e712c5e57ec9159bc0668543f156a"
"UserID": "a95075f5042b1b27060080156d87fe34ec7e712c"
NodeCollection:
......
......@@ -272,12 +272,14 @@ definitions:
Node:
type: object
example:
"UniqueID": "4437d98b4516e899fb7d93cef0bea6111574473703f0aab9d8c2f02aaa673f5c"
"use_case": "string"
"layer_name": "some_layer_name"
"Finished_time": 1576631193265951
"Latitude_Destination": -5.973257
"Longitude_Destination": 37.416316
"TravelID": "5e57ec9159bc0668543f156a"
"TravelPrice": 15
"UniqueID": "a95075f5042b1b27060080156d87fe34ec7e712c5e57ec9159bc0668543f156a"
"UserID": "a95075f5042b1b27060080156d87fe34ec7e712c"
NodeCollection:
......
......@@ -42,6 +42,21 @@ class Repository(MongoRepositoryBase):
else:
return None
def delete_all_layers(self):
super().drop_collection(self._layer_collection)
def delete_all_nodes(self):
super().drop_collection(self._layer_nodes_collection)
def get_layer_for_use_case(self, layer_name: str, use_case: str) -> Layer:
entries = super().get_entries(self._layer_collection, selection={'layer_name': layer_name, 'use_case': use_case})
entries = [Layer(e) for e in entries]
if entries is not None and len(entries) > 0:
return entries[0]
else:
return None
def add_layer_node(self, node: dict):
super().insert_entry(self._layer_nodes_collection, node)
......
from security.token_manager import TokenManager
import network_constants
from db.entities.layer import Layer
from db.repository import Repository
from typing import List, Dict
import requests
......@@ -55,11 +56,21 @@ def _fetch_nodes(use_case: str, layer: Layer) -> List[Dict]:
return nodes
def fetch_nodes_from_semantic_linking(use_case: str):
layers = _fetch_layers(use_case)
# prune DB
repository = Repository()
repository.delete_all_layers()
repository.delete_all_nodes()
print(str(layers))
layers = _fetch_layers(use_case)
for layer in layers:
# check if layer already exists in DB, add it if not
reference_layer = repository.get_layer_for_use_case(layer.layer_name, use_case)
if reference_layer == None:
repository.add_layer(layer)
nodes = repository.get_layer_nodes(layer.layer_name)
nodes = _fetch_nodes(use_case, layer)
print("nodes for layer: "+str(nodes))
\ No newline at end of file
for node in nodes:
repository.add_layer_node(node)
\ No newline at end of file
......@@ -10,4 +10,4 @@ import processing.fetching.fetching as f
if __name__ == "__main__":
# TODO read use_case from somewhere
f.fetch_nodes_from_semantic_linking("debug")
\ No newline at end of file
f.fetch_nodes_from_semantic_linking("smart-energy")
\ 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