Commit f6879c40 authored by mouadh's avatar mouadh

fix config file bug

parent 82c27c2d
...@@ -42,17 +42,18 @@ class MdxEngine: ...@@ -42,17 +42,18 @@ class MdxEngine:
def __init__(self, def __init__(self,
cube_name, cube_name,
client_type='excel',
cubes_path=None, cubes_path=None,
mdx_query=None, mdx_query=None,
cube_folder=CUBE_FOLDER, cube_folder=CUBE_FOLDER,
sep=';', sep=';',
fact_table_name="Facts"): fact_table_name="Facts"):
self.cube_folder = cube_folder self.cube_folder = cube_folder
self.cube = cube_name self.cube = cube_name
self.sep = sep self.sep = sep
self.facts = fact_table_name self.facts = fact_table_name
self.mdx_query = mdx_query self.mdx_query = mdx_query
if cubes_path is None: if cubes_path is None:
self.cube_path = self._get_default_cube_directory() self.cube_path = self._get_default_cube_directory()
else: else:
...@@ -60,10 +61,11 @@ class MdxEngine: ...@@ -60,10 +61,11 @@ class MdxEngine:
# to get cubes in db # to get cubes in db
self._ = self.get_cubes_names() self._ = self.get_cubes_names()
self.client = client_type
self.tables_loaded = self.load_tables() self.tables_loaded = self.load_tables()
# all measures # all measures
self.measures = self.get_measures()
self.load_star_schema_dataframe = self.get_star_schema_dataframe() self.load_star_schema_dataframe = self.get_star_schema_dataframe()
self.measures = self.get_measures()
self.tables_names = self._get_tables_name() self.tables_names = self._get_tables_name()
# default measure is the first one # default measure is the first one
self.selected_measures = [self.measures[0]] self.selected_measures = [self.measures[0]]
...@@ -134,7 +136,7 @@ class MdxEngine: ...@@ -134,7 +136,7 @@ class MdxEngine:
config_file_parser = ConfigParser(self.cube_path) config_file_parser = ConfigParser(self.cube_path)
tables = {} tables = {}
if config_file_parser.config_file_exist( if config_file_parser.config_file_exist(
) and self.cube in config_file_parser.get_cubes_names(): ) and self.cube in config_file_parser.get_cubes_names() and self.client != 'web':
for cubes in config_file_parser.construct_cubes(): for cubes in config_file_parser.construct_cubes():
# TODO working with cubes.source == 'csv' # TODO working with cubes.source == 'csv'
...@@ -158,7 +160,7 @@ class MdxEngine: ...@@ -158,7 +160,7 @@ class MdxEngine:
include=[np.number]).columns if col.lower()[-2:] != 'id' include=[np.number]).columns if col.lower()[-2:] != 'id'
] ]
def get_star_schema_dataframe(self, client_type='excel'): def get_star_schema_dataframe(self):
""" """
Merge all DataFrames as star schema. Merge all DataFrames as star schema.
...@@ -169,13 +171,13 @@ class MdxEngine: ...@@ -169,13 +171,13 @@ class MdxEngine:
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 self.client
) and self.cube in config_file_parser.get_cubes_names(): ) and self.cube in config_file_parser.get_cubes_names(client_type='web'):
for cubes in config_file_parser.construct_cubes(client_type): for cubes in config_file_parser.construct_cubes(self.client):
# TODO cubes.source == 'csv' # TODO cubes.source == 'csv'
if cubes.source == 'postgres': if cubes.source == 'postgres':
# TODO one config file (I will try to merge dimensions between them in web part) # TODO one config file (I will try to merge dimensions between them in web part)
if client_type == 'web': if self.client == 'web':
fusion = _construct_web_star_schema_config_file( fusion = _construct_web_star_schema_config_file(
self, cubes) self, cubes)
else: else:
......
...@@ -219,6 +219,7 @@ class ConfigParser: ...@@ -219,6 +219,7 @@ class ConfigParser:
:return: True | False :return: True | False
""" """
if self.config_file_exist():
with open(os.path.join(self.cube_path, self.file_name)) as config_file: with open(os.path.join(self.cube_path, self.file_name)) as config_file:
parser = etree.XMLParser() parser = etree.XMLParser()
...@@ -229,14 +230,21 @@ class ConfigParser: ...@@ -229,14 +230,21 @@ class ConfigParser:
0].text == 'True' 0].text == 'True'
except: except:
return False return False
else:
return False
def get_cubes_names(self): def get_cubes_names(self, client_type='excel'):
""" """
Get all cubes names in the config file. Get all cubes names in the config file.
:return: dict of cube name as key and cube source as value (csv or postgres) (right now only postgres is supported) :return: dict of cube name as key and cube source as value (csv or postgres) (right now only postgres is supported)
""" """
with open(os.path.join(self.cube_path, self.file_name)) as config_file: if client_type == 'excel':
file_name = self.file_name
elif client_type == 'web':
file_name = self.web_config_file_name
with open(os.path.join(self.cube_path, file_name)) as config_file:
parser = etree.XMLParser() parser = etree.XMLParser()
tree = etree.parse(config_file, parser) tree = etree.parse(config_file, parser)
...@@ -315,7 +323,6 @@ class ConfigParser: ...@@ -315,7 +323,6 @@ class ConfigParser:
# try: # try:
with open(os.path.join(self.cube_path, with open(os.path.join(self.cube_path,
self.web_config_file_name)) as config_file: self.web_config_file_name)) as config_file:
parser = etree.XMLParser() parser = etree.XMLParser()
tree = etree.parse(config_file, parser) tree = etree.parse(config_file, parser)
...@@ -358,7 +365,6 @@ class ConfigParser: ...@@ -358,7 +365,6 @@ class ConfigParser:
# try: # try:
with open(os.path.join(self.cube_path, with open(os.path.join(self.cube_path,
self.web_config_file_name)) as config_file: self.web_config_file_name)) as config_file:
parser = etree.XMLParser() parser = etree.XMLParser()
tree = etree.parse(config_file, parser) tree = etree.parse(config_file, parser)
...@@ -370,7 +376,7 @@ class ConfigParser: ...@@ -370,7 +376,7 @@ class ConfigParser:
'rows': dashboard.find('Global_table/rows').text.split(',') 'rows': dashboard.find('Global_table/rows').text.split(',')
}, },
pie_charts=dashboard.find('PieCharts').text.split(','), pie_charts=dashboard.find('PieCharts').text.split(','),
bar_chats=dashboard.find('BarCharts').text.split(','), bar_charts=dashboard.find('BarCharts').text.split(','),
line_charts={ line_charts={
table.find('name').text: table.find('name').text:
(table.find('columns').text.split(',') (table.find('columns').text.split(',')
......
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