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
4ba40d5b
Commit
4ba40d5b
authored
Jul 24, 2017
by
mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xmlwitch
parent
1eea7384
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
67 deletions
+114
-67
olapy/core/services/xmla_execute_tools.py
olapy/core/services/xmla_execute_tools.py
+114
-67
No files found.
olapy/core/services/xmla_execute_tools.py
View file @
4ba40d5b
...
...
@@ -4,6 +4,7 @@ import itertools
from
collections
import
OrderedDict
import
numpy
as
np
import
xmlwitch
class
XmlaExecuteTools
():
...
...
@@ -88,7 +89,8 @@ class XmlaExecuteTools():
:param splited_df:
:return:
"""
axis0
=
""
# axis0 = ""
xml
=
xmlwitch
.
Builder
()
# only measure selected
if
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
].
keys
()
==
[
self
.
executer
.
facts
...
...
@@ -129,77 +131,122 @@ class XmlaExecuteTools():
first_att
=
3
for
tupls
in
itertools
.
chain
(
*
tuples
):
axis0
+=
"<Tuple>
\
n
"
if
tupls
[
0
][
1
]
in
self
.
executer
.
measures
and
len
(
self
.
executer
.
selected_measures
)
>
1
:
axis0
+=
"""
<Member Hierarchy="[Measures]">
<UName>[Measures].[{0}]</UName>
<Caption>{0}</Caption>
<LName>[Measures]</LName>
<LNum>0</LNum>
<DisplayInfo>0</DisplayInfo>
<HIERARCHY_UNIQUE_NAME>[Measures]</HIERARCHY_UNIQUE_NAME>
</Member>
"""
.
format
(
tupls
[
0
][
1
])
if
tupls
[
0
][
-
1
]
in
self
.
executer
.
measures
:
axis0
+=
"</Tuple>
\
n
"
continue
for
tupl
in
tupls
:
tuple_without_minus_1
=
self
.
get_tuple_without_nan
(
tupl
)
# french caracteres
# TODO encode dataframe
if
type
(
tuple_without_minus_1
[
-
1
])
==
unicode
:
tuple_without_minus_1
=
[
x
.
encode
(
'utf-8'
,
'replace'
)
for
x
in
tuple_without_minus_1
]
axis0
+=
"""
<Member Hierarchy="[{0}].[{0}]">
<UName>[{0}].[{0}].[{1}].{2}</UName>
<Caption>{3}</Caption>
<LName>[{0}].[{0}].[{1}]</LName>
<LNum>{4}</LNum>
<DisplayInfo>131076</DisplayInfo>"""
.
format
(
tuple_without_minus_1
[
0
],
splited_df
[
tuple_without_minus_1
[
0
]].
columns
[
len
(
tuple_without_minus_1
)
-
first_att
],
'.'
.
join
([
'['
+
str
(
i
)
+
']'
for
i
in
tuple_without_minus_1
[
first_att
-
1
:]
]),
tuple_without_minus_1
[
-
1
],
len
(
tuple_without_minus_1
)
-
first_att
)
# PARENT_UNIQUE_NAME must be before HIERARCHY_UNIQUE_NAME
if
len
(
tuple_without_minus_1
[
first_att
-
1
:])
>
1
:
axis0
+=
"""
<PARENT_UNIQUE_NAME>[{0}].[{0}].[{1}].{2}</PARENT_UNIQUE_NAME>"""
.
format
(
tuple_without_minus_1
[
0
],
splited_df
[
tuple_without_minus_1
[
0
]].
columns
[
0
],
'.'
.
join
([
'['
+
str
(
i
)
+
']'
for
i
in
tuple_without_minus_1
[
first_att
-
1
:
-
1
]
]))
axis0
+=
"""
<HIERARCHY_UNIQUE_NAME>[{0}].[{0}]</HIERARCHY_UNIQUE_NAME>
</Member>
"""
.
format
(
tuple_without_minus_1
[
0
])
axis0
+=
"</Tuple>
\
n
"
if
axis0
:
axis0
=
"""
# axis0 += "<Tuple>\n"
with
xml
.
Tuple
:
if
tupls
[
0
][
1
]
in
self
.
executer
.
measures
and
len
(
self
.
executer
.
selected_measures
)
>
1
:
with
xml
.
Member
(
Hierarchy
=
"[Measures]"
):
xml
.
UName
(
'[Measures].[{0}]'
.
format
(
tupls
[
0
][
1
]))
xml
.
Caption
(
'{0}'
.
format
(
tupls
[
0
][
1
]))
xml
.
LName
(
'[Measures]'
)
xml
.
LNum
(
'0'
)
xml
.
DisplayInfo
(
'0'
)
xml
.
HIERARCHY_UNIQUE_NAME
(
'[Measures]'
)
# axis0 += """
# <Member Hierarchy="[Measures]">
# <UName>[Measures].[{0}]</UName>
# <Caption>{0}</Caption>
# <LName>[Measures]</LName>
# <LNum>0</LNum>
# <DisplayInfo>0</DisplayInfo>
# <HIERARCHY_UNIQUE_NAME>[Measures]</HIERARCHY_UNIQUE_NAME>
# </Member>
# """.format(tupls[0][1])
if
tupls
[
0
][
-
1
]
in
self
.
executer
.
measures
:
# tocom
# axis0 += "</Tuple>\n"
continue
for
tupl
in
tupls
:
tuple_without_minus_1
=
self
.
get_tuple_without_nan
(
tupl
)
# french caracteres
# TODO encode dataframe
if
type
(
tuple_without_minus_1
[
-
1
])
==
unicode
:
tuple_without_minus_1
=
[
x
.
encode
(
'utf-8'
,
'replace'
)
for
x
in
tuple_without_minus_1
]
# todo ugly !!
with
xml
.
Member
(
Hierarchy
=
"[{0}].[{0}]"
.
format
(
tuple_without_minus_1
[
0
])):
xml
.
UName
(
'[{0}].[{0}].[{1}].{2}'
.
format
(
tuple_without_minus_1
[
0
],
splited_df
[
tuple_without_minus_1
[
0
]].
columns
[
len
(
tuple_without_minus_1
)
-
first_att
],
'.'
.
join
([
'['
+
str
(
i
)
+
']'
for
i
in
tuple_without_minus_1
[
first_att
-
1
:]
])))
xml
.
Caption
(
'{0}'
.
format
(
tuple_without_minus_1
[
-
1
]))
xml
.
LName
(
'[{0}].[{0}].[{1}]'
.
format
(
tuple_without_minus_1
[
0
],
splited_df
[
tuple_without_minus_1
[
0
]].
columns
[
len
(
tuple_without_minus_1
)
-
first_att
]))
xml
.
LNum
(
'{0}'
.
format
(
len
(
tuple_without_minus_1
)
-
first_att
))
xml
.
DisplayInfo
(
'131076'
)
# axis0 += """
# <Member Hierarchy="[{0}].[{0}]">
# <UName>[{0}].[{0}].[{1}].{2}</UName>
# <Caption>{3}</Caption>
# <LName>[{0}].[{0}].[{1}]</LName>
# <LNum>{4}</LNum>
# <DisplayInfo>131076</DisplayInfo>""".format(
# tuple_without_minus_1[0], splited_df[tuple_without_minus_1[
# 0]].columns[len(tuple_without_minus_1) - first_att],
# '.'.join([
# '[' + str(i) + ']'
# for i in tuple_without_minus_1[first_att - 1:]
# ]), tuple_without_minus_1[-1],
# len(tuple_without_minus_1) - first_att)
# PARENT_UNIQUE_NAME must be before HIERARCHY_UNIQUE_NAME
if
len
(
tuple_without_minus_1
[
first_att
-
1
:])
>
1
:
xml
.
PARENT_UNIQUE_NAME
(
'[{0}].[{0}].[{1}].{2}'
.
format
(
tuple_without_minus_1
[
0
],
splited_df
[
tuple_without_minus_1
[
0
]].
columns
[
0
],
'.'
.
join
([
'['
+
str
(
i
)
+
']'
for
i
in
tuple_without_minus_1
[
first_att
-
1
:
-
1
]
])))
# axis0 += """
# <PARENT_UNIQUE_NAME>[{0}].[{0}].[{1}].{2}</PARENT_UNIQUE_NAME>""".format(
# tuple_without_minus_1[0],
# splited_df[tuple_without_minus_1[0]].columns[0],
# '.'.join([
# '[' + str(i) + ']'
# for i in tuple_without_minus_1[first_att - 1:-1]
# ]))
xml
.
HIERARCHY_UNIQUE_NAME
(
'[{0}].[{0}]'
.
format
(
tuple_without_minus_1
[
0
]))
# axis0 += """
# <HIERARCHY_UNIQUE_NAME>[{0}].[{0}]</HIERARCHY_UNIQUE_NAME>
# </Member>
# """.format(tuple_without_minus_1[0])
# axis0 += "</Tuple>\n"
print
(
xml
)
print
(
type
(
xml
))
print
(
str
(
xml
)
==
''
)
if
str
(
xml
)
!=
''
:
xml
=
"""
<Axis name="{0}">
<Tuples>
{1}
</Tuples>
</Axis>
"""
.
format
(
axis
,
axis0
)
return
axis0
"""
.
format
(
axis
,
str
(
xml
))
# if axis0:
# axis0 = """
# <Axis name="{0}">
# <Tuples>
# {1}
# </Tuples>
# </Axis>
# """.format(axis, axis0)
print
(
xml
)
return
str
(
xml
)
def
generate_xs0
(
self
,
mdx_execution_result
):
"""
...
...
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