def createSharePeriods(self,peer,service,dateTimeStart,dateTimeStop): for countShare in range(1,10): periodStart = randomDate(dateTimeStart,dateTimeStop, random()) periodEnd = randomDate(periodStart,dateTimeStop, random()) quantity = 10 #randint(1,10) service.addSharePeriod(SharePeriod(service,periodStart,periodEnd,quantity,peer.getURN()))
def createEquivalence(self,peer,dateTimeStart,dateTimeStop): # Procura nao fazer para todos equivalenceRepository = peer.getEquivalenceRepository() services = peer.getServices() tam = services.countElements() if tam <2: return for countEle in range(0,tam): serviceS = services.getElements().values()[countEle] if equivalenceRepository.hasElement(serviceS.getUUID()): service = equivalenceRepository.getElementID(serviceS.getUUID()) else: service = ServiceEquivalence(serviceS) for z in range(countEle+1,tam): serviceE = services.getElements().values()[z] if equivalenceRepository.hasElement(serviceE.getUUID()): equivalenceS = equivalenceRepository.getElementID(serviceE.getUUID()) else: equivalenceS = ServiceEquivalence(serviceE) #print "aqui" #print "e --->",countEle,z,equivalenceS.getResource(),equivalenceS.getResourceUUID() serviceQuantity = 5 #randint(1,10) equivalenceQuantity = 5 #randint(1,10) periodStar = randomDate(dateTimeStart,dateTimeStop, random()) periodEnd = randomDate(periodStar,dateTimeStop, random()) #equivalence = Equivalence(service,serviceQuantity,equivalenceS,equivalenceQuantity,periodStar,periodEnd) #print "aa", service,serviceQuantity,equivalenceS,equivalenceQuantity,periodStar,periodEnd service.addEquivalence(Equivalence(service,serviceQuantity,equivalenceS,equivalenceQuantity,periodStar,periodEnd)) equivalenceS.addEquivalence(Equivalence(equivalenceS,equivalenceQuantity,service,serviceQuantity,periodStar,periodEnd)) equivalenceRepository.addElement(service) equivalenceRepository.addElement(equivalenceS)
def createTrust(self,peer,peers,transactionNumber,dateTimeStart,dateTimeStop): keys= peers.keys() shuffle(keys) #directTrust = peer.getDirectTrust() directTrust = peer.getTrustManager().getDirectTrust() status = [True,False] for i in keys: peerID,peerN = i, peers[i] services = peerN.getServices() for countEle in range(0,randint(0,services.countElements())): element = services.getRandonElement() #print element.getUUID(),element.getResource() for countTrans in range(0,randint(0,transactionNumber)): rating= random() period = randomDate(dateTimeStart,dateTimeStop, random()) option = randint(0,1) directTrust.addElement(DirectTrust(peerID,element.getUUID(),element.getTag(),AbstractTrust.DIRECT,rating,period,status[option]))
def factorySimulationProcess(self): peers = {} simulation = self.getSimulation() network = simulation.getNetwork() contt = 0 peer_number = 0 while (simulation.getSimInstance().now() < simulation.getSimulationTime()): #yield hold, self, simulation.getNetwork().getNewPeerTime()*random() peer = network.getRandonPeer() if peer.getPID() in peers.keys(): if peers[peer.getPID()] < 4: peers[peer.getPID()] += 1 else: #print "tttttttttttttttttttttttttttttttttttt" continue else: peers[peer.getPID()] = 0 services = peer.getServices() if services.countElements()>=2: peer_number+=1 urn = "urn:trading:"+uuid.uuid1().__str__() logMsg = "Factoring Process %s => Simulation Time %10.2f making : id %s" % (self.getName(),simulation.getSimInstance().now() , urn) SimulationProcessLogger().resgiterLoggingInfo(logMsg) periodStart = randomDate(simulation.getTransactionDateTimeStart(),simulation.getTransactionDateTimeStop(), random()) periodEnd = randomDate(periodStart,simulation.getTransactionDateTimeStop(), random()) serviceQuantity = 5#randint(1,10) service = services.getElements().values()[randint(0,services.countElements()-1)] #print "Trading Service = %s = %s = %s = %s = %d "%(datetime.today(),peer.getPID(),service.getResource(),peers[peer.getPID()],contt) msg = "Trading Service = %s = %s = %s"%(datetime.today(),peer_number,simulation.getSimInstance().now()) print msg contt+=1 peer.getTradingManager().creatTradingService(service,periodStart,periodEnd,serviceQuantity,AbstractTrading.CLIENT,simulation.getSimInstance().now()) randa = randint(4,8)*6# yield hold, self, randa
def initialize( self, peerUUID, resourceUUID, resourceDescription, trustType=DIRECT, rating=0.5, period=randomDate("1/1/2010 1:30", "1/12/2010 4:50", random()), status=False, ): self.__uuid = createURN(trustType) self.__resourceUUID = resourceUUID self.__resourceDescription = resourceDescription self.__peerUUID = peerUUID self.__rating = rating self.__period = period self.__status = status self.__trustType = trustType TrustLogger().resgiterLoggingInfo( "Initialize Trust = URN = %s,Peer = %s ,Time %s, Description = %s rating = %f and status = %s" % (self.__uuid, self.__peerUUID, self.__period, self.__resourceDescription, self.__rating, self.__status) )