Commit b3e1053d authored by Bogdan's avatar Bogdan

Merge remote-tracking branch 'origin/developBogdan' into developBogdan

parents a039212b 8d27f825
...@@ -4,5 +4,3 @@ ...@@ -4,5 +4,3 @@
*.log *.log
**/env **/env
**/venv **/venv
src/data-hub/role-stage-discovery-microservice/app/resultSimilarityDictN14992C221.json
...@@ -14,7 +14,6 @@ LOGGER = logging.getLogger(__name__) ...@@ -14,7 +14,6 @@ LOGGER = logging.getLogger(__name__)
############################# #############################
import connexion import connexion
# load swagger config # load swagger config
app = connexion.App(__name__, specification_dir='configs/') app = connexion.App(__name__, specification_dir='configs/')
app.add_api('swagger.yml') app.add_api('swagger.yml')
......
...@@ -32,10 +32,6 @@ from processing.similarityFiles.miscFunctions import * ...@@ -32,10 +32,6 @@ from processing.similarityFiles.miscFunctions import *
from processing.similarityFiles.dataOutput import * from processing.similarityFiles.dataOutput import *
#####TEST ONLY#####
from processing.similarityFiles.testSimilarity import *
def main(): def main():
print("\nEntered Main") print("\nEntered Main")
...@@ -110,9 +106,6 @@ def main(): ...@@ -110,9 +106,6 @@ def main():
return return
def test():
testInputData()
##########START########## ##########START##########
main() main()
#test()
#########FINISH########## #########FINISH##########
import unittest import unittest
import sys import sys
sys.path.insert(1, '../') for path in ['../', './']:
sys.path.insert(1, path)
# python -m unittest discover # python -m unittest discover
from db.entities import Cluster from db.entities import Cluster
......
import unittest
import sys
for path in ['../', './', '../../../modules/']:
sys.path.insert(1, path)
from db.entities.connected_node import NodeC from db.entities.connected_node import NodeC
from db.entities.connected_cluster import ClusterC from db.entities.connected_cluster import ClusterC
from db.entities.connected_layer import LayerC from db.entities.connected_layer import LayerC
import os
import sys
import math import math
import datetime import datetime
from typing import Dict from typing import Dict
...@@ -12,23 +16,14 @@ from processing.similarityFiles.dataInput import * ...@@ -12,23 +16,14 @@ from processing.similarityFiles.dataInput import *
from processing.similarityFiles.calculateWeights import * from processing.similarityFiles.calculateWeights import *
from processing.similarityFiles.calculateSimilarity import * from processing.similarityFiles.calculateSimilarity import *
from processing.similarityFiles.miscFunctions import * from processing.similarityFiles.miscFunctions import *
from processing.similarityFiles.dataOutput import *
import json import json
import requests
modules_path = '../../../modules/'
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
from db.repository import *
repo = Repository()
class TestSimilarity(unittest.TestCase):
'''Tests the similarity calculation which works without object orientation.'''
def testInputData():#ONLY FOR TESTING def test_integration_similarityCalculation(self):
''' '''
Only for testing, can be deleted at any time.\n Only for testing, can be deleted at any time.\n
Served as a testing example to make sure the computations are correct Served as a testing example to make sure the computations are correct
...@@ -37,7 +32,7 @@ def testInputData():#ONLY FOR TESTING ...@@ -37,7 +32,7 @@ def testInputData():#ONLY FOR TESTING
limitNrNodes = 100000 limitNrNodes = 100000
layerDict = dict() layerDict = dict()
print("Creating Connected_cluster dict and similarity dict") ("Creating Connected_cluster dict and similarity dict")
inputLayerLocation=getTestLocationLayerData() inputLayerLocation=getTestLocationLayerData()
inputLayerTime=getTestTimeLayerData() inputLayerTime=getTestTimeLayerData()
inputLayerPrice=getTestPriceLayerData() inputLayerPrice=getTestPriceLayerData()
...@@ -48,26 +43,26 @@ def testInputData():#ONLY FOR TESTING ...@@ -48,26 +43,26 @@ def testInputData():#ONLY FOR TESTING
layerDict = calculateWeights(layerDict) layerDict = calculateWeights(layerDict)
similarityDict = calculateSimilarity(layerDict) similarityDict = calculateSimilarity(layerDict)
print("Asserting if the calculated values are true") ("Asserting if the calculated values are true")
#assert x == "hello" #assert x == "hello"
# SYNTAX: # SYNTAX:
#similarityDict[(clusterLabel1,clusterLabel2,layerOfTheClusters)][layerToWhichTheClustersAreCompared] == ExpectedSimilarityValue #similarityDict[(clusterLabel1,clusterLabel2,layerOfTheClusters)][layerToWhichTheClustersAreCompared] == ExpectedSimilarityValue
#checking if the cluster "1" and cluster "2" from the "Location" layer have the sqrt(2) similarity values for when compared with 'Price'and 'Time'layers #checking if the cluster "1" and cluster "2" from the "Location" layer have the sqrt(2) similarity values for when compared with 'Price'and 'Time'layers
assert similarityDict[(1,2,'Location')]['Price'] == math.sqrt(2) self.assertEqual(similarityDict[(1,2,'Location')]['Price'], math.sqrt(2))
assert similarityDict[(1,2,'Location')]['Time'] == math.sqrt(2) self.assertEqual(similarityDict[(1,2,'Location')]['Time'], math.sqrt(2))
assert similarityDict[(1,3,'Location')]['Price'] == math.sqrt(10) self.assertEqual(similarityDict[(1,3,'Location')]['Price'], math.sqrt(10))
assert similarityDict[(1,3,'Location')]['Time'] == math.sqrt(16) self.assertEqual(similarityDict[(1,3,'Location')]['Time'], math.sqrt(16))
assert similarityDict[(2,3,'Location')]['Price'] == math.sqrt(4) self.assertEqual(similarityDict[(2,3,'Location')]['Price'], math.sqrt(4))
assert similarityDict[(2,3,'Location')]['Time'] == math.sqrt(10) self.assertEqual(similarityDict[(2,3,'Location')]['Time'], math.sqrt(10))
assert similarityDict[(4,5,'Time')]['Location'] == math.sqrt(19) self.assertEqual(similarityDict[(4,5,'Time')]['Location'], math.sqrt(19))
assert similarityDict[(4,5,'Time')]['Price'] == math.sqrt(26) self.assertEqual(similarityDict[(4,5,'Time')]['Price'], math.sqrt(26))
assert similarityDict[(6,7,'Price')]['Location'] == math.sqrt(3) self.assertEqual(similarityDict[(6,7,'Price')]['Location'], math.sqrt(3))
assert similarityDict[(6,7,'Price')]['Time'] == math.sqrt(8) self.assertEqual(similarityDict[(6,7,'Price')]['Time'], math.sqrt(8))
# assert similarityDict[(1,2,'Location')] # assert similarityDict[(1,2,'Location')]
print("Test Passed Succesfully") ("Test Passed Succesfully")
return layerDict return layerDict
...@@ -402,3 +397,5 @@ def getTestPriceLayerData(): ...@@ -402,3 +397,5 @@ def getTestPriceLayerData():
if __name__ == '__main__':
unittest.main()
\ 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