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
480dbd4d
Commit
480dbd4d
authored
Apr 19, 2017
by
Mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix (bugs + path prob)
parent
1ac25c8b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
34 deletions
+44
-34
olapy/core/mdx/executor/execute.py
olapy/core/mdx/executor/execute.py
+30
-31
olapy/core/mdx/tools/__init__.py
olapy/core/mdx/tools/__init__.py
+0
-0
olapy/core/mdx/tools/config_file_parser.py
olapy/core/mdx/tools/config_file_parser.py
+0
-0
olapy/core/mdx/tools/connection.py
olapy/core/mdx/tools/connection.py
+6
-2
olapy/core/mdx/tools/models.py
olapy/core/mdx/tools/models.py
+0
-0
olapy/core/services/xmla.py
olapy/core/services/xmla.py
+8
-1
No files found.
olapy/core/mdx/executor/execute.py
View file @
480dbd4d
...
...
@@ -5,14 +5,15 @@ from __future__ import absolute_import, division, print_function
import
itertools
import
os
import
re
from
os.path
import
expanduser
from
collections
import
OrderedDict
import
numpy
as
np
import
pandas
as
pd
import
pandas.io.sql
as
psql
from
..
utils.connection
import
MyDB
from
..
utils.config_file_parser
import
ConfigParser
from
..
tools.config_file_parser
import
ConfigParser
from
..
tools.connection
import
MyDB
class
MdxEngine
:
...
...
@@ -31,6 +32,7 @@ class MdxEngine:
def
__init__
(
self
,
cube_name
,
cubes_path
=
None
,
mdx_query
=
None
,
cube_folder
=
CUBE_FOLDER
,
sep
=
';'
,
...
...
@@ -41,12 +43,18 @@ class MdxEngine:
:param mdx_query: query to execute
:param sep: separator in the csv files
'''
self
.
cube
=
cube_name
self
.
cube_folder
=
cube_folder
self
.
cube
=
cube_name
self
.
sep
=
sep
self
.
facts
=
fact_table_name
self
.
mdx_query
=
mdx_query
self
.
cube_path
=
self
.
_get_cube_path
()
if
cubes_path
is
None
:
self
.
cube_path
=
self
.
_get_default_cube_directory
()
else
:
self
.
cube_path
=
cubes_path
# to get cubes in db
self
.
_
=
self
.
get_cubes_names
()
self
.
tables_loaded
=
self
.
_load_tables
()
...
...
@@ -59,18 +67,16 @@ class MdxEngine:
self
.
selected_measures
=
[
self
.
measures
[
0
]]
@
classmethod
def
get_cubes_names
(
self
):
def
get_cubes_names
(
cls
):
'''
:return: list cubes name under cubes folder
'''
# get csv files folders (cubes)
home_directory
=
expanduser
(
"~"
)
location
=
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
cls
.
CUBE_FOLDER
)
try
:
location
=
os
.
path
.
join
(
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
".."
,
".."
,
".."
,
".."
)),
MdxEngine
.
CUBE_FOLDER
)
MdxEngine
.
csv_files_cubes
=
[
file
for
file
in
os
.
listdir
(
location
)
if
os
.
path
.
isdir
(
os
.
path
.
join
(
location
,
file
))
...
...
@@ -94,6 +100,10 @@ class MdxEngine:
return
MdxEngine
.
csv_files_cubes
+
MdxEngine
.
postgres_db_cubes
def
_get_default_cube_directory
(
self
):
home_directory
=
expanduser
(
"~"
)
return
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
self
.
cube_folder
)
def
_get_tables_name
(
self
):
return
self
.
tables_loaded
.
keys
()
...
...
@@ -222,10 +232,7 @@ class MdxEngine:
db
.
connection
)
fusion
=
fusion
.
merge
(
df
,
left_on
=
fact_key
,
right_on
=
dimension_and_key
.
split
(
'.'
)[
1
],
how
=
'outer'
)
df
,
left_on
=
fact_key
,
right_on
=
dimension_and_key
.
split
(
'.'
)[
1
])
# TODO CHOSE BETWEEN THOSES DF
# if separated dimensions
...
...
@@ -302,8 +309,8 @@ class MdxEngine:
for
cubes
in
config_file_parser
.
construct_cubes
():
# TODO cubes.source == 'csv'
if
cubes
.
source
==
'postgres'
:
fusion
=
self
.
_construct_star_schema_config_file
(
cube_name
,
cubes
)
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
)
...
...
@@ -311,8 +318,9 @@ class MdxEngine:
elif
cube_name
in
self
.
postgres_db_cubes
:
fusion
=
self
.
_construct_star_schema_db
(
cube_name
)
return
fusion
[
[
col
for
col
in
fusion
.
columns
if
col
.
lower
()[
-
3
:]
!=
'_id'
]]
return
fusion
[[
col
for
col
in
fusion
.
columns
if
col
.
lower
()[
-
3
:]
!=
'_id'
]]
def
get_all_tables_names
(
self
,
ignore_fact
=
False
):
"""
...
...
@@ -325,16 +333,6 @@ class MdxEngine:
return
[
tab
for
tab
in
self
.
tables_names
if
self
.
facts
not
in
tab
]
return
self
.
tables_names
def
_get_cube_path
(
self
):
'''
:return: return local cube folder name with full path
'''
return
os
.
path
.
join
(
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'..'
,
".."
,
'..'
,
'..'
)),
self
.
cube_folder
)
def
get_cube
(
self
):
"""
get path to the cube (example /home/your_user_name/olapy-core/cubes)
...
...
@@ -634,8 +632,9 @@ class MdxEngine:
:return: updated columns_to_keep
"""
if len(tuple_as_list) == 3 and tuple_as_list[-1] in self.tables_loaded[
tuple_as_list[0]].columns:
if len(
tuple_as_list
) == 3 and tuple_as_list[-1] in self.tables_loaded[tuple_as_list[0]].columns:
# in case of [Geography].[Geography].[Country]
cols = [tuple_as_list[-1]]
else:
...
...
@@ -737,7 +736,7 @@ class MdxEngine:
# TODO margins=True for columns total !!!!!
return {
'result':
df.
drop_duplicates().replace(np.nan, -1).groupby(cols).sum()
,
df.
groupby(cols).sum()[self.selected_measures]
,
'columns_desc':
tables_n_columns
}
...
...
olapy/core/mdx/
uti
ls/__init__.py
→
olapy/core/mdx/
too
ls/__init__.py
View file @
480dbd4d
File moved
olapy/core/mdx/
uti
ls/config_file_parser.py
→
olapy/core/mdx/
too
ls/config_file_parser.py
View file @
480dbd4d
File moved
olapy/core/mdx/
uti
ls/connection.py
→
olapy/core/mdx/
too
ls/connection.py
View file @
480dbd4d
...
...
@@ -7,8 +7,12 @@ class MyDB(object):
self
.
connection
=
pg
.
connect
(
"user={0} password={1}"
.
format
(
username
,
password
))
else
:
try
:
self
.
connection
=
pg
.
connect
(
"user={0} password={1} dbname='{2}'"
.
format
(
username
,
password
,
db
))
except
:
print
(
"can't connect"
)
def
__del__
(
self
):
if
hasattr
(
self
,
'connection'
):
self
.
connection
.
close
()
\ No newline at end of file
olapy/core/mdx/
uti
ls/models.py
→
olapy/core/mdx/
too
ls/models.py
View file @
480dbd4d
File moved
olapy/core/services/xmla.py
View file @
480dbd4d
...
...
@@ -2,7 +2,9 @@
from
__future__
import
absolute_import
,
division
,
print_function
import
os
from
datetime
import
datetime
from
os.path
import
expanduser
from
lxml
import
etree
from
spyne
import
AnyXml
,
Application
,
ServiceBase
,
rpc
...
...
@@ -222,7 +224,12 @@ def start_server(write_on_file=False):
# log to the file
# TODO FIX it with os
if
write_on_file
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
filename
=
"C:
\
\
logs
\
\
xmla.log"
)
home_directory
=
expanduser
(
"~"
)
if
not
os
.
path
.
isdir
(
os
.
path
.
join
(
home_directory
,
'logs'
)):
os
.
makedirs
(
os
.
path
.
join
(
home_directory
,
'logs'
))
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
filename
=
os
.
path
.
join
(
home_directory
,
'logs'
,
'xmla.log'
))
else
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logging
.
getLogger
(
'spyne.protocol.xml'
).
setLevel
(
logging
.
DEBUG
)
...
...
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