Skip to main content

Depency Graph

A Graph creation, analysis and visualizations library.

Installation

pip install deg

Usage

Can be used directly using the DependencyNode object or by extending the object into some other subjective structure.

A sample usage would look as the following :

from deg import DependencyGraph, DependencyNode

class Table(DependencyNode):
    '''Class for representing each node of the tree.
    This contains every piece of static information that may be required for analysis.
    
    '''
    def __init__(self, name, cols=None):
        super(Table, self).__init__(name)
        self.cols=cols
        self.visited = False
        self.col_relations = None
    
    def add_cols(self, df : pd.DataFrame):
        self.cols = df
    def add_relations(self, df : pd.DataFrame):
        self.col_relations = df
    def generate_search_criteria(self, module=None):
        selection = ''
        if self.is_independent():
            print('Ignoring rules for independent table :\n', self.col_relations.to_string())
            selection = '''TRUNC({tablename}.{datecol}) BETWEEN (SELECT PRG_PERIOD_START FROM PURGE_MODULE_INPUT WHERE REQUEST_ID = PRG_BTCH_ID AND MODULE = '{module}' AND STATUS = 'INITIATED') AND (SELECT PRG_PERIOD_END FROM PURGE_MODULE_INPUT WHERE REQUEST_ID = PRG_BTCH_ID AND MODULE = '{module}' AND STATUS = 'INITIATED')'''.format(tablename=self.name,datecol=self.get_date_col(), module=module)
        else :
            for parent in self.parents:
                criterias = ''
                for _, row in self.col_relations[self.col_relations['r_table'] == parent.name].iterrows():
                    if len(criterias) > 0:
                        criterias += ' AND '
                    criterias += '{0}.{1} = {2}.{3} '.format(row['table_name'], row['column_name'], row['r_table'], row['r_col'])
                criterias += ' AND ' + parent.generate_search_criteria(module=module)
                selection += 'INNER JOIN {parent_name} ON {criterias}'.format(parent_name = parent.name, criterias = criterias)
        return selection
    def get_cols(self) -> pd.DataFrame:
        return self.cols
    def is_visited(self) -> bool :
        return self.visited
    def set_visited(self) :
        self.visited = True
    def get_date_col(self):
        try:
            return self.cols[(self.cols['data_type'] == 'DATE') & (self.cols['nullable'] == 'N')].iloc[-1]['column_name']
        except Exception as e:
            # print(e)
            return None
    def __str__(self):
        return 'Table({0}, {1})'.format(self.name, self.is_independent(), self.children)
    def __repr__(self):
        return 'Table({0}, {1})'.format(self.name, self.is_independent(), self.children)

graph = DependencyGraph(Table)
while True:
    df = get_children(temp)
    if df is None or df.shape == (0, 0) :
        break
    for val in df.itertuples():
        graph.add(val[2], parent=val[1], relation = val[3])
    temp = df.iloc[:, 1]
    execution_limit -= 1
    if execution_limit <= 0 :
        break

Docstrings have been added to detail what functions such as graph.add does.

Metadata

Release files for deg 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deg 1.0.1
File Size Uploaded
deg-1.0.1.tar.gz 12.8 kB Details

Release files / deg-1.0.1.tar.gz

Download URL deg-1.0.1.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b3a5f895e1e039399002161b5901703342bf22437b22164a5961fc40b3e6885a
BLAKE2b-256 checksum
How to use checksums
efb9587d43e12c211fe9762312e320aec2f04fcb921ee8b4234188b465c53c34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.5

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file

1.0.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page