Commit b6948a7b authored by Alexander Lercher's avatar Alexander Lercher

Similarity calculation per use case layers

parent 34d17494
......@@ -48,7 +48,7 @@ paths:
description: "The layer data to be added"
required: true
schema:
$ref: "#/definitions/Layer-UpperCase"
$ref: "#/definitions/Layer"
responses:
'201':
description: "Successful operation"
......@@ -275,16 +275,6 @@ definitions:
items:
$ref: "#/definitions/Cluster"
Layer-UpperCase:
type: object
properties:
LayerName:
type: string
Properties:
type: array
items:
type: string
Layer:
type: object
properties:
......
......@@ -45,7 +45,7 @@ paths:
description: "The layer data to be added"
required: true
schema:
$ref: "#/definitions/Layer-UpperCase"
$ref: "#/definitions/Layer"
responses:
'201':
description: "Successful operation"
......@@ -252,16 +252,6 @@ definitions:
items:
$ref: "#/definitions/Cluster"
Layer-UpperCase:
type: object
properties:
LayerName:
type: string
Properties:
type: array
items:
type: string
Layer:
type: object
properties:
......
......@@ -17,12 +17,14 @@ class Layer:
def to_serializable_dict(self, for_db=False) -> Dict:
return {
"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):
self.layer_name = layer_info['layer_name']
self.properties = layer_info['properties']
self.use_case = layer_info['use_case']
def __repr__(self):
return json.dumps(self.to_serializable_dict())
......
......@@ -12,7 +12,7 @@ import os
import sys
import math
import datetime
from typing import Dict
from typing import Dict, List
### init logging ###
import logging
......@@ -22,8 +22,8 @@ LOGGER = logging.getLogger(__name__)
##################AUX
modules_path = '../../../modules/'
if os.path.exists(modules_path):
for modules_path in ['../../../modules/', './']:
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
#### TO BE DELETED #### ^
......@@ -38,8 +38,15 @@ from processing.similarityFiles.miscFunctions import *
from processing.similarityFiles.dataOutput import *
def main():
print("\nEntered Main")
def main(layerNameList:List[str] = ["Price_Layer","FinishedTime_Layer","Destination_Layer"]):
'''
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
......@@ -56,14 +63,14 @@ def main():
StartingTime_Layer
User_Layer
"""
layerNameList = ["Price_Layer","FinishedTime_Layer","Destination_Layer"] #Get it from somewhere else?
limitNrCluster = -1 #per Layer # 0< equals noLimit
limitNrNodes = -1 #per Layer
layerDict = getClusterDataFromMongo(layerNameList,limitNrCluster,limitNrNodes)
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
#URLlist = None
......@@ -116,5 +123,6 @@ def main():
return
##########START##########
main()
if __name__ is '__main__':
main()
#########FINISH##########
......@@ -14,8 +14,8 @@ def post():
def _insert_layer(layer_data: dict):
'''Converts object keys from external source and inserts into database.'''
layer_data['layer_name'] = layer_data.pop('LayerName')
layer_data['properties'] = layer_data.pop('Properties')
# layer_data['layer_name'] = layer_data.pop('LayerName')
# layer_data['properties'] = layer_data.pop('Properties')
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