def show_connection(self, args, connection_dict): """ Print out connection information. Uses tabulate package. Parameters ----------- args: arguments as per mc and parts argument parser connection_dict: input dictionary of parts, generated by self.get_connection """ current = _get_datetime(args.date,args.time) table_data = [] if args.verbosity == 'm': headers = ['Upstream', '<Port b:', ':Port a>', 'Part', '<Port b:', ':Port a>', 'Downstream'] elif args.verbosity == 'h': headers = ['Upstream', '<Port b:', ':Port a>', 'Part', '<Port b:', ':Port a>', 'Downstream'] for pkey in sorted(connection_dict.keys()): for i in range(len(connection_dict[pkey]['a_ports'])): up = self.__pull_out_component(connection_dict[pkey]['up_parts'],i) dn = self.__pull_out_component(connection_dict[pkey]['down_parts'],i) pta = self.__pull_out_component(connection_dict[pkey]['a_ports'],i) ptb = self.__pull_out_component(connection_dict[pkey]['b_ports'],i) bup = self.__pull_out_component(connection_dict[pkey]['b_on_up'],i) adn = self.__pull_out_component(connection_dict[pkey]['a_on_down'],i) rup = self.__pull_out_component(connection_dict[pkey]['repr_up'],i) rdown = self.__pull_out_component(connection_dict[pkey]['repr_down'],i) startup = self.__pull_out_component(connection_dict[pkey]['start_on_up'],i) stopup = self.__pull_out_component(connection_dict[pkey]['stop_on_up'],i) startdown = self.__pull_out_component(connection_dict[pkey]['start_on_down'],i) stopdown = self.__pull_out_component(connection_dict[pkey]['stop_on_down'],i) if args.active: show_it = False if cm_utils._is_active(current,startup,stopup): show_it = cm_utils._is_active(current,startdown,stopdown) else: show_it = True if show_it: if args.verbosity == 'h': if stopup>current: stopup = '-' if stopdown>current: stopdown = '-' table_data.append([startup,stopup,' ',' ',' ',startdown,stopdown]) table_data.append([up,bup,pta,pkey,ptb,adn,dn]) elif args.verbosity == 'm': if not args.show_active: if stopup>current: stop = '-' if stopdown>current: stopdown = '-' table_data.append([startup,stopup,' ',' ',' ',startdown,stopdown]) table_data.append([up,bup,pta,pkey,ptb,adn,dn]) else: print(rup,rdown) if args.verbosity=='m' or args.verbosity=='h': print(tabulate(table_data,headers=headers,tablefmt='orgtbl')) print('\n')
def show_part(self, args, part_dict): """ Print out part information. Uses tabulate package. Parameters ----------- args: arguments as per mc and parts argument parser part_dict: input dictionary of parts, generated by self.get_part """ current = cm_utils._get_datetime(args.date,args.time) table_data = [] if args.verbosity == 'm': headers = ['HERA P/N','Rev','Part Type','Mfg #','Start','Stop','Active'] elif args.verbosity == 'h': headers = ['HERA P/N','Rev','Part Type','Mfg #','Start','Stop','Active','A ports','B ports','Info','Geo'] for hpn in sorted(part_dict.keys()): is_active = cm_utils._is_active(current,part_dict[hpn]['start_date'],part_dict[hpn]['stop_date']) show_it = True if args.active: if not is_active: show_it = False if show_it: if is_active and part_dict[hpn]['is_connected']: active = 'Yes' elif is_active: active = 'N/C' else: active = 'No' if args.verbosity == 'h': td = [hpn, part_dict[hpn]['rev'], part_dict[hpn]['hptype'], part_dict[hpn]['manufacturer_number'], part_dict[hpn]['start_date'], part_dict[hpn]['stop_date'], connected] pts = '' for a in part_dict[hpn]['a_ports']: pts+=(a+', ') td.append(pts.strip().strip(',')) pts = '' for b in part_dict[hpn]['b_ports']: pts+=(b+', ') td.append(pts.strip().strip(',')) td.append(part_dict[hpn]['short_description']) if part_dict[hpn]['geo'] is not None: s = "{:.1f}E, {:.1f}N, {:.1f}m".format(part_dict[hpn]['geo']['easting'], part_dict[hpn]['geo']['northing'],part_dict[hpn]['geo']['elevation']) td.append(s) table_data.append(td) elif args.verbosity == 'm': table_data.append([hpn, part_dict[hpn]['rev'], part_dict[hpn]['hptype'], part_dict[hpn]['manufacturer_number'], part_dict[hpn]['start_date'], part_dict[hpn]['stop_date'], connected]) else: print(hpn, part_dict[hpn]['repr']) if args.verbosity=='m' or args.verbosity=='h': print(tabulate(table_data,headers=headers,tablefmt='orgtbl')) print('\n')