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 get_similarity(layer_name,batchNr): 
    ''' Gets cluster_similarity from the database.

        :returns: Returns similarity objects from the DB
        :rtype: Dict
    '''  
    batchSize = 1000
    if int(batchNr)<0:
        print("Batch number needs to be a positive integer")
        return Response(status=404)
    skipNr = batchSize*int(batchNr)
    #get_similarity(self,skipNr,batchSize, cluster_layer: str= None, run_id: str=None)
    result = repo.get_similarity(skipNr, batchSize, layer_name)
    if result is None or len(result) == 0:        
        print("MongoDb Get Error: Response 404")
        return Response(status=404)
    else:
        return result
