from flask import request, Response
from db.repository import Repository
from processing.similarityFiles.miscFunctions import convertSimilarityDictToJSON
#from db.entities import clusterset #REMOVE?

repo = Repository()


def add_similarity(inputDict,runId):
    ''' Stores cluster_similarity in the database.

    :param Dict() inputDict: Contains the data to insert

    :param string runId: Id of the Run 

    ''' 

    outputJSON = convertSimilarityDictToJSON(inputDict,runId)
    repo.add_similarity(outputJSON)

def get_similarity(): 
    ''' Gets cluster_similarity from the database.

        :returns: Returns similarity objects from the DB
        :rtype: Dict
    '''  
    result = repo.get_similarity()
    if result is None or len(result) == 0:        
        print("MongoDb Get Error: Response 404")
        return Response(status=404)
    else:
        return result
