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,77 +131,122 @@ class XmlaExecuteTools(): ...@@ -129,77 +131,122 @@ 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"
if tupls[0][1] in self.executer.measures and len( with xml.Tuple:
self.executer.selected_measures) > 1: if tupls[0][1] in self.executer.measures and len(
self.executer.selected_measures) > 1:
axis0 += """ with xml.Member(Hierarchy="[Measures]"):
<Member Hierarchy="[Measures]"> xml.UName('[Measures].[{0}]'.format(tupls[0][1]))
<UName>[Measures].[{0}]</UName> xml.Caption('{0}'.format(tupls[0][1]))
<Caption>{0}</Caption> xml.LName('[Measures]')
<LName>[Measures]</LName> xml.LNum('0')
<LNum>0</LNum> xml.DisplayInfo('0')
<DisplayInfo>0</DisplayInfo> xml.HIERARCHY_UNIQUE_NAME('[Measures]')
<HIERARCHY_UNIQUE_NAME>[Measures]</HIERARCHY_UNIQUE_NAME>
</Member> # axis0 += """
""".format(tupls[0][1]) # <Member Hierarchy="[Measures]">
# <UName>[Measures].[{0}]</UName>
if tupls[0][-1] in self.executer.measures: # <Caption>{0}</Caption>
axis0 += "</Tuple>\n" # <LName>[Measures]</LName>
continue # <LNum>0</LNum>
# <DisplayInfo>0</DisplayInfo>
for tupl in tupls: # <HIERARCHY_UNIQUE_NAME>[Measures]</HIERARCHY_UNIQUE_NAME>
tuple_without_minus_1 = self.get_tuple_without_nan(tupl) # </Member>
# """.format(tupls[0][1])
# french caracteres
# TODO encode dataframe if tupls[0][-1] in self.executer.measures:
if type(tuple_without_minus_1[-1]) == unicode: # tocom
tuple_without_minus_1 = [ # axis0 += "</Tuple>\n"
x.encode('utf-8', 'replace') continue
for x in tuple_without_minus_1
] for tupl in tupls:
tuple_without_minus_1 = self.get_tuple_without_nan(tupl)
axis0 += """
<Member Hierarchy="[{0}].[{0}]"> # french caracteres
<UName>[{0}].[{0}].[{1}].{2}</UName> # TODO encode dataframe
<Caption>{3}</Caption> if type(tuple_without_minus_1[-1]) == unicode:
<LName>[{0}].[{0}].[{1}]</LName> tuple_without_minus_1 = [
<LNum>{4}</LNum> x.encode('utf-8', 'replace')
<DisplayInfo>131076</DisplayInfo>""".format( for x in tuple_without_minus_1
tuple_without_minus_1[0], splited_df[tuple_without_minus_1[ ]
0]].columns[len(tuple_without_minus_1) - first_att],
'.'.join([ # todo ugly !!
'[' + str(i) + ']' with xml.Member(Hierarchy="[{0}].[{0}]".format(tuple_without_minus_1[0])):
for i in tuple_without_minus_1[first_att - 1:] xml.UName('[{0}].[{0}].[{1}].{2}'.format(tuple_without_minus_1[0],
]), tuple_without_minus_1[-1], splited_df[tuple_without_minus_1[
len(tuple_without_minus_1) - first_att) 0]].columns[len(tuple_without_minus_1) - first_att],
# PARENT_UNIQUE_NAME must be before HIERARCHY_UNIQUE_NAME '.'.join(['[' + str(i) + ']' for i in
if len(tuple_without_minus_1[first_att - 1:]) > 1: tuple_without_minus_1[first_att - 1:]
axis0 += """ ])))
<PARENT_UNIQUE_NAME>[{0}].[{0}].[{1}].{2}</PARENT_UNIQUE_NAME>""".format( xml.Caption('{0}'.format(tuple_without_minus_1[-1]))
tuple_without_minus_1[0], xml.LName('[{0}].[{0}].[{1}]'.format(
splited_df[tuple_without_minus_1[0]].columns[0], tuple_without_minus_1[0], splited_df[tuple_without_minus_1[
'.'.join([ 0]].columns[len(tuple_without_minus_1) - first_att]))
'[' + str(i) + ']' xml.LNum('{0}'.format(len(tuple_without_minus_1) - first_att))
for i in tuple_without_minus_1[first_att - 1:-1] xml.DisplayInfo('131076')
]))
axis0 += """ # axis0 += """
<HIERARCHY_UNIQUE_NAME>[{0}].[{0}]</HIERARCHY_UNIQUE_NAME> # <Member Hierarchy="[{0}].[{0}]">
</Member> # <UName>[{0}].[{0}].[{1}].{2}</UName>
""".format(tuple_without_minus_1[0]) # <Caption>{3}</Caption>
# <LName>[{0}].[{0}].[{1}]</LName>
axis0 += "</Tuple>\n" # <LNum>{4}</LNum>
# <DisplayInfo>131076</DisplayInfo>""".format(
if axis0: # tuple_without_minus_1[0], splited_df[tuple_without_minus_1[
axis0 = """ # 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}"> <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