# Path: regenesis/queries.py
# def get_cubes(cube_name=None):
#     ct = cube_table.table.alias('cube')
#     st = statistic_table.table.alias('statistic')
#     q = ct.join(st, st.c.name==ct.c.statistic_name)
#     q = q.select(use_labels=True)
#     if cube_name is not None:
#         q = q.where(ct.c.name==cube_name)
#     return list(engine.query(q))
# 
# def get_all_dimensions():
#     return list(dimension_table)
# 
# def get_dimensions(cube_name):
#     rt = reference_table.table.alias('ref')
#     dt = dimension_table.table.alias('dim')
#     q = rt.join(dt, rt.c.dimension_name==dt.c.name)
#     q = q.select(use_labels=True)
#     q = q.where(rt.c.cube_name==cube_name)
#     res = engine.query(q)
#     return list(res)


import json
from regenesis.queries import get_cubes, get_all_dimensions, get_dimensions
from pprint import pprint


def generate_dimensions():
    dimensions = []
    for dimension in get_all_dimensions():
        pprint (dimension)
        if dimension.get('measure_type').startswith('W-'):
            continue
        attrs = ['name', 'label']
        if 'ZI' in dimension.get('measure_type'):
            attrs = ['text', 'from', 'until']
        dim = {
            'name': dimension.get('name'),
            'label': dimension.get('title_de'),
            'description': dimension.get('definition_de'),
            'attributes': attrs
        }
        dimensions.append(dim)
    return dimensions


def generate_cubes():
    cubes = []
    for cube in get_cubes():
        dimensions = []
        measures = []
        joins = []
        mappings = {}
        cube_name = cube.get('cube_name')

# Path: regenesis/queries.py
# def get_cubes(cube_name=None):
#     ct = cube_table.table.alias('cube')
#     st = statistic_table.table.alias('statistic')
#     q = ct.join(st, st.c.name==ct.c.statistic_name)
#     q = q.select(use_labels=True)
#     if cube_name is not None:
#         q = q.where(ct.c.name==cube_name)
#     return list(engine.query(q))
# 
# def get_all_dimensions():
#     return list(dimension_table)
# 
# def get_dimensions(cube_name):
#     rt = reference_table.table.alias('ref')
#     dt = dimension_table.table.alias('dim')
#     q = rt.join(dt, rt.c.dimension_name==dt.c.name)
#     q = q.select(use_labels=True)
#     q = q.where(rt.c.cube_name==cube_name)
#     res = engine.query(q)
#     return list(res)


# Path: regenesis/modelgen.py
import json
from regenesis.queries import get_cubes, get_all_dimensions, get_dimensions
from pprint import pprint



def generate_dimensions():
    dimensions = []
    for dimension in get_all_dimensions():
        pprint (dimension)
        if dimension.get('measure_type').startswith('W-'):
            continue
        attrs = ['name', 'label']
        if 'ZI' in dimension.get('measure_type'):
            attrs = ['text', 'from', 'until']
        dim = {
            'name': dimension.get('name'),
            'label': dimension.get('title_de'),
            'description': dimension.get('definition_de'),
            'attributes': attrs
        }
        dimensions.append(dim)
    return dimensions


def generate_cubes():
    cubes = []
    for cube in get_cubes():
        dimensions = []
        measures = []
        joins = []
        mappings = {}
        cube_name = cube.get('cube_name')

        for dim in get_dimensions(cube_name):