Esempio n. 1
0
def check_distribution_hierarchy(cur, df, facility_fullname):

    messages = []

    panel_type_id = dbCommon.object_type_to_id(cur, 'Panel')
    transformer_type_id = dbCommon.object_type_to_id(cur, 'Transformer')
    circuit_type_id = dbCommon.object_type_to_id(cur, 'Circuit')

    # Verify that all Panels have valid parent types
    df_pan_no_root = df[(df['object_type_id'] == panel_type_id)
                        & (df['parent_id'] != '')]
    df_join = df_pan_no_root.join(df,
                                  on='parent_id',
                                  how='inner',
                                  lsuffix='_of_panel',
                                  rsuffix='_of_parent')
    df_wrong_parent_type = df_join[
        (df_join['object_type_id_of_parent'] != transformer_type_id)
        & (df_join['object_type_id_of_parent'] != circuit_type_id)]
    for index, row in df_wrong_parent_type.iterrows():
        messages.append(
            make_error_message(
                facility_fullname, 'Panel', row['path_of_panel'],
                'Has parent of wrong type (' + dbCommon.get_object_type(
                    cur, row['object_type_id_of_parent']) + ').'))

    # Verify that all Transformers have valid parent types
    df_tran = df[df['object_type_id'] == transformer_type_id]
    df_join = df_tran.join(df,
                           on='parent_id',
                           how='inner',
                           lsuffix='_of_transformer',
                           rsuffix='_of_parent')
    df_wrong_parent_type = df_join[
        df_join['object_type_id_of_parent'] != circuit_type_id]
    for index, row in df_wrong_parent_type.iterrows():
        messages.append(
            make_error_message(
                facility_fullname, 'Transformer', row['path_of_transformer'],
                'Has parent of wrong type (' + dbCommon.get_object_type(
                    cur, row['object_type_id_of_parent']) + ').'))

    # Verify that all Circuits have valid parent types
    df_circ = df[df['object_type_id'] == circuit_type_id]
    df_join = df_circ.join(df,
                           on='parent_id',
                           how='inner',
                           lsuffix='_of_circuit',
                           rsuffix='_of_parent')
    df_wrong_parent_type = df_join[
        df_join['object_type_id_of_parent'] != panel_type_id]
    for index, row in df_wrong_parent_type.iterrows():
        messages.append(
            make_error_message(
                facility_fullname, 'Circuit', row['path_of_circuit'],
                'Has parent of wrong type (' + dbCommon.get_object_type(
                    cur, row['object_type_id_of_parent']) + ').'))

    return messages
Esempio n. 2
0
def check_distribution_paths(cur, dc_tree, root_id, facility_fullname):

    messages = []

    panel_type_id = dbCommon.object_type_to_id(cur, 'Panel')
    transformer_type_id = dbCommon.object_type_to_id(cur, 'Transformer')

    messages += traverse_distribution_paths(cur, dc_tree, root_id,
                                            panel_type_id, transformer_type_id,
                                            facility_fullname)

    return messages
Esempio n. 3
0
def check_device_hierarchy(cur, df, df_dev, facility_fullname):

    messages = []

    circuit_type_id = dbCommon.object_type_to_id(cur, 'Circuit')

    # Join dataframes to associate devices with their parents
    df_join = df_dev.join(df,
                          on='parent_id',
                          how='inner',
                          lsuffix='_of_device',
                          rsuffix='_of_parent')

    # Extract devices whose parents are of wrong type
    df_wrong_parent_type = df_join[
        df_join['object_type_id'] != circuit_type_id]

    # Report anomalies
    for index, row in df_wrong_parent_type.iterrows():
        messages.append(
            make_error_message(
                facility_fullname, 'Device',
                "'" + row['name'] + "'" + ' on ' + row['path'],
                'Has parent of wrong type (' +
                dbCommon.get_object_type(cur, row['object_type_id']) + ').'))

    return messages
Esempio n. 4
0
def check_distribution_siblings(cur, df, facility_fullname):

    messages = []

    panel_type_id = dbCommon.object_type_to_id(cur, 'Panel')
    transformer_type_id = dbCommon.object_type_to_id(cur, 'Transformer')
    circuit_type_id = dbCommon.object_type_to_id(cur, 'Circuit')

    df_n_sibs = df['parent_id'].value_counts().to_frame('n_sibs')

    # Verify that Panels attached to Circuits have no siblings
    df_pan = df[df['object_type_id'] == panel_type_id]
    df_join = df_pan.join(df,
                          on='parent_id',
                          how='left',
                          lsuffix='_of_panel',
                          rsuffix='_of_parent')
    df_join = df_join.join(df_n_sibs, on='parent_id_of_panel')
    df_has_sibs = df_join[
        (df_join['object_type_id_of_parent'] == circuit_type_id)
        & (df_join['n_sibs'] > 1)]
    for index, row in df_has_sibs.iterrows():
        messages.append(
            make_error_message(facility_fullname, 'Panel',
                               row['path_of_panel'],
                               'Has unexpected siblings.'))

    # Verify that Transformers have no siblings
    df_tran = df[df['object_type_id'] == transformer_type_id]
    df_join = df_tran.join(df,
                           on='parent_id',
                           how='left',
                           lsuffix='_of_transformer',
                           rsuffix='_of_parent')
    df_join = df_join.join(df_n_sibs, on='parent_id_of_transformer')
    df_has_sibs = df_join[df_join['n_sibs'] > 1]
    for index, row in df_has_sibs.iterrows():
        messages.append(
            make_error_message(facility_fullname, 'Transformer',
                               row['path_of_transformer'],
                               'Has unexpected siblings.'))

    return messages
Esempio n. 5
0
def check_circuit_numbers(cur, dc_tree, root_id, facility_name,
                          facility_fullname):

    messages = []

    panel_type_id = dbCommon.object_type_to_id(cur, 'Panel')

    # Traverse the tree
    messages += traverse_circuit_numbers(cur, dc_tree, root_id, panel_type_id,
                                         facility_fullname)

    return messages
Esempio n. 6
0
def check_voltages(cur, dc_tree, root_id, facility_name, facility_fullname):

    messages = []

    transformer_type_id = dbCommon.object_type_to_id(cur, 'Transformer')
    hi_voltage_id = dbCommon.voltage_to_id(cur, '277/480')
    lo_voltage_id = dbCommon.voltage_to_id(cur, '120/208')

    # Traverse the tree
    messages += traverse_voltages(cur, dc_tree, root_id, hi_voltage_id,
                                  transformer_type_id, hi_voltage_id,
                                  lo_voltage_id, facility_fullname)

    return messages
Esempio n. 7
0
def check_distribution_root(cur, df, facility_fullname):

    messages = []

    df_root = df[df['parent_id'] == '']

    # Verify that there is exactly one root
    n_roots = len(df_root)
    if n_roots == 1:

        # Verify that root is a Panel
        root_object_type_id = df_root.iloc[0]['object_type_id']
        if root_object_type_id != dbCommon.object_type_to_id(cur, 'Panel'):
            messages.append(
                make_error_message(facility_fullname, 'Distribution', 'Tree',
                                   'Root is not a Panel.'))

    else:
        messages.append(
            make_error_message(facility_fullname, 'Distribution', 'Tree',
                               'Has ' + str(n_roots) + ' roots.'))

    return messages
Esempio n. 8
0
def check_three_phase(cur, df, facility_fullname):

    messages = []

    # Verify that no element has a Phase C parent without a Phase B parent
    df_c_only = df[(df['phase_b_parent_id'] == '')
                   & (df['phase_c_parent_id'] != '')]
    for index, row in df_c_only.iterrows():
        messages.append(
            make_error_message(
                facility_fullname,
                dbCommon.get_object_type(cur, row['object_type_id']),
                row['path'], 'Has a Phase C Parent but no Phase B Parent.'))

    # Verify that no element has a Phase B parent without a Phase C parent
    df_b_only = df[(df['phase_b_parent_id'] != '')
                   & (df['phase_c_parent_id'] == '')]
    for index, row in df_b_only.iterrows():
        messages.append(
            make_warning_message(
                facility_fullname,
                dbCommon.get_object_type(cur, row['object_type_id']),
                row['path'], 'Has a Phase B Parent but no Phase C Parent.'))

    # Verify that phase parents are siblings and circuits
    circuit_object_type_id = dbCommon.object_type_to_id(cur, 'Circuit')
    df_phase = df[df['phase_b_parent_id'] != '']

    for index, row in df_phase.iterrows():
        parent_id = row['parent_id']
        phase_b_parent_id = row['phase_b_parent_id']
        phase_c_parent_id = row['phase_c_parent_id']

        parents_found = True

        if parent_id not in df.index.values:
            parents_found = False

        if phase_b_parent_id not in df.index.values:
            messages.append(
                make_critical_message(
                    facility_fullname,
                    dbCommon.get_object_type(cur, row['object_type_id']),
                    row['path'],
                    'Phase B Parent not found in Distribution tree.'))
            parents_found = False

        if phase_c_parent_id and (phase_c_parent_id not in df.index.values):
            messages.append(
                make_critical_message(
                    facility_fullname,
                    dbCommon.get_object_type(cur, row['object_type_id']),
                    row['path'],
                    'Phase C Parent not found in Distribution tree.'))
            parents_found = False

        if parents_found:

            # Verify that Phase B Parent is sibling of Parent
            granny_a_id = df.loc[parent_id]['parent_id']
            granny_b_id = df.loc[phase_b_parent_id]['parent_id']
            if granny_a_id != granny_b_id:
                messages.append(
                    make_error_message(
                        facility_fullname,
                        dbCommon.get_object_type(cur, row['object_type_id']),
                        row['path'],
                        'Parent and Phase B Parent are not siblings.'))

            # Verify that Phase B Parent is a Circuit object
            b_parent_object_type_id = df.loc[phase_b_parent_id][
                'object_type_id']
            if b_parent_object_type_id != circuit_object_type_id:
                messages.append(
                    make_error_message(
                        facility_fullname,
                        dbCommon.get_object_type(cur, row['object_type_id']),
                        row['path'], 'Phase B Parent is not a Circuit.'))

            if phase_c_parent_id:

                # Verify that Phase C Parent is sibling of Parent
                granny_c_id = df.loc[phase_c_parent_id]['parent_id']
                if granny_a_id != granny_c_id:
                    messages.append(
                        make_error_message(
                            facility_fullname,
                            dbCommon.get_object_type(cur,
                                                     row['object_type_id']),
                            row['path'],
                            'Parent and Phase C Parent are not siblings.'))

                # Verify that Phase C Parent is a Circuit object
                c_parent_object_type_id = df.loc[phase_c_parent_id][
                    'object_type_id']
                if c_parent_object_type_id != circuit_object_type_id:
                    messages.append(
                        make_error_message(
                            facility_fullname,
                            dbCommon.get_object_type(cur,
                                                     row['object_type_id']),
                            row['path'], 'Phase C Parent is not a Circuit.'))

    return messages