A Graph library to manage inheritance rules
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
deg-1.0.1.tar.gz
(12.8 kB
view details)
File details
Details for the file deg-1.0.1.tar.gz
.
File metadata
- Download URL: deg-1.0.1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3a5f895e1e039399002161b5901703342bf22437b22164a5961fc40b3e6885a |
|
MD5 | 64aaea200b8872cf79e23dca982b3bcf |
|
BLAKE2b-256 | efb9587d43e12c211fe9762312e320aec2f04fcb921ee8b4234188b465c53c34 |