Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
olapy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
olapy
Commits
cf4dde4d
Commit
cf4dde4d
authored
May 12, 2017
by
mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
web config file
parent
682e4901
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
302 additions
and
56 deletions
+302
-56
cubes_templates/cubes_temp.zip
cubes_templates/cubes_temp.zip
+0
-0
olapy/core/mdx/executor/execute.py
olapy/core/mdx/executor/execute.py
+73
-5
olapy/core/mdx/tools/config_file_parser.py
olapy/core/mdx/tools/config_file_parser.py
+213
-51
olapy/core/mdx/tools/models.py
olapy/core/mdx/tools/models.py
+16
-0
No files found.
cubes_templates/cubes_temp.zip
View file @
cf4dde4d
No preview for this file type
olapy/core/mdx/executor/execute.py
View file @
cf4dde4d
...
...
@@ -96,6 +96,7 @@ class MdxEngine:
MdxEngine
.
postgres_db_cubes
=
[
database
[
0
]
for
database
in
cursor
.
fetchall
()
]
except
Exception
:
print
(
'no database connexion'
)
pass
...
...
@@ -258,6 +259,68 @@ class MdxEngine:
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
):
"""
Construct star schema DataFrame from csv files.
...
...
@@ -306,7 +369,7 @@ class MdxEngine:
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.
...
...
@@ -316,13 +379,18 @@ class MdxEngine:
fusion
=
None
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
():
for
cubes
in
config_file_parser
.
construct_cubes
():
for
cubes
in
config_file_parser
.
construct_cubes
(
client_type
):
# TODO cubes.source == 'csv'
if
cubes
.
source
==
'postgres'
:
fusion
=
self
.
_construct_star_schema_config_file
(
cube_name
,
cubes
)
# TODO one config file (I will try to merge dimensions between them in web part)
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
:
fusion
=
self
.
_construct_star_schema_csv_files
(
cube_name
)
...
...
olapy/core/mdx/tools/config_file_parser.py
View file @
cf4dde4d
This diff is collapsed.
Click to expand it.
olapy/core/mdx/tools/models.py
View file @
cf4dde4d
...
...
@@ -51,3 +51,19 @@ class Cube:
def
__str__
(
self
):
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__
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment