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 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 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])