Commit b6948a7b authored by Alexander Lercher's avatar Alexander Lercher

Similarity calculation per use case layers

parent 34d17494
...@@ -48,7 +48,7 @@ paths: ...@@ -48,7 +48,7 @@ paths:
description: "The layer data to be added" description: "The layer data to be added"
required: true required: true
schema: schema:
$ref: "#/definitions/Layer-UpperCase" $ref: "#/definitions/Layer"
responses: responses:
'201': '201':
description: "Successful operation" description: "Successful operation"
...@@ -274,16 +274,6 @@ definitions: ...@@ -274,16 +274,6 @@ definitions:
type: array type: array
items: items:
$ref: "#/definitions/Cluster" $ref: "#/definitions/Cluster"
Layer-UpperCase:
type: object
properties:
LayerName:
type: string
Properties:
type: array
items:
type: string
Layer: Layer:
type: object type: object
......
...@@ -45,7 +45,7 @@ paths: ...@@ -45,7 +45,7 @@ paths:
description: "The layer data to be added" description: "The layer data to be added"
required: true required: true
schema: schema:
$ref: "#/definitions/Layer-UpperCase" $ref: "#/definitions/Layer"
responses: responses:
'201': '201':
description: "Successful operation" description: "Successful operation"
...@@ -251,16 +251,6 @@ definitions: ...@@ -251,16 +251,6 @@ definitions:
type: array type: array
items: items:
$ref: "#/definitions/Cluster" $ref: "#/definitions/Cluster"
Layer-UpperCase:
type: object
properties:
LayerName:
type: string
Properties:
type: array
items:
type: string
Layer: Layer:
type: object type: object
......
...@@ -17,12 +17,14 @@ class Layer: ...@@ -17,12 +17,14 @@ class Layer:
def to_serializable_dict(self, for_db=False) -> Dict: def to_serializable_dict(self, for_db=False) -> Dict:
return { return {
"layer_name": self.layer_name, "layer_name": self.layer_name,
"properties": self.properties "properties": self.properties,
"use_case": self.use_case
} }
def from_serializable_dict(self, layer_info: Dict, from_db=False): def from_serializable_dict(self, layer_info: Dict, from_db=False):
self.layer_name = layer_info['layer_name'] self.layer_name = layer_info['layer_name']
self.properties = layer_info['properties'] self.properties = layer_info['properties']
self.use_case = layer_info['use_case']
def __repr__(self): def __repr__(self):
return json.dumps(self.to_serializable_dict()) return json.dumps(self.to_serializable_dict())
......
...@@ -12,7 +12,7 @@ import os ...@@ -12,7 +12,7 @@ import os
import sys import sys
import math import math
import datetime import datetime
from typing import Dict from typing import Dict, List
### init logging ### ### init logging ###
import logging import logging
...@@ -22,9 +22,9 @@ LOGGER = logging.getLogger(__name__) ...@@ -22,9 +22,9 @@ LOGGER = logging.getLogger(__name__)
##################AUX ##################AUX
modules_path = '../../../modules/' for modules_path in ['../../../modules/', './']:
if os.path.exists(modules_path): if os.path.exists(modules_path):
sys.path.insert(1, modules_path) sys.path.insert(1, modules_path)
#### TO BE DELETED #### ^ #### TO BE DELETED #### ^
...@@ -38,8 +38,15 @@ from processing.similarityFiles.miscFunctions import * ...@@ -38,8 +38,15 @@ from processing.similarityFiles.miscFunctions import *
from processing.similarityFiles.dataOutput import * from processing.similarityFiles.dataOutput import *
def main(): def main(layerNameList:List[str] = ["Price_Layer","FinishedTime_Layer","Destination_Layer"]):
print("\nEntered Main") '''
Executes the similarity calculation by calculating weights between clusters in different layers.
Then calculating the Euclidean distance between nodes in the same layer based on one other layer each.
Everything is loaded from and stored to the database.
:param layerNameList: The list of layer names as strings
'''
print("Entered Similarity Main")
outputToFileFLAG = False outputToFileFLAG = False
...@@ -56,14 +63,14 @@ def main(): ...@@ -56,14 +63,14 @@ def main():
StartingTime_Layer StartingTime_Layer
User_Layer User_Layer
""" """
layerNameList = ["Price_Layer","FinishedTime_Layer","Destination_Layer"] #Get it from somewhere else?
limitNrCluster = -1 #per Layer # 0< equals noLimit limitNrCluster = -1 #per Layer # 0< equals noLimit
limitNrNodes = -1 #per Layer limitNrNodes = -1 #per Layer
layerDict = getClusterDataFromMongo(layerNameList,limitNrCluster,limitNrNodes) layerDict = getClusterDataFromMongo(layerNameList,limitNrCluster,limitNrNodes)
if layerDict is None or len(layerDict) == 0: if layerDict is None or len(layerDict) == 0:
LOGGER.error(f"None of the following layers existed: {str(layerNameList)}. Similarity calculation was not performed.") LOGGER.error(f"No data for any of the following layers existed: {str(layerNameList)}. Similarity calculation was not performed.")
return return
#URLlist = None #URLlist = None
...@@ -116,5 +123,6 @@ def main(): ...@@ -116,5 +123,6 @@ def main():
return return
##########START########## ##########START##########
main() if __name__ is '__main__':
main()
#########FINISH########## #########FINISH##########
...@@ -14,8 +14,8 @@ def post(): ...@@ -14,8 +14,8 @@ def post():
def _insert_layer(layer_data: dict): def _insert_layer(layer_data: dict):
'''Converts object keys from external source and inserts into database.''' '''Converts object keys from external source and inserts into database.'''
layer_data['layer_name'] = layer_data.pop('LayerName') # layer_data['layer_name'] = layer_data.pop('LayerName')
layer_data['properties'] = layer_data.pop('Properties') # layer_data['properties'] = layer_data.pop('Properties')
repo.add_layer(Layer(layer_data)) repo.add_layer(Layer(layer_data))
......
import processing.similarityFiles.similarityMain as SimilarityCalc
from db.repository import Repository
repo = Repository()
def run_similarity_calc_per_use_case():
layers = repo.get_layers()
uc_layers = {}
for layer in layers:
uc = layer.use_case
if uc not in uc_layers:
uc_layers[uc] = []
uc_layers[uc].append(layer.layer_name)
for key in uc_layers:
layers = uc_layers[key]
print(f"Running for use case {key} with layers {str(layers)}.")
SimilarityCalc.main(layerNameList=layers)
if __name__ == '__main__':
run_similarity_calc_per_use_case()
\ 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