Commit 151cddf3 authored by mouadh's avatar mouadh

format

parent a35255b4
......@@ -311,15 +311,15 @@ class MdxEngine:
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)
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:]]]
return fusion[[
column for column in all_columns if 'id' != column[-2:]
]]
def _construct_star_schema_csv_files(self, cube_name):
"""
......@@ -379,7 +379,8 @@ class MdxEngine:
fusion = None
config_file_parser = ConfigParser(self.cube_path)
if config_file_parser.config_file_exist(client_type
if config_file_parser.config_file_exist(
client_type
) and cube_name in config_file_parser.get_cubes_names():
for cubes in config_file_parser.construct_cubes(client_type):
# TODO cubes.source == 'csv'
......
......@@ -215,7 +215,10 @@ class ConfigParser:
"""
# TODO one config file (I will try to merge dimensions between them in web part)
def __init__(self, cube_path, file_name='cubes-config.xml', web_config_file_name='web_cube_config.xml'):
def __init__(self,
cube_path,
file_name='cubes-config.xml',
web_config_file_name='web_cube_config.xml'):
"""
:param cube_path: path to cube (csv folders)
......@@ -225,14 +228,15 @@ class ConfigParser:
self.file_name = file_name
self.web_config_file_name = web_config_file_name
def config_file_exist(self,client_type='excel'):
def config_file_exist(self, client_type='excel'):
"""
Check whether the config file exists or not.
:return: True | False
"""
if client_type == 'web':
return os.path.isfile(os.path.join(self.cube_path, self.web_config_file_name))
return os.path.isfile(
os.path.join(self.cube_path, self.web_config_file_name))
return os.path.isfile(os.path.join(self.cube_path, self.file_name))
def xmla_authentication(self):
......@@ -284,8 +288,7 @@ class ConfigParser:
table_name=xml_facts.find('table_name').text,
keys={
key.text: key.attrib['ref']
for key in xml_facts.findall(
'keys/column_name')
for key in xml_facts.findall('keys/column_name')
},
measures=[
mes.text
......@@ -331,27 +334,21 @@ class ConfigParser:
table_name=xml_facts.find('table_name').text,
keys={
key.text: key.attrib['ref']
for key in xml_facts.findall(
'keys/column_name')
for key in xml_facts.findall('keys/column_name')
},
measures=[
mes.text
for mes in xml_facts.findall('measures/name')
mes.text for mes in xml_facts.findall('measures/name')
]) for xml_facts in tree.xpath('/cubes/cube/facts')
]
tables = [
Table(
name=xml_column.attrib['name'],
columns = xml_column.find('columns').text.split(','),
columns=xml_column.find('columns').text.split(','),
new_names={
new_col.attrib['old_column_name'] : new_col.text
new_col.attrib['old_column_name']: new_col.text
for new_col in xml_column.findall('new_name')
}
)
for xml_column in tree.xpath(
'/cubes/cube/tables/table')
}) for xml_column in tree.xpath('/cubes/cube/tables/table')
]
return [
......@@ -359,15 +356,12 @@ class ConfigParser:
name=xml_cube.find('name').text,
source=xml_cube.find('source').text,
facts=facts,
tables = tables
)
for xml_cube in tree.xpath('/cubes/cube')
tables=tables) for xml_cube in tree.xpath('/cubes/cube')
]
# except:
# raise ('Bad configuration in the configuration file')
def construct_cubes(self,client_type='excel'):
def construct_cubes(self, client_type='excel'):
"""
Construct cube (with it dimensions) and facts from the config file.
:param client_type: excel | web
......
......@@ -5,16 +5,18 @@ USERNAME = 'postgres'
PASSWORD = 'root'
HOST = 'localhost'
class MyDB(object):
"""Connect to sql database (postgres only right now)."""
def __init__(self,
username=USERNAME,
password=PASSWORD,
db=None,
host=HOST):
if db is None:
self.connection = pg.connect(
"user={0} password={1} host='{2}'".format(username, password,host))
self.connection = pg.connect("user={0} password={1} host='{2}'".
format(username, password, host))
else:
try:
self.connection = pg.connect(
......
......@@ -37,6 +37,7 @@ class Dimension:
def __str__(self):
return str(self.__dict__)
class Cube:
"""Cube class used to encapsulate config file attributes."""
......@@ -52,6 +53,7 @@ class Cube:
def __str__(self):
return str(self.__dict__)
class Table:
"""Column class used to encapsulate config file attributes for web client."""
......
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