Commit cf4dde4d authored by mouadh's avatar mouadh

web config file

parent 682e4901
...@@ -96,6 +96,7 @@ class MdxEngine: ...@@ -96,6 +96,7 @@ class MdxEngine:
MdxEngine.postgres_db_cubes = [ MdxEngine.postgres_db_cubes = [
database[0] for database in cursor.fetchall() database[0] for database in cursor.fetchall()
] ]
except Exception: except Exception:
print('no database connexion') print('no database connexion')
pass pass
...@@ -258,6 +259,68 @@ class MdxEngine: ...@@ -258,6 +259,68 @@ class MdxEngine:
return fusion return fusion
def _construct_web_star_schema_config_file(self, cube_name, cubes_obj):
"""
Construct star schema DataFrame from configuration file.
:param cube_name: cube name (or database name)
:param cubes_obj: cubes object
:return: star schema DataFrame
"""
all_columns = []
self.facts = cubes_obj.facts[0].table_name
db = MyDB(db=cube_name)
# load facts table
# measures in config-file only
if cubes_obj.facts[0].measures:
self.measures = cubes_obj.facts[0].measures
all_columns += cubes_obj.facts[0].measures
fusion = psql.read_sql_query("SELECT * FROM {0}".format(self.facts),
db.connection)
tables = {}
for table in cubes_obj.tables:
tab = psql.read_sql_query("SELECT * FROM {0}".format(table.name),
db.connection)
try:
if table.columns:
tab = tab[table.columns]
except:
print("table columns doesn't exist")
print('pass with all columns')
try:
if table.new_names:
tab = tab.rename(columns=table.new_names)
except:
print("verify your old and new columns names")
print('pass with no change')
all_columns += list(tab.columns)
tables.update({table.name: tab})
for fact_key, dimension_and_key in cubes_obj.facts[0].keys.items():
dimension_name = dimension_and_key.split('.')[0]
if dimension_name in tables.keys():
df = tables[dimension_name]
else:
df = psql.read_sql_query(
"SELECT * FROM {0}".format(dimension_and_key.split('.')[0]),
db.connection)
fusion = fusion.merge(
df, left_on=fact_key, right_on=dimension_and_key.split('.')[1])
return fusion[[column for column in all_columns if 'id' != column[-2:]]]
def _construct_star_schema_csv_files(self, cube_name): def _construct_star_schema_csv_files(self, cube_name):
""" """
Construct star schema DataFrame from csv files. Construct star schema DataFrame from csv files.
...@@ -306,7 +369,7 @@ class MdxEngine: ...@@ -306,7 +369,7 @@ class MdxEngine:
return fusion return fusion
def get_star_schema_dataframe(self, cube_name): def get_star_schema_dataframe(self, cube_name, client_type='excel'):
""" """
Merge all DataFrames as star schema. Merge all DataFrames as star schema.
...@@ -316,13 +379,18 @@ class MdxEngine: ...@@ -316,13 +379,18 @@ class MdxEngine:
fusion = None fusion = None
config_file_parser = ConfigParser(self.cube_path) config_file_parser = ConfigParser(self.cube_path)
if config_file_parser.config_file_exist( if config_file_parser.config_file_exist(client_type
) and cube_name in config_file_parser.get_cubes_names(): ) and cube_name in config_file_parser.get_cubes_names():
for cubes in config_file_parser.construct_cubes(): for cubes in config_file_parser.construct_cubes(client_type):
# TODO cubes.source == 'csv' # TODO cubes.source == 'csv'
if cubes.source == 'postgres': if cubes.source == 'postgres':
fusion = self._construct_star_schema_config_file( # TODO one config file (I will try to merge dimensions between them in web part)
cube_name, cubes) if client_type == 'web':
fusion = self._construct_web_star_schema_config_file(
cube_name, cubes)
else:
fusion = self._construct_star_schema_config_file(
cube_name, cubes)
elif cube_name in self.csv_files_cubes: elif cube_name in self.csv_files_cubes:
fusion = self._construct_star_schema_csv_files(cube_name) fusion = self._construct_star_schema_csv_files(cube_name)
......
This diff is collapsed.
...@@ -51,3 +51,19 @@ class Cube: ...@@ -51,3 +51,19 @@ class Cube:
def __str__(self): def __str__(self):
return str(self.__dict__) return str(self.__dict__)
class Table:
"""Column class used to encapsulate config file attributes for web client."""
def __init__(self, **kwargs):
"""
:param kwargs: {
table_name : 'something',
old_column_name : 'something',
new_column_name : 'something'
}
"""
self.__dict__.update(kwargs)
def __str__(self):
return str(self.__dict__)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment