Exemple #1
0
try:
    import sqlalchemy
    import sqlalchemy.sql as sql
    from sqlalchemy.sql.functions import ReturnTypeFromArgs
except ImportError:
    from cubes.common import MissingPackage
    sqlalchemy = sql = MissingPackage("sqlalchemy", "SQL aggregation browser")
    missing_error = MissingPackage("sqlalchemy", "SQL browser extensions")

    class ReturnTypeFromArgs(object):
        def __init__(*args, **kwargs):
            # Just fail by trying to call missing package
            missing_error()


class avg(ReturnTypeFromArgs):
    pass


# Works with PostgreSQL
class stddev(ReturnTypeFromArgs):
    pass


class variance(ReturnTypeFromArgs):
    pass
Exemple #2
0
# Soft dependency on Werkzeug
try:
    from werkzeug.local import Local, LocalManager
    from werkzeug.routing import Map, Rule

    local = Local()
    local_manager = LocalManager([local])

except:
    from cubes.common import MissingPackage
    _missing = MissingPackage("werkzeug", "Slicer server")
    Local = LocalManager = _missing
    Map = Rule = _missing

    local = _missing
    local_manager = _missing
Exemple #3
0
    import sqlalchemy
    import sqlalchemy.sql as sql

    aggregation_functions = {
        "sum": sql.functions.sum,
        "min": sql.functions.min,
        "max": sql.functions.max,
        "count": sql.functions.count,
        "avg": extensions.avg,
        "stddev": extensions.stddev,
        "variance": extensions.variance
    }

except ImportError:
    from cubes.common import MissingPackage
    sqlalchemy = sql = MissingPackage("sqlalchemy", "SQL aggregation browser")
    aggregation_functions = {}

__all__ = ["SnowflakeBrowser", "QueryContext"]


class SnowflakeBrowser(AggregationBrowser):
    """docstring for SnowflakeBrowser"""
    def __init__(self,
                 cube,
                 connectable=None,
                 locale=None,
                 metadata=None,
                 debug=False,
                 **options):
        """SnowflakeBrowser is a SQL-based AggregationBrowser implementation that
Exemple #4
0
import pkgutil
import urlparse
import urllib2
import shutil
import json
import os
import re

from collections import OrderedDict, namedtuple
from .errors import *

try:
    import jsonschema
except ImportError:
    from cubes.common import MissingPackage
    jsonschema = MissingPackage("jsonschema", "Model validation")

__all__ = (
    "read_model_metadata",
    "read_model_metadata_bundle",
    "write_model_metadata_bundle",
    "expand_cube_metadata",
    "expand_dimension_links",
    "expand_dimension_metadata",
    "expand_level_metadata",
    "expand_attribute_metadata",
    "validate_model",
)

# TODO: add the following:
#
Exemple #5
0
import os
import shutil
import cubes

try:
    from whoosh import index
    from whoosh.fields import Schema, TEXT, KEYWORD, ID, STORED, NUMERIC
    from whoosh.qparser import QueryParser
    from whoosh.query import Term
    from whoosh.sorting import FieldFacet

except ImportError:
    from cubes.common import MissingPackage
    m = MissingPackage('whoosh', "search engine backend")
    Schema = index = m


class WhooshIndexer(object):
    """Create a SQL index for Sphinx"""
    def __init__(self, browser, config=None):
        """Creates a cube indexer - object that will provide xmlpipe2 data source for Sphinx
        search engine (http://sphinxsearch.com).

        :Attributes:
            * `browser` - configured AggregationBrowser instance

        Generated attributes:
            * id
            * dimension
            * (hierarchy) - assume default
            * level
Exemple #6
0
try:
    from collections import OrderedDict
except ImportError:
    from ordereddict import OrderedDict
    
from cubes.common import logger_name, get_logger
from collections import deque

try:
    import sqlalchemy
    import sqlalchemy.sql.expression as expression
    import sqlalchemy.sql.functions as functions
except ImportError:
    from cubes.common import MissingPackage
    _missing = MissingPackage("sqlalchemy", "Built-in SQL aggregation browser")
    sqlalchemy = expression = functions = _missing

__all__ = [
    "SQLBrowser",
    "CubeQuery"
]

# FIXME: required functionality TODO
# 
# * [DONE] number of items in drill-down
# * [DONE] dimension values
# * [DONE] drill-down sorting
# * [DONE] drill-down pagination
# * drill-down limits (such as top-10)
# * [DONE] facts sorting
Exemple #7
0
from collections import defaultdict

from apiclient.errors import HttpError
from apiclient.discovery import build
from oauth2client.client import AccessTokenRefreshError

from collections import OrderedDict

import re

try:
    from oauth2client.client import SignedJwtAssertionCredentials
except ImportError:
    from cubes.common import MissingPackage
    SignedJwtAssertionCredentials = MissingPackage(
        "oauth2client.crypt",
        "Google Analytics Backend with SignedJwtAssertionCredentials; " +
        "you may need to install pyopenssl and OpenSSL")

try:
    import httplib2
except ImportError:
    from cubes.common import MissingPackage
    httplib2 = MissingPackage("httplib2", "Google Analytics Backend")

# .js file that contains structure with definition of GA cubes – relation
# between metrics and dimensions that can be used together in a query
# Note: this is kind-of workaround, since GA metadata API does not provide a
# way to get this information
_GA_CUBES_JS = "https://developers.google.com/apps/js/analytics_dm/analytics_dm_js-bundle.js"

GA_TIME_DIM_METADATA = {