Beispiel #1
0
    def shouldAddLastBlock(self):
        if self.isLastBlock():
            if Voted.objects.count() == Elector.objects.count():
                return True
        eb = ElectionBusiness()
        if eb.isLocked() and eb.hadFinished():
            return True

        return False
Beispiel #2
0
 def isLastBlock(self):
     eb =  ElectionBusiness()
     if self.shouldAddBlock():
         ec = eb.getCurrentElectionConfig()
         if (Voted.objects.count()-ec.min_votes_in_last_block)/Elector.objects.count() > ec.attendance_rate:
             return True
     if eb.isLocked() and eb.hadFinished():
         return True
     return False
Beispiel #3
0
 def shouldAddBlock(self):
     eb = ElectionBusiness()
     # While election is occurring, new blocks should be generated.
     if eb.isOccurring():
         return True
     if eb.isLocked() and eb.hadFinished():
         return True
     ec = eb.getCurrentElectionConfig()
     if not ec:
         raise DatabaseError('There is not Election Configuration for the current election')
     # Independently of election is occurring, if we have votes, a new block must be generated.
     if Voted.objects.filter(hash_val__isnull=True).count() > 0:
         return True
     # If election is not occurring and we do not have votes we do not need to generate a block.
     return False