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: ...@@ -295,12 +295,14 @@ definitions:
Node: Node:
type: object type: object
example: example:
"UniqueID": "4437d98b4516e899fb7d93cef0bea6111574473703f0aab9d8c2f02aaa673f5c"
"use_case": "string"
"layer_name": "some_layer_name"
"Finished_time": 1576631193265951 "Finished_time": 1576631193265951
"Latitude_Destination": -5.973257 "Latitude_Destination": -5.973257
"Longitude_Destination": 37.416316 "Longitude_Destination": 37.416316
"TravelID": "5e57ec9159bc0668543f156a" "TravelID": "5e57ec9159bc0668543f156a"
"TravelPrice": 15 "TravelPrice": 15
"UniqueID": "a95075f5042b1b27060080156d87fe34ec7e712c5e57ec9159bc0668543f156a"
"UserID": "a95075f5042b1b27060080156d87fe34ec7e712c" "UserID": "a95075f5042b1b27060080156d87fe34ec7e712c"
NodeCollection: NodeCollection:
......
...@@ -272,13 +272,15 @@ definitions: ...@@ -272,13 +272,15 @@ definitions:
Node: Node:
type: object type: object
example: example:
"Finished_time": 1576631193265951 "UniqueID": "4437d98b4516e899fb7d93cef0bea6111574473703f0aab9d8c2f02aaa673f5c"
"Latitude_Destination": -5.973257 "use_case": "string"
"Longitude_Destination": 37.416316 "layer_name": "some_layer_name"
"TravelID": "5e57ec9159bc0668543f156a" "Finished_time": 1576631193265951
"TravelPrice": 15 "Latitude_Destination": -5.973257
"UniqueID": "a95075f5042b1b27060080156d87fe34ec7e712c5e57ec9159bc0668543f156a" "Longitude_Destination": 37.416316
"UserID": "a95075f5042b1b27060080156d87fe34ec7e712c" "TravelID": "5e57ec9159bc0668543f156a"
"TravelPrice": 15
"UserID": "a95075f5042b1b27060080156d87fe34ec7e712c"
NodeCollection: NodeCollection:
type: array type: array
......
...@@ -41,6 +41,21 @@ class Repository(MongoRepositoryBase): ...@@ -41,6 +41,21 @@ class Repository(MongoRepositoryBase):
return entries[0] return entries[0]
else: else:
return None 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): def add_layer_node(self, node: dict):
super().insert_entry(self._layer_nodes_collection, node) super().insert_entry(self._layer_nodes_collection, node)
......
from security.token_manager import TokenManager from security.token_manager import TokenManager
import network_constants import network_constants
from db.entities.layer import Layer from db.entities.layer import Layer
from db.repository import Repository
from typing import List, Dict from typing import List, Dict
import requests import requests
...@@ -55,11 +56,21 @@ def _fetch_nodes(use_case: str, layer: Layer) -> List[Dict]: ...@@ -55,11 +56,21 @@ def _fetch_nodes(use_case: str, layer: Layer) -> List[Dict]:
return nodes return nodes
def fetch_nodes_from_semantic_linking(use_case: str): 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: 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) nodes = _fetch_nodes(use_case, layer)
print("nodes for layer: "+str(nodes)) for node in nodes:
\ No newline at end of file repository.add_layer_node(node)
\ No newline at end of file
...@@ -10,4 +10,4 @@ import processing.fetching.fetching as f ...@@ -10,4 +10,4 @@ import processing.fetching.fetching as f
if __name__ == "__main__": if __name__ == "__main__":
# TODO read use_case from somewhere # TODO read use_case from somewhere
f.fetch_nodes_from_semantic_linking("debug") f.fetch_nodes_from_semantic_linking("smart-energy")
\ No newline at end of file \ No newline at end of file
...@@ -27,19 +27,19 @@ class Test_MessageHandler(unittest.TestCase): ...@@ -27,19 +27,19 @@ class Test_MessageHandler(unittest.TestCase):
{ {
'type': 'blockchain-transaction', 'type': 'blockchain-transaction',
'content': 'content':
{ {
"ApplicationType": "smart-energy", "ApplicationType": "smart-energy",
"Customer": 13, "Customer": 13,
"Postcode": 2261, "Postcode": 2261,
"Timestamp": "01.07.2012 00:30", "Timestamp": "01.07.2012 00:30",
"Solar_Production_kWh": 0.0, "Solar_Production_kWh": 0.0,
"Energy_Consumption_kWh": 0.23399999999999999, "Energy_Consumption_kWh": 0.23399999999999999,
"Heating_Consumption_kWh": 0.23399999999999999, "Heating_Consumption_kWh": 0.23399999999999999,
"Price_AUD/MWh": 57.04, "Price_AUD/MWh": 57.04,
"Total_Demand_MWh": 8097.93, "Total_Demand_MWh": 8097.93,
"Latitude": -33.362679, "Latitude": -33.362679,
"Longitude": 151.447302, "Longitude": 151.447302,
} }
} }
return json.dumps(message_values) return json.dumps(message_values)
......
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