示例#1
0
def remove_old_documents():
    output = []
    randomizedDocument_list = RandomizedDocument.objects.filter(active=True).exclude(mopDocument__clearance=Clearance.CLEARANCE_WHITE)
    for randomizedDocument in randomizedDocument_list:
        if randomizedDocument.dueAt and randomizedDocument.dueAt < now():
            randomizedDocument.active = False
            randomizedDocument.save()
            output.append(randomizedDocument.serial)
            
            mopDocumentInstance_list = MopDocumentInstance.objects.filter(randomizedDocument=randomizedDocument).filter(status=MopDocumentInstance.STATUS_ACTIVE)
            for mopDocumentInstance in mopDocumentInstance_list:
                mopDocumentInstance.status = MopDocumentInstance.STATUS_REVOKED
                mopDocumentInstance.save()
                
                mail = Mail()
                mail.mop = mopDocumentInstance.mop
                mail.type = Mail.TYPE_RECEIVED
                mail.processed = True
                mail.unit = mopDocumentInstance.randomizedDocument.unit
                mail.subject = Mail.SUBJECT_REVOKE_DOCUMENT
                mail.bodyType = Mail.BODY_REVOKING_DOCUMENT
                mail.mopDocumentInstance = mopDocumentInstance
                mail.trust = mopDocumentInstance.getTrustFinal()
                mail.save()
                
                mopDocumentInstance.mop.mopTracker.addTrust(mopDocumentInstance.getTrustFinal(), True)
                mopDocumentInstance.mop.mopTracker.save()
                
    return output
示例#2
0
文件: models.py 项目: bachour/deptx
 def hasAppeared(self):
     if self.isTutorial:
         return True
     try:
         if self.appearAt <= now():
             return True
         else:
             return False
     except:
         return True
示例#3
0
文件: models.py 项目: bachour/deptx
 def hasTimeLeft(self):
     if self.isTutorial:
         return True
     try:
         if self.dueAt > now():
             return True
         else:
             return False
     except:
         return True
示例#4
0
def delayedEnough(mail, delay):
    if mail.mop.mopTracker.tutorial < MopTracker.TUTORIAL_6_DONE:
        print "tutorial so no delay"
        return True
    elif mail.mop.user.is_staff:
        print "staff so no delay"
        return True
    
    difference = (now() - mail.sentAt).total_seconds()
    if difference >= delay:
        if getrandbits(1):
            print "coin win"
            return True
        else:
            print "coin loss"
            return False
    else:
        print "too fresh"
        return False
示例#5
0
def analyze_performance():
    mopTracker_list = MopTracker.objects.all()
    for mopTracker in mopTracker_list:
        trustInstance = TrustInstance(mop=mopTracker.mop, totalTrust=mopTracker.totalTrust, oldTrust=mopTracker.trust, oldClearance=mopTracker.clearance)
        mopTracker.check_for_demotion()
        mopTracker.check_for_promotion()
        trustInstance.newClearance = mopTracker.clearance
        trustInstance.specialStatus = mopTracker.hasSpecialStatus
        try:
            mopDocumentInstance = MopDocumentInstance.objects.filter(mop=mopTracker.mop, correct=True, status=MopDocumentInstance.STATUS_REPORTED).order_by('-modifiedAt')[0]
        except:
            mopDocumentInstance = None
        if not mopDocumentInstance == None:
            age = now() - mopDocumentInstance.modifiedAt
            if age > timedelta(days=3):
                if mopTracker.trust > 0:
                    mopTracker.trust = mopTracker.trust * 0.9
                else:
                    mopTracker.trust = 0
        trustInstance.newTrust = mopTracker.trust
        mopTracker.save()
        trustInstance.save()
示例#6
0
def create_single_document(mopDocument):
    randomizedDocument = randomize_document(mopDocument)
    randomizedDocument.appearAt = now()
    randomizedDocument.dueAt = now() + timedelta(days=1)
    randomizedDocument.save()
    return randomizedDocument.serial
示例#7
0
文件: models.py 项目: bachour/deptx
 def secondsToStart(self):
     difference = self.startTime - now()
     days = difference.days
     seconds = difference.seconds
     totalSeconds = seconds + (days * 24 * 60 * 60) 
     return totalSeconds
示例#8
0
文件: models.py 项目: bachour/deptx
 def hasClosed(self):
     return now() > self.closeTime    
示例#9
0
文件: models.py 项目: bachour/deptx
 def hasStopped(self):
     return now() > self.stopTime
示例#10
0
文件: models.py 项目: bachour/deptx
 def hasStarted(self):
     return now() > self.startTime
示例#11
0
def analyze_performance(simulation=False):
    output = []

    if simulation:
        output.append("RUNNING SIMULATION")

    # if not simulation:
    #    revokeDocuments()

    mopTracker_list = MopTracker.objects.all().order_by("trust")
    output.append("MoPs under performance review: %d" % mopTracker_list.count())
    lastPeriod, thisPeriod, days = getPeriods()
    today = now().date()

    if not simulation:
        if not thisPeriod.reviewDate == today:
            output.append(
                "No review scheduled for today (%s). Next review scheduled for %s" % (today, thisPeriod.reviewDate)
            )
            return output
        output.append(
            "Last review: %s, This review: %s, Days since last review: %s"
            % (lastPeriod.reviewDate, thisPeriod.reviewDate, days)
        )
        if days == 0:
            output.append("No performance review possible.")
            return output
    else:
        output.append(
            "Last review: %s, This review: %s, Days since last review: %s"
            % (lastPeriod.reviewDate, thisPeriod.reviewDate, days)
        )

    for mopTracker in mopTracker_list:
        performanceInstance, out = doPerformance(mopTracker.mop, thisPeriod, days)
        output.append(out)
        if simulation:
            continue
        performanceInstance.save()

        mopTracker.clearance = performanceInstance.result
        mopTracker.totalTrust += mopTracker.trust
        mopTracker.trust = 0
        mopTracker.credit = performanceInstance.credit
        mopTracker.save()

        unit = Unit.objects.filter(type=Unit.TYPE_ADMINISTRATIVE)[0]

        mail = Mail(
            mop=mopTracker.mop,
            performanceInstance=performanceInstance,
            unit=unit,
            subject=Mail.SUBJECT_INFORMATION,
            type=Mail.TYPE_RECEIVED,
        )
        if performanceInstance.type == PerformanceInstance.TYPE_PROMOTION:
            mail.bodyType = Mail.BODY_PERFORMANCE_REPORT_PROMOTION
        elif performanceInstance.type == PerformanceInstance.TYPE_DEMOTION:
            mail.bodyType = Mail.BODY_PERFORMANCE_REPORT_DEMOTION
        else:
            mail.bodyType = Mail.BODY_PERFORMANCE_REPORT_NEUTRAL
        mail.save()
        logging.log_action(ActionLog.ACTION_MOP_RECEIVE_MAIL_PERFORMANCE, mop=mopTracker.mop, mail=mail)
    if not simulation:
        thisPeriod.processed = True
        thisPeriod.reviewTime = now().time()
        thisPeriod.save()
        if not PerformancePeriod.objects.filter(processed=False):
            newPeriod = PerformancePeriod()
            newDate = thisPeriod.reviewDate + datetime.timedelta(days=14)
            newPeriod.reviewDate = newDate
            newPeriod.save()
    return output