예제 #1
0
 def _parse_cut_spec(self, cut_strings, context):
     if cut_strings:
         cuts = []
         for cut_string in cut_strings:
             self.logger.debug("preparing %s from string: '%s'" % (context, cut_string))
             cuts += cubes.cuts_from_string(cut_string)
     else:
         self.logger.debug("preparing %s as whole cube" % context)
         cuts = []
     return cuts
예제 #2
0
    def prepare_cell(self):
        cut_string = self.args.get("cut")

        if cut_string:
            self.logger.debug("preparing cell for cut string: '%s'" % cut_string)
            cuts = cubes.cuts_from_string(cut_string)
        else:
            self.logger.debug("preparing cell for whole cube")
            cuts = []

        self.cell = cubes.Cell(self.cube, cuts)
예제 #3
0
    def prepare_cell(self):
        cut_string = self.args.get("cut")

        if cut_string:
            self.logger.debug("preparing cell from string: '%s'" % cut_string)
            cuts = cubes.cuts_from_string(cut_string)
        else:
            self.logger.debug("preparing cell as whole cube")
            cuts = []

        self.cell = cubes.Cell(self.cube, cuts)
예제 #4
0
    def prepare_cell(self):
        cut_strings = self.args.getlist("cut")

        if cut_strings:
            cuts = []
            for cut_string in cut_strings:
                self.logger.debug("preparing cell from string: '%s'" % cut_string)
                cuts += cubes.cuts_from_string(cut_string)
        else:
            self.logger.debug("preparing cell as whole cube")
            cuts = []

        self.cell = cubes.Cell(self.cube, cuts)
예제 #5
0
def drilldown(dim_name=None):
    cube = workspace.cube(CUBE_NAME)
    browser = workspace.browser(cube)
    result = browser.aggregate()
    # print('keys: ' + result.levels)

    if not dim_name:
        return render_template('drilldown.html', dimensions=cube.dimensions)

    dimension = cube.dimension(dim_name)
    hierarchy = dimension.hierarchy()

    cutstr = request.args.get("cut")
    page = int(request.args.get('page', 0))
    cell = cubes.Cell(browser.cube, cubes.cuts_from_string(cube, cutstr))

    cut = cell.cut_for_dimension(dimension)

    if cut:
        path = cut.path
    else:
        path = []

    result = browser.aggregate(cell, drilldown=[dim_name], page=page, page_size=10)

    if path:
        details = browser.cell_details(cell, dimension)[0]
    else:
        details = []

    levels = hierarchy.levels_for_path(path)
    if levels:
        next_level = hierarchy.next_level(levels[-1])
    else:
        next_level = hierarchy.next_level(None)

    is_last = hierarchy.is_last(next_level)

    pagination = Pagination(page=page, css_framework='foundation', total=result.total_cell_count, per_page=10)

    return render_template('drilldown.html',
                            dimensions=cube.dimensions,
                            dimension=dimension,
                            levels=levels,
                            next_level=next_level,
                            result=result,
                            cell=cell,
                            is_last=is_last,
                            details=details,
                            pagination=pagination
                            )
예제 #6
0
def drilldown_charts(dim_name=None):
    cube = workspace.cube(CUBE_NAME)
    browser = workspace.browser(cube)
    form = forms_data()

    if not dim_name:
        return render_template('charts.html', dimensions=cube.dimensions)

    dimension = cube.dimension(dim_name)
    hierarchy = dimension.hierarchy()

    cutstr = request.args.get("cut")
    cell = cubes.Cell(browser.cube, cubes.cuts_from_string(cube, cutstr))

    cut = cell.cut_for_dimension(dimension)

    if cut:
        path = cut.path
    else:
        path = []

    result = browser.aggregate(cell, drilldown=[dim_name])

    if path:
        details = browser.cell_details(cell, dimension)[0]
    else:
        details = []

    levels = hierarchy.levels_for_path(path)
    if levels:
        next_level = hierarchy.next_level(levels[-1])
    else:
        next_level = hierarchy.next_level(None)

    is_last = hierarchy.is_last(next_level)


    return render_template( dim_name+'_chart.html',
                            dimensions=cube.dimensions,
                            dimension=dimension,
                            levels=levels,
                            next_level=next_level,
                            result=result,
                            cell=cell,
                            is_last=is_last,
                            details=details,
                            chart="Charts",
                            form=form)
예제 #7
0
파일: application.py 프로젝트: zmyer/cubes
def report(dim_name=None):
    browser = workspace.browser(CUBE_NAME)
    cube = browser.cube

    if not dim_name:
        return render_template('report.html', dimensions=cube.dimensions)

    # First we need to get the hierarchy to know the order of levels. Cubes
    # supports multiple hierarchies internally.

    dimension = cube.dimension(dim_name)
    hierarchy = dimension.hierarchy()

    # Parse the`cut` request parameter and convert it to a list of
    # actual cube cuts. Think of this as of multi-dimensional path, even that
    # for this simple example, we are goint to use only one dimension for
    # browsing.

    cutstr = request.args.get("cut")
    cell = Cell(cube, cuts_from_string(cube, cutstr))

    # Get the cut of actually browsed dimension, so we know "where we are" -
    # the current dimension path
    cut = cell.cut_for_dimension(dimension)

    if cut:
        path = cut.path
    else:
        path = []

    #
    # Do the work, do the aggregation.
    #
    result = browser.aggregate(cell, drilldown=[dim_name])

    # If we have no path, then there is no cut for the dimension, # therefore
    # there is no corresponding detail.
    if path:
        details = browser.cell_details(cell, dimension)[0]
    else:
        details = []

    # Find what level we are on and what is going to be the drill-down level
    # in the hierarchy

    levels = hierarchy.levels_for_path(path)
    if levels:
        next_level = hierarchy.next_level(levels[-1])
    else:
        next_level = hierarchy.next_level(None)

    # Are we at the very detailed level?

    is_last = hierarchy.is_last(next_level)
    # Finally, we render it

    return render_template('report.html',
                           dimensions=cube.dimensions,
                           dimension=dimension,
                           levels=levels,
                           next_level=next_level,
                           result=result,
                           cell=cell,
                           is_last=is_last,
                           details=details)
예제 #8
0
def report(dim_name=None):
    global model
    browser = get_browser()

    if not dim_name:
        return render_template('report_star.html', dimensions=model.dimensions)

    # First we need to get the hierarchy to know the order of levels. Cubes
    # supports multiple hierarchies internally.

    dimension = model.dimension(dim_name)
    hierarchy = dimension.hierarchy()

    # Parse the`cut` request parameter and convert it to a list of
    # actual cube cuts. Think of this as of multi-dimensional path, even that
    # for this simple example, we are goint to use only one dimension for
    # browsing.

    cutstr = request.args.get("cut")
    cell = cubes.Cell(browser.cube, cubes.cuts_from_string(cutstr))

    # Get the cut of actually browsed dimension, so we know "where we are" -
    # the current dimension path
    cut = cell.cut_for_dimension(dimension)

    if cut:
        path = cut.path
    else:
        path = []

    #
    # Do the work, do the aggregation.
    #
    result = browser.aggregate(cell, drilldown=[dim_name])

    # If we have no path, then there is no cut for the dimension, # therefore
    # there is no corresponding detail.
    if path:
        breadcrumbs = browser.cell_details(cell, dimension)[0]
    else:
        breadcrumbs = {}

    # Find what level we are on and what is going to be the drill-down level
    # in the hierarchy

    levels = hierarchy.levels_for_path(path)
    if levels:
        next_level = hierarchy.next_level(levels[-1])
    else:
        next_level = hierarchy.levels[0]

    # To have human-readable table, we are not going to display keys or codes,
    # but actual human-readable labels that are also stored within dimension.
    # The dimension provides information in which attribute the label is
    # stored.

    label_attribute = next_level.label_attribute.ref(simplify=True)

    # We also need to know key attribute for the level, so we can generate
    # appropriate URL links with cut of drilled-down cells.

    key = next_level.key.ref(simplify=True)

    # Are we at the very detailed level?

    is_last = len(path) >= len(hierarchy.levels) - 1

    # Finally, we render it

    return render_template('report_star.html',
                           dimensions=model.dimensions,
                           dimension=dimension,
                           levels=levels,
                           next_level=next_level,
                           label_attribute=label_attribute,
                           level_key=key,
                           result=result,
                           cell=cell,
                           is_last=is_last,
                           breadcrumbs=breadcrumbs)
예제 #9
0
def report(dim_name=None):
    cube = workspace.cube("contracts")
    browser = workspace.browser(cube)
    result = browser.aggregate()
    print 'keys: ', result.levels

    if not dim_name:
        return render_template('report.html', dimensions=cube.dimensions)

    # First we need to get the hierarchy to know the order of levels. Cubes
    # supports multiple hierarchies internally.
    
    dimension = cube.dimension(dim_name)
    hierarchy = dimension.hierarchy()

    # Parse the`cut` request parameter and convert it to a list of 
    # actual cube cuts. Think of this as of multi-dimensional path, even that 
    # for this simple example, we are goint to use only one dimension for
    # browsing.

    cutstr = request.args.get("cut")
    cell = cubes.Cell(browser.cube, cubes.cuts_from_string(cube,cutstr))

    # Get the cut of actually browsed dimension, so we know "where we are" -
    # the current dimension path
    cut = cell.cut_for_dimension(dimension)

    if cut:
        path = cut.path
    else:
        path = []
    
    #
    # Do the work, do the aggregation.
    #
    print "AGGREGATE %s DD: %s" % (cell, dim_name)
    result = browser.aggregate(cell, drilldown=[dim_name])

    # If we have no path, then there is no cut for the dimension, # therefore
    # there is no corresponding detail.
    if path:
        details = browser.cell_details(cell, dimension)[0]
    else:
        details = []

    # Find what level we are on and what is going to be the drill-down level
    # in the hierarchy
    
    levels = hierarchy.levels_for_path(path)
    if levels:
        next_level = hierarchy.next_level(levels[-1])
    else:
        next_level = hierarchy.next_level(None)

    # Are we at the very detailed level?

    is_last = hierarchy.is_last(next_level)
    # Finally, we render it

    return render_template('report.html',
                            dimensions=cube.dimensions,
                            dimension=dimension,
                            levels=levels,
                            next_level=next_level,
                            result=result,
                            cell=cell,
                            is_last=is_last,
                            details=details)
예제 #10
0
# Drill down on service
print('\n\n...drilling down on services...')
result = browser.aggregate(drilldown=["dm_service:service_name"])
for record in result:
    print(record)
    # print(record["dm_service.crown"], "\t", record['amount_sum'])

# Cut

print('\n\n...Cut services for Crown Service Only...')

dimension = cube.dimension("dm_service")
hierarchy = dimension.hierarchy()

cell = Cell(cube, cuts_from_string(cube, "dm_service:True"))

cut = cell.cut_for_dimension(dimension)

if cut:
    path = cut.path
else:
    path = []

#
# Do the work, do the aggregation.
#
result = browser.aggregate(cell, drilldown=["dm_datetime"])
for record in result:
    print(record)
예제 #11
0
def report(dim_name=None):
    global model
    browser = get_browser()

    if not dim_name:
        return render_template('report_star.html', dimensions=model.dimensions)

    # First we need to get the hierarchy to know the order of levels. Cubes
    # supports multiple hierarchies internally.
    
    dimension = model.dimension(dim_name)
    hierarchy = dimension.hierarchy()

    # Parse the`cut` request parameter and convert it to a list of 
    # actual cube cuts. Think of this as of multi-dimensional path, even that 
    # for this simple example, we are goint to use only one dimension for
    # browsing.

    cutstr = request.args.get("cut")
    cell = cubes.Cell(browser.cube, cubes.cuts_from_string(cutstr))

    # Get the cut of actually browsed dimension, so we know "where we are" -
    # the current dimension path
    cut = cell.cut_for_dimension(dimension)

    if cut:
        path = cut.path
    else:
        path = []
    
    #
    # Do the work, do the aggregation.
    #
    result = browser.aggregate(cell, drilldown=[dim_name])

    # If we have no path, then there is no cut for the dimension, # therefore
    # there is no corresponding detail.
    if path:
        breadcrumbs = browser.cell_details(cell, dimension)[0]
    else:
        breadcrumbs = {}

    # Find what level we are on and what is going to be the drill-down level
    # in the hierarchy
    
    levels = hierarchy.levels_for_path(path)
    if levels:
        next_level = hierarchy.next_level(levels[-1])
    else:
        next_level = hierarchy.levels[0]
    
    # To have human-readable table, we are not going to display keys or codes,
    # but actual human-readable labels that are also stored within dimension.
    # The dimension provides information in which attribute the label is
    # stored.
    
    label_attribute = next_level.label_attribute.ref(simplify=True)

    # We also need to know key attribute for the level, so we can generate
    # appropriate URL links with cut of drilled-down cells.

    key = next_level.key.ref(simplify=True)

    # Are we at the very detailed level?

    is_last = len(path) >= len(hierarchy.levels)-1

    # Finally, we render it

    return render_template('report_star.html', 
                            dimensions=model.dimensions, 
                            dimension=dimension,
                            levels=levels, 
                            next_level=next_level, 
                            label_attribute=label_attribute, 
                            level_key=key,
                            result=result, 
                            cell=cell, is_last=is_last,
                            breadcrumbs=breadcrumbs)