Commit 4ba40d5b authored by mouadh's avatar mouadh

xmlwitch

parent 1eea7384
...@@ -4,6 +4,7 @@ import itertools ...@@ -4,6 +4,7 @@ import itertools
from collections import OrderedDict from collections import OrderedDict
import numpy as np import numpy as np
import xmlwitch
class XmlaExecuteTools(): class XmlaExecuteTools():
...@@ -88,7 +89,8 @@ class XmlaExecuteTools(): ...@@ -88,7 +89,8 @@ class XmlaExecuteTools():
:param splited_df: :param splited_df:
:return: :return:
""" """
axis0 = "" # axis0 = ""
xml = xmlwitch.Builder()
# only measure selected # only measure selected
if mdx_execution_result['columns_desc'][mdx_query_axis].keys() == [ if mdx_execution_result['columns_desc'][mdx_query_axis].keys() == [
self.executer.facts self.executer.facts
...@@ -129,23 +131,32 @@ class XmlaExecuteTools(): ...@@ -129,23 +131,32 @@ class XmlaExecuteTools():
first_att = 3 first_att = 3
for tupls in itertools.chain(*tuples): for tupls in itertools.chain(*tuples):
axis0 += "<Tuple>\n" # axis0 += "<Tuple>\n"
with xml.Tuple:
if tupls[0][1] in self.executer.measures and len( if tupls[0][1] in self.executer.measures and len(
self.executer.selected_measures) > 1: self.executer.selected_measures) > 1:
with xml.Member(Hierarchy="[Measures]"):
axis0 += """ xml.UName('[Measures].[{0}]'.format(tupls[0][1]))
<Member Hierarchy="[Measures]"> xml.Caption('{0}'.format(tupls[0][1]))
<UName>[Measures].[{0}]</UName> xml.LName('[Measures]')
<Caption>{0}</Caption> xml.LNum('0')
<LName>[Measures]</LName> xml.DisplayInfo('0')
<LNum>0</LNum> xml.HIERARCHY_UNIQUE_NAME('[Measures]')
<DisplayInfo>0</DisplayInfo>
<HIERARCHY_UNIQUE_NAME>[Measures]</HIERARCHY_UNIQUE_NAME> # axis0 += """
</Member> # <Member Hierarchy="[Measures]">
""".format(tupls[0][1]) # <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: if tupls[0][-1] in self.executer.measures:
axis0 += "</Tuple>\n" # tocom
# axis0 += "</Tuple>\n"
continue continue
for tupl in tupls: for tupl in tupls:
...@@ -159,47 +170,83 @@ class XmlaExecuteTools(): ...@@ -159,47 +170,83 @@ class XmlaExecuteTools():
for x in tuple_without_minus_1 for x in tuple_without_minus_1
] ]
axis0 += """ # todo ugly !!
<Member Hierarchy="[{0}].[{0}]"> with xml.Member(Hierarchy="[{0}].[{0}]".format(tuple_without_minus_1[0])):
<UName>[{0}].[{0}].[{1}].{2}</UName> xml.UName('[{0}].[{0}].[{1}].{2}'.format(tuple_without_minus_1[0],
<Caption>{3}</Caption> splited_df[tuple_without_minus_1[
<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], 0]].columns[len(tuple_without_minus_1) - first_att],
'.'.join([ '.'.join(['[' + str(i) + ']' for i in
'[' + str(i) + ']' tuple_without_minus_1[first_att - 1:]
for i in tuple_without_minus_1[first_att - 1:] ])))
]), tuple_without_minus_1[-1], xml.Caption('{0}'.format(tuple_without_minus_1[-1]))
len(tuple_without_minus_1) - first_att) 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 # PARENT_UNIQUE_NAME must be before HIERARCHY_UNIQUE_NAME
if len(tuple_without_minus_1[first_att - 1:]) > 1: if len(tuple_without_minus_1[first_att - 1:]) > 1:
axis0 += """ xml.PARENT_UNIQUE_NAME('[{0}].[{0}].[{1}].{2}'.format(
<PARENT_UNIQUE_NAME>[{0}].[{0}].[{1}].{2}</PARENT_UNIQUE_NAME>""".format(
tuple_without_minus_1[0], tuple_without_minus_1[0],
splited_df[tuple_without_minus_1[0]].columns[0], splited_df[tuple_without_minus_1[0]].columns[0],
'.'.join([ '.'.join([
'[' + str(i) + ']' '[' + str(i) + ']'
for i in tuple_without_minus_1[first_att - 1:-1] for i in tuple_without_minus_1[first_att - 1:-1]
])) ])))
axis0 += """ # axis0 += """
<HIERARCHY_UNIQUE_NAME>[{0}].[{0}]</HIERARCHY_UNIQUE_NAME> # <PARENT_UNIQUE_NAME>[{0}].[{0}].[{1}].{2}</PARENT_UNIQUE_NAME>""".format(
</Member> # tuple_without_minus_1[0],
""".format(tuple_without_minus_1[0]) # splited_df[tuple_without_minus_1[0]].columns[0],
# '.'.join([
axis0 += "</Tuple>\n" # '[' + str(i) + ']'
# for i in tuple_without_minus_1[first_att - 1:-1]
if axis0: # ]))
axis0 = """
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}"> <Axis name="{0}">
<Tuples> <Tuples>
{1} {1}
</Tuples> </Tuples>
</Axis> </Axis>
""".format(axis, axis0) """.format(axis, str(xml))
return axis0 # 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): def generate_xs0(self, mdx_execution_result):
""" """
......
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