Commit b6793cda authored by Stefane Fermigier's avatar Stefane Fermigier

Format w/ yapf.

parent 64486df0
......@@ -12,11 +12,9 @@ manager = Manager(app)
def initdb():
db.create_all()
db.session.add(
User(
username="admin", email="admin@admin.com", password='admin'))
User(username="admin", email="admin@admin.com", password='admin'))
db.session.add(
User(
username="demo", email="demo@demo.com", password="demo"))
User(username="demo", email="demo@demo.com", password="demo"))
db.session.commit()
print('Initialized the database')
......
from __future__ import absolute_import, division, print_function
import sys
from core.services.xmla import start_server
......
from __future__ import absolute_import, division, print_function
import itertools
import os
import re
from collections import OrderedDict
import itertools
import numpy as np
import pandas as pd
......@@ -51,9 +51,8 @@ class MdxEngine:
location = os.path.join(
os.path.abspath(
os.path.join(
os.path.dirname(__file__), "..", "..", "..", "..")),
MdxEngine.CUBE_FOLDER)
os.path.join(os.path.dirname(__file__), "..", "..", "..",
"..")), MdxEngine.CUBE_FOLDER)
return [
file for file in os.listdir(location)
if os.path.isdir(os.path.join(location, file))
......@@ -68,9 +67,8 @@ class MdxEngine:
'''
return os.path.join(
os.path.abspath(
os.path.join(
os.path.dirname(__file__), '..', "..", '..', '..')),
self.cube_folder)
os.path.join(os.path.dirname(__file__), '..', "..", '..',
'..')), self.cube_folder)
def _load_tables(self):
"""
......@@ -455,7 +453,9 @@ class MdxEngine:
tables_n_columns = self.get_tables_and_columns(query_axes)
columns_to_keep = OrderedDict(
(table, columns) for table, columns in tables_n_columns['all'].items() if table != self.facts)
(table, columns)
for table, columns in tables_n_columns['all'].items()
if table != self.facts)
# if we have measures on axes we have to ignore them
tuples_on_mdx_query = [
......@@ -499,8 +499,7 @@ class MdxEngine:
self.execute_one_tuple(tupl, start_df,
columns_to_keep.values()))
cols = list(
itertools.chain.from_iterable(columns_to_keep.values()))
cols = list(itertools.chain.from_iterable(columns_to_keep.values()))
# TODO BUG !!! https://github.com/pandas-dev/pandas/issues/15525
# solution 1 .astype(str) ( take a lot of time from execution)
......
......@@ -10,26 +10,21 @@
# Any changes you make to it will be overwritten the next time
# the file is generated.
from __future__ import print_function, division, absolute_import, unicode_literals
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from grako.buffering import Buffer
from grako.parsing import graken, Parser
from grako.util import re, RE_FLAGS, generic_main # noqa
from grako.parsing import Parser, graken
from grako.util import RE_FLAGS, generic_main, re # noqa
__all__ = [
'MdxParserGen',
'UnknownSemantics',
'main'
]
__all__ = ['MdxParserGen', 'UnknownSemantics', 'main']
KEYWORDS = {}
class UnknownBuffer(Buffer):
def __init__(
self,
def __init__(self,
text,
whitespace=None,
nameguard=None,
......@@ -37,8 +32,7 @@ class UnknownBuffer(Buffer):
eol_comments_re=None,
ignorecase=None,
namechars='',
**kwargs
):
**kwargs):
super(UnknownBuffer, self).__init__(
text,
whitespace=whitespace,
......@@ -47,13 +41,12 @@ class UnknownBuffer(Buffer):
eol_comments_re=eol_comments_re,
ignorecase=ignorecase,
namechars=namechars,
**kwargs
)
**kwargs)
class MdxParserGen(Parser):
def __init__(
self,
def __init__(self,
whitespace=None,
nameguard=None,
comments_re=None,
......@@ -64,8 +57,7 @@ class MdxParserGen(Parser):
keywords=None,
namechars='',
buffer_class=UnknownBuffer,
**kwargs
):
**kwargs):
if keywords is None:
keywords = KEYWORDS
super(MdxParserGen, self).__init__(
......@@ -79,8 +71,7 @@ class MdxParserGen(Parser):
keywords=keywords,
namechars=namechars,
buffer_class=buffer_class,
**kwargs
)
**kwargs)
@graken()
def _MDX_statement_(self):
......@@ -105,10 +96,10 @@ class MdxParserGen(Parser):
self._condition_specification_()
self.name_last_node('condition_specification')
self._check_eof()
self.ast._define(
['axis_specification_columns', 'axis_specification_rows', 'condition_specification', 'cube_specification', 'name'],
[]
)
self.ast._define([
'axis_specification_columns', 'axis_specification_rows',
'condition_specification', 'cube_specification', 'name'
], [])
@graken()
def _axis_specification_(self):
......@@ -148,6 +139,7 @@ class MdxParserGen(Parser):
self._operator_()
self.name_last_node('@')
self._dim_props_type_()
self._closure(block1)
@graken()
......@@ -173,6 +165,7 @@ class MdxParserGen(Parser):
self._comma_()
self.name_last_node('@')
self._dim_props_op_()
self._closure(block1)
@graken()
......@@ -197,6 +190,7 @@ class MdxParserGen(Parser):
self._error('no available options')
self._dim_props_ligne_()
self.name_last_node('@')
self._closure(block1)
@graken()
......@@ -248,6 +242,7 @@ class MdxParserGen(Parser):
self.name_last_node('@')
with self._optional():
self._right_bracket_()
self._closure(block0)
@graken()
......@@ -305,6 +300,7 @@ class MdxParserGen(Parser):
self.name_last_node('@')
with self._optional():
self._right_bracket_()
self._closure(block0)
with self._optional():
self._right_parentheses_()
......@@ -347,7 +343,8 @@ class MdxParserGen(Parser):
self._token('except')
with self._option():
self._token('extract')
self._error('expecting one of: CROSSJOIN NONEMPTY except extract union')
self._error(
'expecting one of: CROSSJOIN NONEMPTY except extract union')
@graken()
def _dimension_shortcut_(self):
......@@ -420,6 +417,7 @@ class MdxParserGen(Parser):
class UnknownSemantics(object):
def MDX_statement(self, ast):
return ast
......
from __future__ import absolute_import, division, print_function
from grako.model import ModelBuilderSemantics
from .gen_parser.mdxparser import MdxParserGen
from .gen_parser.models import selectStatement
......
......@@ -92,7 +92,7 @@ class Propertielist(ComplexModel):
class Command(ComplexModel):
_type_info = {'Statement': Unicode, }
_type_info = {'Statement': Unicode,}
class ExecuteRequest(ComplexModel):
......
from __future__ import absolute_import, division, print_function
from lxml import etree
from datetime import datetime
from lxml import etree
from spyne import AnyXml, Application, ServiceBase, rpc
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from .xmla_execute_xsds import execute_xsd
from ..services.models import DiscoverRequest, ExecuteRequest, Session
from .xmla_discover_tools import XmlaDiscoverTools
from .xmla_execute_tools import XmlaExecuteTools
from ..services.models import DiscoverRequest, ExecuteRequest, Session
from .xmla_execute_xsds import execute_xsd
class XmlaProviderService(ServiceBase):
......@@ -81,8 +82,7 @@ class XmlaProviderService(ServiceBase):
return discover_tools.discover_mdschema_measures__response(request)
elif request.RequestType == "MDSCHEMA_DIMENSIONS":
return discover_tools.discover_mdschema_dimensions_response(
request)
return discover_tools.discover_mdschema_dimensions_response(request)
elif request.RequestType == "MDSCHEMA_HIERARCHIES":
return discover_tools.discover_mdschema_hierarchies_response(
......@@ -100,8 +100,7 @@ class XmlaProviderService(ServiceBase):
request)
elif request.RequestType == "MDSCHEMA_PROPERTIES":
return discover_tools.discover_mdschema_properties_response(
request)
return discover_tools.discover_mdschema_properties_response(request)
elif request.RequestType == "MDSCHEMA_MEMBERS":
return discover_tools.discover_mdschema_members_response(request)
......
from __future__ import absolute_import, division, print_function
from .xmla_discover_xsds import discover_datasources_xsd, discover_preperties_xsd, discover_schema_rowsets_xsd, \
discover_literals_xsd, mdschema_sets_xsd, mdschema_kpis_xsd, dbschema_catalogs_xsd, mdschema_cubes_xsd, \
dbschema_tables_xsd, mdschema_measures_xsd, mdschema_dimensions_xsd, mdschema_hierarchies_xsd, mdschema_levels_xsd, \
mdschema_measuresgroups_xsd, mdschema_measuresgroups_dimensions_xsd, mdschema_properties_PROPERTIES_xsd, \
mdschema_members_xsd
import uuid
from lxml import etree
from ..mdx.executor.execute import MdxEngine
import uuid
from .xmla_discover_xsds import (dbschema_catalogs_xsd, dbschema_tables_xsd,
discover_datasources_xsd,
discover_literals_xsd,
discover_preperties_xsd,
discover_schema_rowsets_xsd,
mdschema_cubes_xsd, mdschema_dimensions_xsd,
mdschema_hierarchies_xsd, mdschema_kpis_xsd,
mdschema_levels_xsd, mdschema_measures_xsd,
mdschema_measuresgroups_dimensions_xsd,
mdschema_measuresgroups_xsd,
mdschema_members_xsd,
mdschema_properties_PROPERTIES_xsd,
mdschema_sets_xsd)
# TODO clean
......@@ -67,6 +76,7 @@ class XmlaDiscoverTools():
</return>""")
def discover_properties_response(self, request):
def get_props(xsd, PropertyName, PropertyDescription, PropertyType,
PropertyAccessType, IsRequired, Value):
return etree.fromstring("""
......@@ -108,15 +118,15 @@ class XmlaDiscoverTools():
elif request.Restrictions.RestrictionList.PropertyName == 'MdpropMdxSubqueries':
if 'Unspecified' in request.Properties.PropertyList.Catalog:
return get_props(discover_preperties_xsd,
'MdpropMdxSubqueries', 'MdpropMdxSubqueries',
'int', 'Read', 'false', '15')
return get_props(discover_preperties_xsd, 'MdpropMdxSubqueries',
'MdpropMdxSubqueries', 'int', 'Read', 'false',
'15')
if request.Properties.PropertyList.Catalog is not None:
self.change_catalogue(request.Properties.PropertyList.Catalog)
return get_props(discover_preperties_xsd,
'MdpropMdxSubqueries', 'MdpropMdxSubqueries',
'int', 'Read', 'false', '15')
return get_props(discover_preperties_xsd, 'MdpropMdxSubqueries',
'MdpropMdxSubqueries', 'int', 'Read', 'false',
'15')
elif request.Restrictions.RestrictionList.PropertyName == 'MdpropMdxDrillFunctions':
if 'Unspecified' in request.Properties.PropertyList.Catalog:
......@@ -2281,8 +2291,7 @@ class XmlaDiscoverTools():
</row>
</root>
</return>
""".format(self.selected_catalogue, separed_tuple[
0], joined, request.Restrictions.RestrictionList.
MEMBER_UNIQUE_NAME, ''.join(
c for c in separed_tuple[-1]
if c not in '[]')))
""".format(
self.selected_catalogue, separed_tuple[0], joined,
request.Restrictions.RestrictionList.MEMBER_UNIQUE_NAME,
''.join(c for c in separed_tuple[-1] if c not in '[]')))
from __future__ import absolute_import, division, print_function
from collections import OrderedDict
import itertools
from collections import OrderedDict
class XmlaExecuteTools():
......@@ -523,8 +522,8 @@ class XmlaExecuteTools():
tuple = ""
# not used dimensions
for dim_diff in list(
set(self.executer.get_all_tables_names(ignore_fact=True)) -
set([
set(self.executer.get_all_tables_names(ignore_fact=True)) - set(
[
table_name
for table_name in mdx_execution_result['columns_desc'][
'all']
......
......@@ -5,7 +5,6 @@ from flask import Flask
from flask_login import LoginManager
from flask_sqlalchemy import SQLAlchemy
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config[
......
......@@ -38,10 +38,8 @@ class IFrame(object):
params = "?" + six.moves.urllib.parse.urlencode(self.params)
else:
params = ""
return self.iframe.format(src=self.src,
width=self.width,
height=self.height,
params=params)
return self.iframe.format(
src=self.src, width=self.width, height=self.height, params=params)
template = """
......
from __future__ import absolute_import, division, print_function
import json
import pandas as pd
import plotly
import plotly.graph_objs as go
......
from __future__ import absolute_import, division, print_function
import itertools
import os
from io import BytesIO
from itertools import groupby
from operator import itemgetter
import itertools
import pandas as pd
from flask import flash, redirect, render_template, request, send_file, url_for
from flask_login import current_user, login_required, login_user, logout_user
......@@ -13,14 +13,14 @@ from pandas import DataFrame, Series
from treelib import Tree
from treelib.tree import DuplicatedNodeIdError
from .forms import LoginForm, QueryForm
from .models import User
from olapy.web.pivottable import pivot_ui
from ..core.mdx.executor.execute import MdxEngine
from ..core.mdx.executor.execute import MdxEngine
from ..web import app, login_manager
from ..web.logger import Logs
from ..web.stats_utils import graphs
from .forms import LoginForm, QueryForm
from .models import User
# in pandas there is a problem with conversion multiindex dataframe to json
# to solve the export to excel problem we used a global variable
......@@ -35,6 +35,7 @@ log_mdx = Logs('mdx')
class Nod:
def __init__(self, text, id, parent):
self.text = text
self.id = id
......@@ -235,9 +236,10 @@ def stats():
ex = MdxEngine(CUBE)
graph = graphs()
columns = list(itertools.chain.from_iterable(
[[column for column in df.columns] for table_name, df in ex.tables_loaded.items() if
table_name != ex.facts]))
columns = list(
itertools.chain.from_iterable([[column for column in df.columns]
for table_name, df in ex.tables_loaded.
items() if table_name != ex.facts]))
columns.append(ex.measures[0])
temp_rslt = ex.load_star_schema_dataframe[columns].head(200)
......@@ -249,9 +251,8 @@ def stats():
return render_template(
'stats.html',
user=current_user,
table_result=temp_rslt.to_html(classes=[
'table table-bordered table-hover table-striped display'
]),
table_result=temp_rslt.to_html(
classes=['table table-bordered table-hover table-striped display']),
graphe=graph,
ids=graph['ids'])
......
......@@ -4,7 +4,6 @@ from __future__ import absolute_import, division, print_function
import pip
from setuptools import find_packages, setup
session = pip.download.PipSession()
_install_requires = pip.req.parse_requirements(
'requirements.txt', session=session)
......
......@@ -213,13 +213,15 @@ def test_execution_query1():
def test_execution_query3():
df = pd.DataFrame({'Continent': ['America', 'Europe'],
'Amount': [768, 255]}
).groupby(['Continent']).sum()
df = pd.DataFrame({
'Continent': ['America', 'Europe'],
'Amount': [768, 255]
}).groupby(['Continent']).sum()
executer.mdx_query = query12
assert assert_frame_equal(df, executer.execute_mdx()['result']) is None
executer.mdx_query = query11
assert list(executer.execute_mdx()['result']['Amount']) == [1023, 1023, 1023, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
assert list(executer.execute_mdx()['result'][
'Amount']) == [1023, 1023, 1023, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
......@@ -9,6 +9,7 @@ from spyne import Application
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from werkzeug.serving import make_server
from olapy.core.services.xmla import XmlaProviderService
from tests.xs0_responses import TEST_QUERY_AXIS0
......@@ -18,6 +19,7 @@ RUNNING_TOX = 'RUNTING_TOX' in os.environ
class Member(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
......@@ -42,8 +44,7 @@ class WSGIServer:
Copy/pasted from pytest_localserver w/ slight changes.
"""
def __init__(self, host='127.0.0.1', port=8000, application=None,
**kwargs):
def __init__(self, host='127.0.0.1', port=8000, application=None, **kwargs):
self._server = make_server(host, port, application, **kwargs)
self.server_address = self._server.server_address
......
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