def make_views():
    for cube in get_cubes():
        slug = slugify(cube.get('statistic_title_de'))
        slug = slug.replace('-', '_')
        slug = slug + '_' + cube.get('cube_name')
        q = 'DROP VIEW IF EXISTS ' + slug
        engine.query(q)
        q, params = query_cube(cube.get('cube_name'), readable=False)
        q = 'CREATE VIEW ' + slug + ' AS ' + unicode(q)
        engine.query(q, **params)
        print [slug, q]
Beispiel #2
0
def make_views():
    for cube in get_cubes():
        slug = slugify(cube.get('statistic_title_de'))
        slug = slug.replace('-', '_')
        slug = slug + '_' + cube.get('cube_name')
        q = 'DROP VIEW IF EXISTS ' + slug
        engine.query(q)
        q, params = query_cube(cube.get('cube_name'), readable=False)
        q = 'CREATE VIEW ' + slug + ' AS ' + str(q)
        engine.query(q, **params)
        print([slug, q])
Beispiel #3
0
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)
Beispiel #4
0
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))
Beispiel #5
0
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)
Beispiel #6
0
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))
Beispiel #7
0
def get_statistics(dimension_name=None):
    ct = cube_table.table.alias('cube')
    st = statistic_table.table.alias('statistic')
    rt = reference_table.table.alias('reference')
    tables = [ct, st, rt]
    wheres = [
        st.c.name == ct.c.statistic_name, rt.c.cube_name == ct.c.name,
        rt.c.dimension_name == dimension_name
    ]
    q = select([st], and_(*wheres), tables, distinct=True)
    return list(engine.query(q))
Beispiel #8
0
def get_statistics(dimension_name=None):
    ct = cube_table.table.alias('cube')
    st = statistic_table.table.alias('statistic')
    rt = reference_table.table.alias('reference')
    tables = [ct, st, rt]
    wheres = [
      st.c.name==ct.c.statistic_name,
      rt.c.cube_name==ct.c.name,
      rt.c.dimension_name==dimension_name
      ]
    q = select([st], and_(*wheres), tables, distinct=True)
    return list(engine.query(q))
Beispiel #9
0
def freeze_data():
    print "Freezing dimension values..."
    prefix = os.path.join(get_output_dir(), 'data', 'dimensions')
    freeze(value_table.all(), prefix=prefix, filename='{{dimension_name}}.csv', format='csv')
    freeze(value_table.all(), prefix=prefix, filename='{{dimension_name}}.json', format='json')

    print "Freezing cubes..."
    for cube in get_cubes():
        prefix = os.path.join(get_output_dir(), 'data',
                              cube['statistic_name'],
                              cube['cube_name'])
        slug = slugify(cube['statistic_title_de'])
        for (text, rb) in [('labeled', True), ('raw', False)]:
            q, ps = query_cube(cube['cube_name'], readable=rb)
            fn = '%s-%s-%s.csv' % (slug, cube['cube_name'], text)
            print [fn]
            freeze(engine.query(q), prefix=prefix, filename=fn)
Beispiel #10
0
def get_cubes(statistic_name=None):
    q = cube_table.table.select()
    q = q.where(cube_table.table.c.statistic_name==statistic_name)
    return list(engine.query(q))
Beispiel #11
0
def get_cubes(statistic_name=None):
    q = cube_table.table.select()
    q = q.where(cube_table.table.c.statistic_name == statistic_name)
    return list(engine.query(q))