Commit d3571181 authored by mouadh's avatar mouadh

more xmlwitch

parent 31f6e07f
......@@ -363,19 +363,21 @@ class XmlaExecuteTools():
ignore_fact=True)
all_dimensions_names.append('Measures')
hierarchy_info_slicer = ""
xml = xmlwitch.Builder()
slicer_list = list(
set(all_dimensions_names) - set(
table_name
for table_name in mdx_execution_result['columns_desc']['all']))
# we have to write measures after dimensions !
# we have to write measures after dimensions ! (todo change xsd)
if 'Measures' in slicer_list:
slicer_list.insert(
len(slicer_list),
slicer_list.pop(slicer_list.index('Measures')))
if slicer_list:
with xml.AxisInfo(name='SlicerAxis'):
for dim_diff in slicer_list:
to_write = "[{0}].[{0}]".format(dim_diff)
if dim_diff == 'Measures':
......@@ -386,20 +388,15 @@ class XmlaExecuteTools():
continue
else:
to_write = "[Measures]"
hierarchy_info_slicer += """
<HierarchyInfo name="{0}">
<UName name="{0}.[MEMBER_UNIQUE_NAME]" type="xs:string"/>
<Caption name="{0}.[MEMBER_CAPTION]" type="xs:string"/>
<LName name="{0}.[LEVEL_UNIQUE_NAME]" type="xs:string"/>
<LNum name="{0}.[LEVEL_NUMBER]" type="xs:int"/>
<DisplayInfo name="{0}.[DISPLAY_INFO]" type="xs:unsignedInt"/>
</HierarchyInfo>
""".format(to_write)
if hierarchy_info_slicer:
hierarchy_info_slicer = "<AxisInfo name='SlicerAxis'>\n" + hierarchy_info_slicer + "\n</AxisInfo>\n"
with xml.HierarchyInfo(name=to_write):
xml.UName(name="{0}.[MEMBER_UNIQUE_NAME]".format(to_write), **{'type': 'xs:string'})
xml.Caption(name="{0}.[MEMBER_CAPTION]".format(to_write), **{'type': 'xs:string'})
xml.LName(name="{0}.[LEVEL_UNIQUE_NAME]".format(to_write), **{'type': 'xs:string'})
xml.LNum(name="{0}.[LEVEL_NUMBER]".format(to_write), **{'type': 'xs:int'})
xml.DisplayInfo(name="{0}.[DISPLAY_INFO]".format(to_write), **{'type': 'xs:unsignedInt'})
return hierarchy_info_slicer
return str(xml)
def generate_one_axis_info(self,
mdx_execution_result,
......@@ -438,45 +435,40 @@ class XmlaExecuteTools():
:param Axis: Axis0 or Axis1 (Axis0 by default)
:return:
"""
hierarchy_info = ""
# measure must be written at the top
if self.executer.facts in mdx_execution_result['columns_desc'][
mdx_query_axis].keys() and len(mdx_execution_result[
'columns_desc'][mdx_query_axis][self.executer.facts]) > 1:
hierarchy_info += """
<HierarchyInfo name="{0}">
<UName name="{0}.[MEMBER_UNIQUE_NAME]" type="xs:string"/>
<Caption name="{0}.[MEMBER_CAPTION]" type="xs:string"/>
<LName name="{0}.[LEVEL_UNIQUE_NAME]" type="xs:string"/>
<LNum name="{0}.[LEVEL_NUMBER]" type="xs:int"/>
<DisplayInfo name="{0}.[DISPLAY_INFO]" type="xs:unsignedInt"/>
<PARENT_UNIQUE_NAME name="{0}.[PARENT_UNIQUE_NAME]" type="xs:string"/>
<HIERARCHY_UNIQUE_NAME name="{0}.[HIERARCHY_UNIQUE_NAME]" type="xs:string"/>
</HierarchyInfo>
""".format('[Measures]')
for table_name in mdx_execution_result['columns_desc'][mdx_query_axis]:
axis_tables = mdx_execution_result['columns_desc'][mdx_query_axis]
xml = xmlwitch.Builder()
# measure must be written at the top
if axis_tables:
with xml.AxisInfo(name=Axis):
# many measures , then write this on the top
if self.executer.facts in axis_tables.keys() and len(axis_tables[self.executer.facts]) > 1:
with xml.HierarchyInfo(name='[Measures]'):
xml.UName(name="[Measures].[MEMBER_UNIQUE_NAME]", **{'type': 'xs:string'})
xml.Caption(name="[Measures].[MEMBER_CAPTION]", **{'type': 'xs:string'})
xml.LName(name="[Measures].[LEVEL_UNIQUE_NAME]", **{'type': 'xs:string'})
xml.LNum(name="[Measures].[LEVEL_NUMBER]", **{'type': 'xs:int'})
xml.DisplayInfo(name="[Measures].[DISPLAY_INFO]", **{'type': 'xs:unsignedInt'})
xml.PARENT_UNIQUE_NAME(name="[Measures].[PARENT_UNIQUE_NAME]", **{'type': 'xs:string'})
xml.HIERARCHY_UNIQUE_NAME(name="[Measures].[HIERARCHY_UNIQUE_NAME]", **{'type': 'xs:string'})
for table_name in axis_tables:
if table_name != self.executer.facts:
hierarchy_info += """
<HierarchyInfo name="[{0}].[{0}]">
<UName name="[{0}].[{0}].[MEMBER_UNIQUE_NAME]" type="xs:string"/>
<Caption name="[{0}].[{0}].[MEMBER_CAPTION]" type="xs:string"/>
<LName name="[{0}].[{0}].[LEVEL_UNIQUE_NAME]" type="xs:string"/>
<LNum name="[{0}].[{0}].[LEVEL_NUMBER]" type="xs:int"/>
<DisplayInfo name="[{0}].[{0}].[DISPLAY_INFO]" type="xs:unsignedInt"/>
<PARENT_UNIQUE_NAME name="[{0}].[{0}].[PARENT_UNIQUE_NAME]" type="xs:string"/>
<HIERARCHY_UNIQUE_NAME name="[{0}].[{0}].[HIERARCHY_UNIQUE_NAME]" type="xs:string"/>
</HierarchyInfo>
""".format(table_name)
with xml.HierarchyInfo(name='[{0}].[{0}]'.format(table_name)):
xml.UName(name="[{0}].[{0}].[MEMBER_UNIQUE_NAME]".format(table_name),
**{'type': 'xs:string'})
xml.Caption(name="[{0}].[{0}].[MEMBER_CAPTION]".format(table_name), **{'type': 'xs:string'})
xml.LName(name="[{0}].[{0}].[LEVEL_UNIQUE_NAME]".format(table_name),
**{'type': 'xs:string'})
xml.LNum(name="[{0}].[{0}].[LEVEL_NUMBER]".format(table_name), **{'type': 'xs:int'})
xml.DisplayInfo(name="[{0}].[{0}].[DISPLAY_INFO]".format(table_name),
**{'type': 'xs:unsignedInt'})
xml.PARENT_UNIQUE_NAME(name="[{0}].[{0}].[PARENT_UNIQUE_NAME]".format(table_name),
**{'type': 'xs:string'})
xml.HIERARCHY_UNIQUE_NAME(name="[{0}].[{0}].[HIERARCHY_UNIQUE_NAME]".format(table_name),
**{'type': 'xs:string'})
if hierarchy_info:
hierarchy_info = """
<AxisInfo name='{0}'>
{1}
</AxisInfo>
""".format(Axis, hierarchy_info)
return hierarchy_info
return str(xml)
def generate_axes_info(self, mdx_execution_result):
"""
......@@ -500,15 +492,16 @@ class XmlaExecuteTools():
@staticmethod
def generate_cell_info():
return """
<CellInfo>
<Value name="VALUE"/>
<FormatString name="FORMAT_STRING" type="xs:string"/>
<Language name="LANGUAGE" type="xs:unsignedInt"/>
<BackColor name="BACK_COLOR" type="xs:unsignedInt"/>
<ForeColor name="FORE_COLOR" type="xs:unsignedInt"/>
<FontFlags name="FONT_FLAGS" type="xs:int"/>
</CellInfo>"""
xml = xmlwitch.Builder()
with xml.CellInfo:
xml.Value(name="VALUE")
xml.FormatString(name="FORMAT_STRING", **{'type': 'xs:string'})
xml.Language(name="LANGUAGE", **{'type': 'xs:unsignedInt'})
xml.BackColor(name="BACK_COLOR", **{'type': 'xs:unsignedInt'})
xml.ForeColor(name="FORE_COLOR", **{'type': 'xs:unsignedInt'})
xml.FontFlags(name="FONT_FLAGS", **{'type': 'xs:int'})
return str(xml)
def generate_slicer_axis(self, mdx_execution_result):
"""
......@@ -541,11 +534,17 @@ class XmlaExecuteTools():
"""
tuple = ""
# not used dimensions
for dim_diff in list(
unused_dimensions = list(
set(self.executer.get_all_tables_names(ignore_fact=True)) -
set(table_name
for table_name in mdx_execution_result['columns_desc'][
'all'])):
'all']))
xml = xmlwitch.Builder()
if unused_dimensions:
with xml.Axis(name="SlicerAxis"):
with xml.Tuples:
with xml.Tuple:
for dim_diff in unused_dimensions:
# TODO encode dataframe
# french caracteres
......@@ -557,39 +556,25 @@ class XmlaExecuteTools():
column_attribut = self.executer.tables_loaded[dim_diff].iloc[
0][0]
tuple += """
<Member Hierarchy="[{0}].[{0}]">
<UName>[{0}].[{0}].[{1}].[{2}]</UName>
<Caption>{2}</Caption>
<LName>[{0}].[{0}].[{1}]</LName>
<LNum>0</LNum>
<DisplayInfo>2</DisplayInfo>
</Member>
""".format(dim_diff,
self.executer.tables_loaded[dim_diff].columns[0],
column_attribut)
with xml.Member(Hierarchy="[{0}].[{0}]".format(dim_diff)):
xml.UName('[{0}].[{0}].[{1}].[{2}]'.format(dim_diff,
self.executer.tables_loaded[
dim_diff].columns[0],
column_attribut))
xml.Caption(str(column_attribut))
xml.LName('[{0}].[{0}].[{1}]'.format(dim_diff,
self.executer.tables_loaded[dim_diff].columns[0]))
xml.LNum('0')
xml.DisplayInfo('2')
# if we have zero on one only measures used
if len(self.executer.selected_measures) <= 1:
tuple += """
<Member Hierarchy="[Measures]">
<UName>[Measures].[{0}]</UName>
<Caption>{0}</Caption>
<LName>[Measures]</LName>
<LNum>0</LNum>
<DisplayInfo>0</DisplayInfo>
</Member>
""".format(self.executer.measures[0])
if tuple:
tuple = """
<Axis name="SlicerAxis">
<Tuples>
<Tuple>
{0}
</Tuple>
</Tuples>
</Axis>
""".format(tuple)
with xml.Member(Hierarchy="[Measures]".format(dim_diff)):
xml.UName('[Measures].[{0}]'.format(self.executer.measures[0]))
xml.Caption('{0}'.format(self.executer.measures[0]))
xml.LName('[Measures]')
xml.LNum('0')
xml.DisplayInfo('0')
return tuple
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