Exemple #1
0
    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')
Exemple #2
0
def entry_OK_to_add(args):
    OK = True
    if geo_location.is_station_present(args,args.station_name,args.station_number):
        print(args.station_name,'/',args.station_number,' already present.')
        OK = False
    if OK:
        if geo_location.is_station_active(args,args.station_name):
            print(args.station_name,'is already active.')
            if cm_utils._query_yn('Shall I deactivate it to add new station_number?'):
                dt = cm_utils._get_datetime(args.date,args.time)
                old_station_number = geo_location.is_station_active(args,args.station_name,True)
                data = [[args.station_name,old_station_number,'station_number_stop_date',dt]]
                geo_location.update(args,data)
            else:
                OK = False
    return OK
Exemple #3
0
def is_in_connections_db(args,station_name,check_if_active=False):
    db = mc.connect_to_mc_db(args)
    with db.sessionmaker() as session:
        connected_station = session.query(part_connect.Connections).filter(part_connect.Connections.up == station_name)
        if connected_station.count() > 0:
            station_connected = True
        else:
            station_connected = False
        if station_connected and check_if_active:
            current = cm_utils._get_datetime(args.date,args.time)
            for connection in connected_station.all():
                stop_date = cm_utils._get_stopdate(connection.stop_date)
                if current>connection.start_date and current<stop_date:
                    station_connected = int(connection.down.strip('A'))
                else:
                    station_connected = False
    return station_connected
Exemple #4
0
def find_station_name(args,station_number):
    station = 'A'+str(station_number)
    db = mc.connect_to_mc_db(args)
    with db.sessionmaker() as session:
        connected_station = session.query(part_connect.Connections).filter(part_connect.Connections.down == station)
        if connected_station.count() > 0:
            station_connected = True
        else:
            station_connected = False
        if station_connected:
            current = cm_utils._get_datetime(args.date,args.time)
            for connection in connected_station.all():
                stop_date = cm_utils._get_stopdate(connection.stop_date)
                if current>connection.start_date and current<stop_date:
                    station_connected = connection.up
                else:
                    station_connected = False
    return station_connected
Exemple #5
0
def add_entry(args):
    ###NotNull
    sname = args.station_name
    snumb = args.station_number
    start = cm_utils._get_datetime(args.date,args.time)
    mclsn = args.meta_class_name
    data = [[sname,snumb,'station_name',sname],
            [sname,snumb,'station_number',snumb],
            [sname,snumb,'meta_class_name',mclsn],
            [sname,snumb,'station_number_start_date',start]]
    ###Other
    if args.datum:
        data.append([sname,snumb,'datum',args.datum])
    if args.tile:
        data.append([sname,snumb,'tile',args.tile])
    if args.northing:
        data.append([sname,snumb,'northing',args.northing])
    if args.easting:
        data.append([sname,snumb,'easting',args.easting])
    if args.elevation:
        data.append([sname,snumb,'elevation',args.elevation])

    geo_location.update(args,data)
Exemple #6
0
    def get_hookup(self, args, hpn_query=None, rev_query=None, port_query=None, show_hookup=False):
        """
        Return the full hookup.  Note that if a part is selected up or down stream of a branching part, 
        it picks one and doesn't give all options -- something to work on.
        Returns hookup_dict, a dictionary keyed on derived key of hpn:port

        Parameters
        -----------
        args:  arguments as per mc and parts argument parser
        hpn_query:  the input hera part number (whole or first part thereof)
        port_query:  a specifiable port name,  default is 'all'
        show_hookup:  boolean to call show_hookup or not

        """
        self.current = cm_utils._get_datetime(args.date,args.time)
        exact_match = False
        if hpn_query is None:
            hpn_query = args.mapr
            exact_match = args.exact_match
        if rev_query is None:
            rev_query = args.revision_number
        if port_query is None:
            port_query = args.specify_port
        parts = self.get_part(args, hpn_query=hpn_query, rev_query=rev_query, 
                exact_match=exact_match, return_dictionary=True, show_part=False)
        connections = None
        hookup_dict = {}
        for hpn in parts.keys():
            if parts[hpn]['is_connected'] == False:
                continue
            number_a_ports = len(parts[hpn]['a_ports'])
            number_b_ports = len(parts[hpn]['b_ports'])
            if port_query == 'all':
                if number_b_ports>number_a_ports:
                    pq = 'b_ports'
                    alt_pq = 'a_ports'
                else:
                    pq = 'a_ports'
                    alt_pq = 'b_ports'
                port_query = parts[hpn][pq]
                if self.no_connection_designator in port_query:
                    port_query = parts[hpn][alt_pq]
            elif type(port_query) is not list:
                port_query = [port_query]
            for p in port_query:
                if p == self.no_connection_designator:
                    continue
                self.upstream = [[hpn,p]]
                self.downstream = []
                self.__go_upstream(args, hpn, rev_query, p)
                self.__go_downstream(args, hpn, rev_query, p)
                furthest_up = self.upstream[-1][0].strip('*')
                try_station = self.get_part(args,hpn_query=furthest_up,rev_query=rev_query,
                              exact_match=True, return_dictionary=True, show_part=False)
                keep_entry = True
                hukey = hpn+':'+p
                if try_station[furthest_up]['hptype'] == 'station':
                    hookup_dict[hukey] = [[str(try_station[furthest_up]['geo']['station_number']),'S']]
                else:
                    hookup_dict[hukey] = []
                for pn in reversed(self.upstream):
                    hookup_dict[hukey].append(pn)
                for pn in self.downstream:
                    hookup_dict[hukey].append(pn)
                #-#for pkey in hookup_dict.keys():
                #-#    print('#-#==>', hookup_dict[pkey])
        if len(hookup_dict.keys())==0:
            print(hpn_query,'not found')
            return None
        tkey = hookup_dict.keys()[0]
        hookup_dict['columns'] = []
        for hu in hookup_dict[tkey]:
            pn = hu[0].strip('*')
            if hu[1]=='S':
                hookup_dict['columns'].append(['station','column'])
            else:
                get_part_type = self.get_part(args,hpn_query=pn,rev_query=rev_query,
                                exact_match=True, return_dictionary=True, show_part=False)
                hookup_dict['columns'].append([get_part_type[pn]['hptype'],'column'])
        if args.show_levels:
            hookup_dict = self.__get_correlator_levels(hookup_dict,args.levels_testing)
        if show_hookup:
            self.show_hookup(hookup_dict,args.mapr_cols,args.show_levels,args.active)
        return hookup_dict