def rpt_carrier_history(carrier):
     """ generates a report showing all records from a specified carrier. """
     sql = "SELECT effective_date, list_status, ns_day, route_s, station" \
           " FROM carriers WHERE carrier_name = '%s' ORDER BY effective_date DESC" % carrier
     results = inquire(sql)
     stamp = datetime.now().strftime("%Y%m%d_%H%M%S")
     filename = "report_carrier_history" + "_" + stamp + ".txt"
     report = open(dir_path('report') + filename, "w")
     report.write("\nCarrier Status Change History\n\n")
     report.write(
         '   Showing all status changes in the klusterbox database for {}\n\n'
         .format(carrier))
     report.write('{:<16}{:<8}{:<10}{:<31}{:<25}\n'.format(
         "Date Effective", "List", "N/S Day", "Route/s", "Station"))
     report.write(
         '----------------------------------------------------------------------------------\n'
     )
     i = 1
     for line in results:
         report.write('{:<16}{:<8}{:<10}{:<31}{:<25}\n'.format(
             dt_converter(line[0]).strftime("%m/%d/%Y"), line[1], line[2],
             line[3], line[4]))
         if i % 3 == 0:
             report.write(
                 '----------------------------------------------------------------------------------\n'
             )
         i += 1
     report.close()
     if sys.platform == "win32":  # open the text document
         os.startfile(dir_path('report') + filename)
     if sys.platform == "linux":
         subprocess.call(["xdg-open", 'kb_sub/report/' + filename])
     if sys.platform == "darwin":
         subprocess.call(["open", dir_path('report') + filename])
 def pay_period_guide(self):
     """
     creates a txt file which is saved in the archive which list out the pay periods for a year.
     """
     i = 0
     year = simpledialog.askinteger("Pay Period Guide",
                                    "Enter the year you want generated.",
                                    parent=self.frame,
                                    minvalue=2,
                                    maxvalue=9999)
     if year is not None:
         firstday = datetime(1, 12, 22)
         while int(firstday.strftime("%Y")) != year - 1:
             firstday += timedelta(weeks=52)
             if int(firstday.strftime("%m")) <= 12 and int(
                     firstday.strftime("%d")) <= 12:
                 firstday += timedelta(weeks=2)
         filename = "pp_guide" + "_" + str(
             year) + ".txt"  # create the filename for the text doc
         report = open(dir_path('pp_guide') + filename,
                       "w")  # create the document
         report.write("\nPay Period Guide\n")
         report.write("Year: " + str(year) + "\n")
         report.write("---------------------------------------------\n\n")
         report.write(
             "                 START (Sat):   END (Fri):         \n")
         for i in range(1, 27):
             # calculate dates
             wk1_start = firstday
             wk1_end = firstday + timedelta(days=6)
             wk2_start = firstday + timedelta(days=7)
             wk2_end = firstday + timedelta(days=13)
             report.write("PP: " + str(i).zfill(2) + "\n")
             report.write("\t week 1: " + wk1_start.strftime("%b %d, %Y") +
                          " - " + wk1_end.strftime("%b %d, %Y") + "\n")
             report.write("\t week 2: " + wk2_start.strftime("%b %d, %Y") +
                          " - " + wk2_end.strftime("%b %d, %Y") + "\n")
             # increment the first day by two weeks
             firstday += timedelta(days=14)
         # handle cases where there are 27 pay periods
         if int(firstday.strftime("%m")) <= 12 and int(
                 firstday.strftime("%d")) <= 12:
             i += 1
             wk1_start = firstday
             wk1_end = firstday + timedelta(days=6)
             wk2_start = firstday + timedelta(days=7)
             wk2_end = firstday + timedelta(days=13)
             report.write("PP: " + str(i).zfill(2) + "\n")
             report.write("\t week 1: " + wk1_start.strftime("%b %d, %Y") +
                          " - " + wk1_end.strftime("%b %d, %Y") + "\n")
             report.write("\t week 2: " + wk2_start.strftime("%b %d, %Y") +
                          " - " + wk2_end.strftime("%b %d, %Y") + "\n")
         report.close()
         if sys.platform == "win32":
             os.startfile(dir_path('pp_guide') + filename)
         if sys.platform == "linux":
             subprocess.call(["xdg-open", 'kb_sub/pp_guide/' + filename])
         if sys.platform == "darwin":
             subprocess.call(["open", dir_path('pp_guide') + filename])
 def rpt_carrier(self):
     """ Generate and display a report of carrier routes and nsday """
     self.get_carrierlist()
     ns_dict = NsDayDict.get_custom_nsday(
     )  # get the ns day names from the dbase
     stamp = datetime.now().strftime("%Y%m%d_%H%M%S")  # create a file name
     filename = "report_carrier_route_nsday" + "_" + stamp + ".txt"
     report = open(dir_path('report') + filename, "w")
     report.write("\nCarrier Route and NS Day Report\n\n\n")
     report.write('   Showing results for:\n')
     report.write('      Station: {}\n'.format(projvar.invran_station))
     if not projvar.invran_weekly_span:  # if investigation range is daily
         f_date = projvar.invran_date
         report.write('      Date: {}\n'.format(
             f_date.strftime("%m/%d/%Y")))
     else:  # if investigation range is weekly
         f_date = projvar.invran_date_week[
             0]  # use the first day of the service week
         report.write('      Dates: {} through {}\n'.format(
             projvar.invran_date_week[0].strftime("%m/%d/%Y"),
             projvar.invran_date_week[6].strftime("%m/%d/%Y")))
     report.write('      Pay Period: {}\n\n'.format(projvar.pay_period))
     report.write('{:>4} {:<23} {:<13} {:<29} {:<10}\n'.format(
         "", "Carrier Name", "N/S Day", "Route/s", "Start Date"))
     report.write(
         '     ------------------------------------------------------------------- ----------\n'
     )
     i = 1
     for line in self.carrier_list:
         ii = 0
         for rec in reversed(line):
             if not ii:
                 report.write('{:>4} {:<23} {:<4} {:<8} {:<29}\n'.format(
                     i, rec[1], projvar.ns_code[rec[3]],
                     self.rpt_ns_fixer(ns_dict[rec[3]]), rec[4]))
             else:
                 report.write(
                     '{:>4} {:<23} {:<4} {:<8} {:<29} {:<10}\n'.format(
                         "", rec[1], projvar.ns_code[rec[3]],
                         self.rpt_ns_fixer(ns_dict[rec[3]]), rec[4],
                         self.rpt_dt_limiter(dt_converter(rec[0]),
                                             f_date).strftime("%A")))
             ii += 1
         if i % 3 == 0:
             report.write(
                 '     ------------------------------------------------------------------- ----------\n'
             )
         i += 1
     report.close()
     if sys.platform == "win32":  # open the text document
         os.startfile(dir_path('report') + filename)
     if sys.platform == "linux":
         subprocess.call(["xdg-open", 'kb_sub/report/' + filename])
     if sys.platform == "darwin":
         subprocess.call(["open", dir_path('report') + filename])
 def rpt_carrier_route(self):
     """ Generate and display a report of carrier routes """
     self.get_carrierlist()
     stamp = datetime.now().strftime("%Y%m%d_%H%M%S")
     filename = "report_carrier_route" + "_" + stamp + ".txt"
     report = open(dir_path('report') + filename, "w")
     report.write("\nCarrier Route Report\n\n\n")
     report.write('   Showing results for:\n')
     report.write('      Station: {}\n'.format(projvar.invran_station))
     if not projvar.invran_weekly_span:  # if investigation range is daily
         f_date = projvar.invran_date
         report.write('      Date: {}\n'.format(
             f_date.strftime("%m/%d/%Y")))
     else:
         f_date = projvar.invran_date_week[0]
         report.write('      Date: {} through {}\n'.format(
             projvar.invran_date_week[0].strftime("%m/%d/%Y"),
             projvar.invran_date_week[6].strftime("%m/%d/%Y")))
     report.write('      Pay Period: {}\n\n'.format(projvar.pay_period))
     report.write('{:>4}  {:<22} {:<29}\n'.format("", "Carrier Name",
                                                  "Route/s"))
     report.write(
         '      ---------------------------------------------------- -------------------\n'
     )
     i = 1
     for line in self.carrier_list:
         ii = 0
         for rec in reversed(
                 line):  # reverse order so earliest one appears first
             if not ii:  # if the first record
                 report.write('{:>4}  {:<22} {:<29}\n'.format(
                     i, rec[1], rec[4]))
             else:  # if not the first record, use alternate format
                 report.write(
                     '{:>4}  {:<22} {:<29} effective {:<10}\n'.format(
                         "", rec[1], rec[4],
                         self.rpt_dt_limiter(dt_converter(rec[0]),
                                             f_date).strftime("%A")))
             ii += 1
         if i % 3 == 0:
             report.write(
                 '      ---------------------------------------------------- -------------------\n'
             )
         i += 1
     report.close()
     if sys.platform == "win32":  # open the text document
         os.startfile(dir_path('report') + filename)
     if sys.platform == "linux":
         subprocess.call(["xdg-open", 'kb_sub/report/' + filename])
     if sys.platform == "darwin":
         subprocess.call(["open", dir_path('report') + filename])
 def tacs_cheatsheet():
     """ generate a tacs cheatsheet for the user. """
     stamp = datetime.now().strftime("%d%H%M%S")  # create a file name
     filename = "tacs_cheatsheet" + "_" + stamp + ".txt"
     report = open(dir_path('report') + filename, "w")
     report.write("TACS Cheat Sheet\n")
     report.write("\nD/A (Designation and Activity) Codes:\n\n")
     report.write("13-4 .......... Full Time Regular (FTR)\n")
     report.write("33-4 .......... Part Time Regular (PTR)\n")
     report.write("43-4 .......... Part Time Flexible (PTF)\n")
     report.write("84-4 .......... City Carrier Assistant (CCA)\n")
     report.write("11-0 .......... Clerk\n")
     report.write("16-6 .......... Maintenance\n")
     report.write("09-0 .......... Supervisor/ Manager\n")
     report.write("\nHour Codes:\n\n")
     report.write("5200 .......... Work Hours\n")
     report.write("5300 .......... Overtime Hours\n")
     report.write("4300 .......... Penalty Overtime\n")
     report.write("4800 .......... Holiday Premium Pay\n")
     report.write("49## .......... OWCP Leave Without Pay (LWOP)\n")
     report.write("5400 .......... Night Work Premium\n")
     report.write("55## .......... Annual Leave\n")
     report.write("56## .......... Sick Leave\n")
     report.write("5800 .......... Holiday Leave\n")
     report.write("59## .......... Leave Without Pay (LWOP) - Part Day\n")
     report.write("60## .......... Leave Without Pay (LWOP) - Full Day\n")
     report.write("2400 .......... Absent Without Leave (AWOL)\n")
     report.write("\nOperation Codes:\n\n")
     report.write("721 ........... Street Time\n")
     report.write("722 ........... Office Time\n")
     report.write("613 ........... Stewards Time\n")
     report.write("354 ........... Standby Time\n")
     report.write("743 ........... Route Maintenance\n")
     report.write("\nMove Codes:\n\n")
     report.write("BT ............ Begin Tour\n")
     report.write("MV 7210-## .... Move to Street\n")
     report.write("MV 7220-## .... Move to Office\n")
     report.write("093 ........... No Lunch\n")
     report.write("OL ............ Begin Lunch\n")
     report.write("IL ............ End Lunch\n")
     report.write("ET ............ End Tour\n")
     report.close()
     if sys.platform == "win32":  # open the text document
         os.startfile(dir_path('report') + filename)
     if sys.platform == "linux":
         subprocess.call(["xdg-open", dir_path('report') + filename])
     if sys.platform == "darwin":
         subprocess.call(["open", dir_path('report') + filename])
    def rpt_dov_history(date_array, history_array):
        """ Generate and display a report of dispatch of value times for a station """
        stamp = datetime.now().strftime("%Y%m%d_%H%M%S")  # create a file name
        filename = "report_dov_history" + "_" + stamp + ".txt"
        report = open(dir_path('report') + filename, "w")
        report.write("\nDispatch of Value History\n\n\n")
        report.write('   Showing results for:\n')
        report.write('      Station: {}\n\n'.format(projvar.invran_station))

        report.write(
            '{:>4} {:<16} {:<7} {:<7} {:<7} {:<7} {:<7} {:<7} {:<7} \n'.format(
                "", "Effective Date", "sat", "sun", "mon", "tue", "wed", "thu",
                "fri"))
        report.write(
            '     -----------------------------------------------------------------------------\n'
        )
        i = 1
        for line in history_array:
            date = Convert(date_array[i - 1]).str_to_dt()
            date = Convert(date).dt_to_backslash_str()
            report.write(
                '{:>4} {:<16} {:<7} {:<7} {:<7} {:<7} {:<7} {:<7} {:<7}\n'.
                format("", date, line[0], line[1], line[2], line[3], line[4],
                       line[5], line[6]))
            if i % 3 == 0:
                report.write(
                    '     -----------------------------------------------------------------------------\n'
                )
            i += 1
        report.write('\n\n\n')
        report.write(
            ' This report shows the settings for dispatch of value (DOV) times. The most recent \n'
            ' records will be on the top and earlier records lower on the list. \n\n'
            ' Effective Date is the first day of the service week and will always be a Saturday. \n'
            ' this is the date on which the record is effective. The record will apply to later \n'
            ' days of the week until updated/changed.\n\n'
            ' * Asterisks denote a temporary record. Such records will only apply for one day, \n'
            ' after which the earlier non-temporary will apply.\n\n'
            ' The bottom record is the default. It generates automatically and can not/ should \n'
            ' not be deleted. The time set in the default records is arbitrary and is not \n'
            ' necessarily the correct time.')
        report.close()
        if sys.platform == "win32":  # open the text document
            os.startfile(dir_path('report') + filename)
        if sys.platform == "linux":
            subprocess.call(["xdg-open", 'kb_sub/report/' + filename])
        if sys.platform == "darwin":
            subprocess.call(["open", dir_path('report') + filename])
 def open(self):
     """ open the file.  """
     self.target_file.close()
     self.csv_fix.destroy()
     self.report.close()
     try:
         if sys.platform == "win32":
             os.startfile(dir_path('over_max') + self.filename)
         if sys.platform == "linux":
             subprocess.call(["xdg-open", 'kb_sub/over_max/' + self.filename])
         if sys.platform == "darwin":
             subprocess.call(["open", dir_path('over_max') + self.filename])
     except PermissionError:
         messagebox.showerror("Report Generator",
                              "The report was not generated.",
                              parent=self.frame)
def ee_skimmer(frame):
    """ This the function called for the csv everything report reader """
    days = ("Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
    mv_codes = ("BT", "MV", "ET")
    carrier = []
    path = dir_filedialog()
    file_path = filedialog.askopenfilename(initialdir=path, filetypes=[("Excel files", "*.csv *.xls")])
    if file_path[-4:].lower() == ".csv" or file_path[-4:].lower() == ".xls":
        pass
    else:
        messagebox.showerror("Report Generator",
                             "The file you have selected is not a .csv or .xls file.\n"
                             "You must select a file with a .csv or .xls extension.",
                             parent=frame)
        return
    csv_fix = CsvRepair()  # create a CsvRepair object
    # returns a file path for a checked and, if needed, fixed csv file.
    file_path = csv_fix.run(file_path)
    target_file = open(file_path, newline="")
    with target_file as file:
        a_file = csv.reader(file)
        cc = 0
        good_id = "no"
        for line in a_file:
            if cc == 0:
                if line[0][:8] != "TAC500R3":
                    messagebox.showwarning("File Selection Error",
                                           "The selected file does not appear to be an "
                                           "Employee Everything report.",
                                           parent=frame)
                    target_file.close()  # close the opened file which is no longer being read
                    csv_fix.destroy()  # destroy the CsvRepair object and the proxy csv file
                    return
            if cc == 2:
                pp = line[0]  # find the pay period
                filename = "ee_reader" + "_" + pp + ".txt"
                try:
                    report = open(dir_path('ee_reader') + filename, "w")
                except (PermissionError, FileNotFoundError):
                    messagebox.showwarning("Report Generator",
                                           "The Employee Everything Report Reader "
                                           "was not generated.",
                                           parent=frame)
                    target_file.close()  # close the opened file which is no longer being read
                    csv_fix.destroy()  # destroy the CsvRepair object and the proxy csv file
                    return
                report.write("\nEmployee Everything Report Reader\n")
                report.write(
                    "pay period: " + pp[:-3] + " " + pp[4] + pp[5] + "-" + pp[6] + "\n\n")  # printe pay period
            if cc != 0:
                if good_id != line[4] and good_id != "no":  # if new carrier or employee
                    ee_analysis(carrier, report)  # trigger analysis
                    del carrier[:]  # empty array
                    good_id = "no"  # reset trigger
                # find first line of specific carrier
                if line[18] == "Base" and line[19] in ("844", "134", "434"):
                    good_id = line[4]  # set trigger to id of carriers who are FT or aux carriers
                    carrier.append(line)  # gather times and moves for anaylsis
                if good_id == line[4] and line[18] != "Base":
                    if line[18] in days:  # get the hours for each day
                        carrier.append(line)  # gather times and moves for anaylsis
                    if line[19] in mv_codes and line[32] != "(W)Ring Deleted From PC":
                        carrier.append(line)  # gather times and moves for anaylsis
            cc += 1
        ee_analysis(carrier, report)  # when loop ends, run final analysis
        del carrier[:]  # empty array
        report.close()
        if sys.platform == "win32":
            os.startfile(dir_path('ee_reader') + filename)
        if sys.platform == "linux":
            subprocess.call(["xdg-open", 'kb_sub/ee_reader/' + filename])
        if sys.platform == "darwin":
            subprocess.call(["open", dir_path('ee_reader') + filename])
    target_file.close()  # close the opened file which is no longer being read
    csv_fix.destroy()  # destroy the CsvRepair object and the proxy csv file
 def make_report(self):
     """ make report object """
     pp_str = self.pp[:-3] + "_" + self.pp[4] + self.pp[5] + "_" + self.pp[6]
     self.filename = "max" + "_" + pp_str + ".txt"
     self.report = open(dir_path('over_max') + self.filename, "w")
Beispiel #10
0
 def rpt_carrier_by_list(self):
     """ generates a report which shows carriers by the list. """
     self.get_carrierlist()
     list_dict = {
         "nl": "No List",
         "wal": "Work Assignment List",
         "otdl": "Overtime Desired List",
         "ptf": "Part Time Flexible",
         "aux": "Auxiliary Carrier"
     }
     # initialize arrays for data sorting
     otdl_array = []
     wal_array = []
     nl_array = []
     ptf_array = []
     aux_array = []
     for line in self.carrier_list:
         for carrier in line:
             if carrier[2] == "otdl":
                 otdl_array.append(carrier)
             if carrier[2] == "wal":
                 wal_array.append(carrier)
             if carrier[2] == "nl":
                 nl_array.append(carrier)
             if carrier[2] == "ptf":
                 ptf_array.append(carrier)
             if carrier[2] == "aux":
                 aux_array.append(carrier)
     array_var = nl_array + wal_array + otdl_array + ptf_array + aux_array  #
     stamp = datetime.now().strftime("%Y%m%d_%H%M%S")  # create a file name
     filename = "report_carrier_by_list" + "_" + stamp + ".txt"
     report = open(dir_path('report') + filename, "w")
     report.write("\nCarrier by List\n\n")
     report.write('   Showing results for:\n')
     report.write('      Station: {}\n'.format(projvar.invran_station))
     if not projvar.invran_weekly_span:  # if investigation range is daily
         f_date = projvar.invran_date
         report.write('      Date: {}\n'.format(
             f_date.strftime("%m/%d/%Y")))
     else:
         f_date = projvar.invran_date_week[0]
         report.write('      Dates: {} through {}\n'.format(
             projvar.invran_date_week[0].strftime("%m/%d/%Y"),
             projvar.invran_date_week[6].strftime("%m/%d/%Y")))
     report.write('      Pay Period: {}\n'.format(projvar.pay_period))
     i = 1
     last_list = ""  # this is a indicator for when a new list is starting
     for line in array_var:
         if last_list != line[
                 2]:  # if the new record is in a different list that the last
             report.write('\n\n      {:<20}\n\n'.format(
                 list_dict[line[2]]))  # write new headers
             report.write('{:>4}  {:<22} {:>4}\n'.format(
                 "", "Carrier Name", "List"))
             report.write(
                 '      ---------------------------  -------------------\n')
             i = 1
         if dt_converter(line[0]) not in projvar.invran_date_week:
             report.write('{:>4}  {:<22} {:>4}\n'.format(
                 i, line[1], line[2]))
         else:
             report.write('{:>4}  {:<22} {:>4}  effective {:<10}\n'.format(
                 i, line[1], line[2],
                 self.rpt_dt_limiter(dt_converter(line[0]),
                                     f_date).strftime("%A")))
         if i % 3 == 0:
             report.write(
                 '      ---------------------------  -------------------\n')
         last_list = line[2]
         i += 1
     report.close()
     if sys.platform == "win32":  # open the text document
         os.startfile(dir_path('report') + filename)
     if sys.platform == "linux":
         subprocess.call(["xdg-open", 'kb_sub/report/' + filename])
     if sys.platform == "darwin":
         subprocess.call(["open", dir_path('report') + filename])