예제 #1
0
 def yes(self):
     if not self.primary.arr[6]:
         self.primary.arr[6] = getNow()
     else:
         dateline = self.primary.arr[6]
         dateline += "," + getNow()
         self.primary.arr[6] = dateline
     self.primary.commitToDB()
     self.primary.close()
     self.terminate()
예제 #2
0
def logPurge():
    if Config.doLogPurge:
        logTC("Starting log file purge...")
        filesToPurge = []
        filePaths = []
        purgePeriodAgo = Date(getNow()).dateobj - datetime.timedelta(days=Config.logPurgePeriod)
        purgePeriodAgo = Date(
            str(purgePeriodAgo.month) + "-" + str(purgePeriodAgo.day) + "-" + str(purgePeriodAgo.year)
        )
        for dirpath, _, filenames in os.walk(Config.loggingDir):
            for f in filenames:
                if f.endswith(".txt"):
                    lfDate = Date(findSS(f, "log-", ".txt"))
                    if lfDate.isPast(date=purgePeriodAgo):
                        filesToPurge.append(f)
                        filePaths.append(os.path.abspath(os.path.join(dirpath, f)))
        if len(filesToPurge) > 0:
            logTC("Found " + str(len(filesToPurge)) + " files to purge.")
            logTC("Purging now...")
            for f in range(0, len(filesToPurge)):
                logTC("Purging " + filesToPurge[f])
                os.remove(filePaths[f])
            logTC("Log file purge complete!")
        else:
            logTC("No files to purge found.")

    else:
        pass
예제 #3
0
    def __init__(self, primary, sub, geo="440x400"):
        self.primary = primary
        self.ew = tk.Toplevel(sub)
        self.ew.protocol("WM_DELETE_WINDOW", self.terminate)
        self.ew.geometry(geo)
        self.ew.wm_title("Issue Visitor Pass?")
        self.ew.focus_set()
        self.ew.grab_set()
        self.dates = []
        
        if self.primary.arr[7] in ("BLOCKED", "BARRED"):
            line1 = self.primary.fnameVar.get() + " " + self.primary.lnameVar.get() + " is " + self.primary.arr[7] + " and should NOT get a visitor pass."

            line2 = "Do you still want to issue a visitor pass for " + getNow() + "?"

            line3 = ""
        elif not self.primary.arr[7]:
            self.dates = multiParse(self.primary.arr[6])
            oneperiodago = Date(getNow()).dateobj - datetime.timedelta(days=Config.visitorcardperiod)
            oneperiodago = Date(str(oneperiodago.month) + '-' + str(oneperiodago.day) + '-' + str(oneperiodago.year))
            relevantdates = []
            for date in self.dates:
                if not date.isPast(date=oneperiodago):
                    relevantdates.append(date)
            numcards = len(relevantdates)
            if numcards >= 3:
                line1 = self.primary.fnameVar.get() + " " + self.primary.lnameVar.get() + " has gotten " + str(numcards) + " visitor cards"

                line2 = "within a " + str(Config.visitorcardperiod) + " day period of today, and should not get any more."
                
                line3 = "Do you still want to issue a visitor pass for " + getNow() + "?"
            elif numcards > 0:
                line1 = self.primary.fnameVar.get() + " " + self.primary.lnameVar.get() + " has gotten " + str(numcards) + " visitor card"
                if numcards is not 1:
                    line1 += "s"

                line2 = "within a " + str(Config.visitorcardperiod) + " day period of today. Do you want to issue a pass for " + getNow() + "?"

                line3 = ""
            else:
                line1 = "Visitor pass will be issued to " + self.primary.fnameVar.get() + " " + self.primary.lnameVar.get() + " for the date " + getNow()

                line2 = "Is this OK?"

                line3 = ""
        else:
            logTC("Invalid data in status field!", "ERROR")
            e = ErrorWindow(self.ew, "Invalid data in status field! (Please see and administrator)")
           
        self.msg1 = tk.Label(self.ew, text=line1)
        self.msg1.grid(row=1, column=1, columnspan=2, padx=PADX)

        self.msg2 = tk.Label(self.ew, text=line2)
        self.msg2.grid(row=2, column=1, columnspan=2, padx=PADX)

        self.msg3 = tk.Label(self.ew, text=line3)
        self.msg3.grid(row=3, column=1, columnspan=2, padx=PADX)

        self.datesLabel = tk.Label(self.ew, text="Dates Issued:")
        self.datesLabel.grid(row=4, column=1, columnspan=2, padx=PADX, pady=PADY)

        self.scrollbar = tk.Scrollbar(self.ew, orient="vertical", command=self.onScroll)
        self.scrollbar.grid(row=5, column=2, sticky='ns')
        
        self.datesLB = tk.Listbox(self.ew, yscrollcommand=self.scrollbar.set, width=25, height=10)
        self.datesLB.grid(row=5, column=1, columnspan=2)
        self.datesLB.bind("<MouseWheel>", self.onMouseWheel)
        
        self.affirmativeButton = tk.Button(self.ew, text="Yes", width=15, command=self.yes)
        self.affirmativeButton.grid(row=6, column=1, padx=PADX, pady=(10, 0))

        self.negativeButton = tk.Button(self.ew, text="No", width=15, command=self.terminate)
        self.negativeButton.grid(row=6, column=2, padx=PADX, pady=(10, 0))

        self.popDates()
예제 #4
0
def customFunction(obj):
    currentdate = Date(getNow())

    #Calculate total visitor cards issued
    res = 0
    for record in obj.data:
        try:
            for vcdate in multiParse(record[6]):
                res += 1
        except TypeError:
            pass
    obj.output("Total Visitor Cards issued: " + str(res) + "\n\n")
    
    #Calculate Visitor Cards YTD
    #set up the variable to hold the results
    res = 0
    #iterate through every record in the data
    for record in obj.data:
        try:
            #iterate through every date in the record
            for vcdate in multiParse(record[6]):
                #check to see if the year of the record is equal to the
                #current year
                if vcdate.year == currentdate.year:
                    #if it is, raise the result variable by 1
                    res += 1
        except TypeError:
            #if the date field is empty, do nothing.
            pass
    #output the result to the metrics window
    obj.output("Visitor cards issued YTD: " + str(res) + "\n\n")

    #Calculate Visitor Cards MTD
    res = 0
    for record in obj.data:
        try:
            for vcdate in multiParse(record[6]):
                if vcdate.year == currentdate.year:
                    if vcdate.month == currentdate.month:
                        res += 1
        except TypeError:
            pass
    obj.output("Visitor cards issued MTD: " + str(res) + "\n\n")

    #Calculate Average per day
    avg = 0
    earliest = None
    for record in obj.data:
        try:
            for vcdate in multiParse(record[6]):
                if not earliest:
                    earliest = vcdate
                else:
                    if vcdate.year < earliest.year:
                        earliest = vcdate
                    else:
                        if vcdate.month < earliest.month:
                            earliest = vcdate
                        else:
                            if vcdate.day < earliest.day:
                                earliest = vcdate
                            else:
                                pass
                avg += 1  
        except TypeError:
            pass
    elapsedtime = currentdate.dateobj - earliest.dateobj
    avg = avg / 1.0
    try:
        avg = avg / (elapsedtime.days + 1)
    except ZeroDivisionError:
        pass
    obj.output("Average Visitor Cards per Day: " + str(avg) + "\n\n")