# Path: regenesis/core.py
# def get_catalog(catalog_name):
# 
# Path: regenesis/database.py
# def get_fact_table(cube_name):
# def load_cube(cube, update=False):
# 
# Path: regenesis/database.py
# def get_fact_table(cube_name):
# def load_cube(cube, update=False):


from sqlalchemy import func, select, and_
from sqlalchemy.sql.expression import bindparam
from regenesis.core import engine, app
from regenesis.database import cube_table, value_table, statistic_table
from regenesis.database import dimension_table, reference_table, get_fact_table
from pprint import pprint
    q = fact_table.select()
    selects, wheres, tables = [], [], [fact_table]

    if not readable:
        selects.append(fact_table.columns['fact_id'].label('REGENESIS_ID'))

    params = {}
    for dim in dimensions:
        name = dim.get('dim_name')
        field = name.upper()
        title = dim.get('dim_title_de')

        if readable:
            unit = dim.get('ref_unit_name')
            if unit is not None:
                field = '%s; %s' % (field, unit)
            field = '%s (%s)' % (title, field)

        type_ = dim.get('ref_type')
        if type_ == 'measure':
            selects.append(fact_table.columns[name].label(field))
            if not readable:
                selects.append(fact_table.columns[name + "_quality"].label(field + '_QUALITY'))
                selects.append(fact_table.columns[name + "_error"].label(field + '_ERROR'))
        if type_ == 'time':
            selects.append(fact_table.columns[name].label(field))
            if not readable:
                selects.append(fact_table.columns[name + '_from'].label(field + '_FROM'))
                selects.append(fact_table.columns[name + '_until'].label(field + '_UNTIL'))
        elif type_ == 'axis':

# Path: regenesis/core.py
# def get_catalog(catalog_name):
# 
# Path: regenesis/database.py
# def get_fact_table(cube_name):
# def load_cube(cube, update=False):
# 
# Path: regenesis/database.py
# def get_fact_table(cube_name):
# def load_cube(cube, update=False):


# Path: regenesis/queries.py
from sqlalchemy import func, select, and_
from sqlalchemy.sql.expression import bindparam
from regenesis.core import engine, app
from regenesis.database import cube_table, value_table, statistic_table
from regenesis.database import dimension_table, reference_table, get_fact_table
from pprint import pprint

    q = fact_table.select()
    selects, wheres, tables = [], [], [fact_table]

    if not readable:
        selects.append(fact_table.columns['fact_id'].label('REGENESIS_ID'))

    params = {}
    for dim in dimensions:
        name = dim.get('dim_name')
        field = name.upper()
        title = dim.get('dim_title_de')

        if readable:
            unit = dim.get('ref_unit_name')
            if unit is not None:
                field = '%s; %s' % (field, unit)
            field = '%s (%s)' % (title, field)

        type_ = dim.get('ref_type')
        if type_ == 'measure':
            selects.append(fact_table.columns[name].label(field))
            if not readable:
                selects.append(fact_table.columns[name + "_quality"].label(field + '_QUALITY'))
                selects.append(fact_table.columns[name + "_error"].label(field + '_ERROR'))
        if type_ == 'time':
            selects.append(fact_table.columns[name].label(field))
            if not readable:
                selects.append(fact_table.columns[name + '_from'].label(field + '_FROM'))
                selects.append(fact_table.columns[name + '_until'].label(field + '_UNTIL'))
        elif type_ == 'axis':

            vt = value_table.table.alias('value_%s' % name)