Beispiel #1
0
def test_rosetta(mcsession, capsys):
    active = cm_active.ActiveData(mcsession)
    at_date = Time('2020-07-01 01:00:00', scale='utc')
    active.load_parts(at_date)
    active.load_rosetta(at_date)
    assert active.rosetta['SNPC000700'].syspn == 'heraNode700Snap700'
    print(active.rosetta['SNPC000700'])
    captured = capsys.readouterr()
    assert captured.out.strip().startswith('<SNPC000700')
    cm_partconnect.update_part_rosetta('SNPC000702',
                                       'heraNode700Snap1',
                                       at_date,
                                       session=mcsession)
    active.load_rosetta(at_date)
    assert active.rosetta['SNPC000702'].syspn == 'heraNode700Snap1'
    stop_at = Time('2020-08-01 01:00:00', scale='utc')
    cm_partconnect.update_part_rosetta('SNPC000701', 'heraNode700Snap2',
                                       at_date, stop_at, mcsession)
    active.load_rosetta(Time('2020-07-15 01:00:00', scale='utc'))
    assert int(active.rosetta['SNPC000701'].stop_gpstime) == 1280278818
    cm_partconnect.update_part_rosetta('SNPC000709',
                                       'heraNode700Snap709',
                                       stop_at,
                                       session=mcsession)
    assert int(active.rosetta['SNPC000709'].stop_gpstime) == 1280278818
    # Add a test part to fail on update part
    rose = cm_partconnect.PartRosetta()
    rose.hpn = 'SNPC000701'
    rose.syspn = 'heraNode0Snap701'
    rose.start_gpstime = Time('2019-07-15 01:00:00', scale='utc').gps
    mcsession.add(rose)
    mcsession.commit()
    with pytest.raises(ValueError,
                       match="Multiple rosetta relationships active"
                       " for heraNode0Snap701"):
        cm_partconnect.update_part_rosetta('SNPC000701', 'heraNode0Snap701',
                                           stop_at, None, mcsession)
    # Add a test part to fail on load active
    rose = cm_partconnect.PartRosetta()
    rose.hpn = 'SNPC000701'
    rose.syspn = 'heraNode700Snap700'
    rose.start_gpstime = Time('2019-07-01 01:00:00', scale='utc').gps
    mcsession.add(rose)
    mcsession.commit()
    pytest.raises(ValueError, active.load_rosetta)
    rose2 = cm_partconnect.PartRosetta()
    rose2.hpn = 'SNPC000712'
    rose2.syspn = 'heraNode712Snap712'
    rose2.start_gpstime = Time('2019-07-01 01:00:00', scale='utc').gps
    rose2.stop_gpstime = Time('2020-08-01 01:00:00', scale='utc').gps
    mcsession.add(rose2)
    mcsession.commit()
    with pytest.warns(
            UserWarning,
            match="No action taken.  <SNPC000712  -  heraNode712Snap712 ::"
            " 1245978018 - 1280278818> already has a valid stop date"):
        cm_partconnect.update_part_rosetta('SNPC000712',
                                           'heraNode712Snap712',
                                           '2020/01/02',
                                           session=mcsession)
Beispiel #2
0
def test_active_revisions_mixed_start_time(parts):
    test_part = 'test_part2'
    test_rev = 'Q'
    test_hptype = 'antenna'
    start_time = Time('2019-07-01 00:30:00', scale='utc')

    # Add a test part
    part = cm_partconnect.Parts()
    part.hpn = test_part
    part.hpn_rev = test_rev
    part.hptype = test_hptype
    part.manufacture_number = 'XYZ'
    part.start_gpstime = start_time.gps
    parts.test_session.add(part)
    parts.test_session.commit()

    active = cm_active.ActiveData(parts.test_session)
    active.load_parts()
    key_order = np.argsort(
        [active.parts[k].start_gpstime for k in active.parts.keys()])
    key_order = [list(active.parts.keys())[k] for k in key_order]
    # print(active.parts[key_order[-1]])
    # print(active.parts[key_order[-2]])
    key_order[-1], key_order[-2] = key_order[-2], key_order[-1]
    active.parts = OrderedDict({key: active.parts[key] for key in key_order})
    # vals = list(active.parts.values())
    # print(vals[0])
    # print(vals[1])
    revs = active.revs('TEST_PART')

    assert revs[0].hpn == 'TEST_PART'
    assert revs[0].number == 2
    assert revs[0].started == start_time.gps
Beispiel #3
0
def test_active_revisions_mixed_stop_time(parts):
    test_part = 'new_part2'
    test_rev = 'Q'
    test_hptype = 'antenna'
    start_time = Time('2019-07-01 00:30:00', scale='utc')
    stop_time = Time('2050-07-01 01:45:00', scale='utc')

    # Add a test part
    part = cm_partconnect.Parts()
    part.hpn = test_part
    part.hpn_rev = test_rev
    part.hptype = test_hptype
    part.manufacture_number = 'XYZ'
    part.start_gpstime = start_time.gps
    part.stop_gpstime = stop_time.gps
    parts.test_session.add(part)
    parts.test_session.commit()
    #
    test_part = 'new_part3'
    test_rev = 'Q'
    test_hptype = 'antenna'
    start_time = Time('2019-07-01 00:31:00', scale='utc')
    stop_time = Time('2050-07-01 02:45:00', scale='utc')

    # Add a test part
    part1 = cm_partconnect.Parts()
    part1.hpn = test_part
    part1.hpn_rev = test_rev
    part1.hptype = test_hptype
    part1.manufacture_number = 'XYZ'
    part1.start_gpstime = start_time.gps
    part1.stop_gpstime = stop_time.gps
    parts.test_session.add(part1)
    parts.test_session.commit()

    active = cm_active.ActiveData(parts.test_session)

    active.load_parts()
    key_order = np.argsort(
        [active.parts[k].start_gpstime for k in active.parts.keys()])

    key_order = [list(active.parts.keys())[k] for k in key_order]
    active.parts = OrderedDict({key: active.parts[key] for key in key_order})

    vals = list(active.parts.values())
    assert part1 in vals

    revs = active.revs('NEW_PART')

    assert revs[0].hpn == 'NEW_PART'
    assert revs[0].number == 2
    assert revs[0].ended == stop_time.gps
Beispiel #4
0
def test_active_revisions(parts):
    active = cm_active.ActiveData(parts.test_session)
    active.load_parts()
    revs = active.revs('HH')
    assert revs[0].hpn == 'HH'
    hndl = cm_handling.Handling(parts.test_session)
    with pytest.raises(ValueError) as ml:
        hndl.get_dossier('HH701', at_date='2019/12/01', active=active)
    assert str(ml.value).startswith('Supplied')
    active.at_date = Time('2019-12-10')
    xxx = hndl.get_dossier('HH701', at_date=None, active=active)
    yyy = list(xxx.keys())[0]
    assert yyy == 'HH701:A'
Beispiel #5
0
def query_ex_ants(JD, good_statuses):
    '''Query the HERA CM database for antennas considered bad on a certain date.
    
    Arguments
        JD: string, int, or float Julian Date on which to queury the database
        good_statuses: string of comma-separated statuses considered acceptable. Antennas
            with any other status will be returned. Current possibilities include:
                * 'dish_maintenance',
                * 'dish_ok',
                * 'RF_maintenance',
                * 'RF_ok',
                * 'digital_maintenance',
                * 'digital_ok',
                * 'calibration_maintenance',
                * 'calibration_ok',
                * 'calibration_triage'
    
    Returns:
        ex_ants: string of space-separated antennas considered bad
    '''
    # Load database
    h = cm_active.ActiveData(at_date=JD)
    h.load_apriori()

    # Check that input statuses are sensible
    good_statuses = [status.strip() for status in good_statuses.split(',')]
    assert len(
        good_statuses) > 0, 'There must be at least one input good status.'
    valid_statuses = list(h.apriori.values())[0].valid_statuses() + list(
        h.apriori.values())[0].old_statuses()
    for status in good_statuses:
        assert status in valid_statuses, 'Invalid Status: {}'.format(status)

    # Pick out antnenna names with bad statuses
    exants = []
    for ant in h.apriori:
        if h.apriori[ant].status not in good_statuses:
            exants.append(int(
                ant[2:].split(':')[0]))  # Assumes the format HH0:A or HA330:A

    # Return sorted exants
    exants = ' '.join([str(ant) for ant in sorted(exants)])
    return exants
Beispiel #6
0
def test_duplicate(mcsession):
    active = cm_active.ActiveData(mcsession)
    active.pytest_param = 'up'
    pytest.raises(ValueError, active.load_connections)
    active.pytest_param = 'down'
    pytest.raises(ValueError, active.load_connections)
Beispiel #7
0
def test_apriori(mcsession):
    active = cm_active.ActiveData(mcsession)
    active.load_apriori()
    assert active.apriori['HH700:A'].status == 'not_connected'
Beispiel #8
0
            prefix = 'N'
        args.hpn = cm_utils.listify(args.hpn, prefix=prefix, padding=2)
    node_info = cm_sysutils.node_info(args.hpn, session)
    cm_sysutils.print_node(node_info)
elif view == 'revisions':
    from hera_mc import cm_active, cm_revisions
    args.hpn = cm_utils.listify(args.hpn)
    if args.verbosity == 1:
        columns = ['HPN', 'Revision', 'Start', 'Stop']
    elif args.verbosity == 2:
        columns = 'present'
    else:
        columns = 'all'
    if args.columns is not None and args.columns not in ['present', 'all']:
        columns = cm_utils.listify(args.columns)
    active = cm_active.ActiveData(session, date_query)
    active.load_parts()
    revs = active.revs(args.hpn)
    print(cm_revisions.show_revisions(revs, columns=columns))
else:  # view == 'parts' or view == 'connections' or view == 'info'
    args.hpn = cm_utils.listify(args.hpn)
    handling = cm_handling.Handling(session)
    if view == 'parts':
        if args.verbosity == 1:
            columns = ['hpn', 'hpn_rev', 'hptype', 'input_ports', 'output_ports']
        elif args.verbosity == 2:
            columns = ['hpn', 'hpn_rev', 'hptype', 'manufacturer_number',
                       'start_gpstime', 'stop_gpstime',
                       'input_ports', 'output_ports', 'geo']
        else:
            columns = ['hpn', 'hpn_rev', 'hptype', 'manufacturer_number',