def test_multi_slice(self): full_cube = Cell(self.cube) cuts_list = (PointCut("date", [2010]), PointCut("cpv", [50, 20]), PointCut("supplier", [1234])) cell_list = full_cube.multi_slice(cuts_list) self.assertEqual(3, len(cell_list.cuts)) self.assertRaises(CubesError, full_cube.multi_slice, {})
def test_slice_drilldown(self): cut = PointCut("date", []) original_cell = Cell(self.cube, [cut]) cell = original_cell.drilldown("date", 2010) self.assertEqual([2010], cell.cut_for_dimension("date").path) cell = cell.drilldown("date", 1) self.assertEqual([2010, 1], cell.cut_for_dimension("date").path) cell = cell.drilldown("date", 2) self.assertEqual([2010, 1, 2], cell.cut_for_dimension("date").path)
def test_get_cell_dimension_cut(self): full_cube = Cell(self.cube) cell = full_cube.slice(PointCut("date", [2010])) cell = cell.slice(PointCut("supplier", [1234])) cut = cell.cut_for_dimension("date") self.assertEqual(str(cut.dimension), "date") self.assertRaises(NoSuchDimensionError, cell.cut_for_dimension, "someunknown") cut = cell.cut_for_dimension("cpv") self.assertEqual(cut, None)
def test_multi_slice(self): full_cube = Cell(self.cube) cuts_list = ( PointCut("date", [2010]), PointCut("cpv", [50, 20]), PointCut("supplier", [1234])) cell_list = full_cube.multi_slice(cuts_list) self.assertEqual(3, len(cell_list.cuts)) self.assertRaises(CubesError, full_cube.multi_slice, {})
def test_cutting(self): full_cube = Cell(self.cube) self.assertEqual(self.cube, full_cube.cube) self.assertEqual(0, len(full_cube.cuts)) cell = full_cube.slice(PointCut("date", [2010])) self.assertEqual(1, len(cell.cuts)) cell = cell.slice(PointCut("supplier", [1234])) cell = cell.slice(PointCut("cpv", [50, 20])) self.assertEqual(3, len(cell.cuts)) self.assertEqual(self.cube, cell.cube) # Adding existing slice should result in changing the slice properties cell = cell.slice(PointCut("date", [2011])) self.assertEqual(3, len(cell.cuts))
def manage_filters(self, filters, cube): cube = self.WORKSPACE.cube(cube) cuts = [] for f in filters: cut = SetCut(f['data']['dimension'], [ key.split('~') for key in f['data']['data']['filters']['keys'] ], f['data']['hierarchy']) cuts.append(cut) cell = Cell(cube, cuts) return cell
def request_filter_members(): request_data = json.loads(request.data) cube = WORKSPACE.cube(request_data['cube']) dimension = cube.dimension(request_data['dimension']) hierarchy = dimension.hierarchy(request_data['hierarchy']) level = dimension.level(request_data['level']) browser = WORKSPACE.browser(cube) cell = Cell(cube, []) members = browser.members(cell, request_data['dimension'],level=request_data['level'], hierarchy=request_data['hierarchy']) html = ENGINE.format_to_filter_html_table(members, dimension, hierarchy, level) return html
def prepare_cell_cubes_ext(argname="cut", target="cell", restrict=False): """Sets `g.cell` with a `Cell` object from argument with name `argname`""" # Used by prepare_browser_request and in /aggregate for the split cell # TODO: experimental code, for now only for dims with time role converters = {"time": CalendarMemberConverter(workspace.calendar)} #if geometry__time not in cuts, then add default date range #has geometry__time has_geom_time = False cuts = [] for cut_string in request.args.getlist(argname): try: if cut_string.split(":")[0] == "geometry__time": has_geom_time = True except: pass cuts += cuts_from_string(g.cube, cut_string, role_member_converters=converters) if not has_geom_time: #add the time cut by default cuts += cuts_from_string(g.cube, DEFAULT_TIMECUT, role_member_converters=converters) if cuts: cell = Cell(g.cube, cuts) else: cell = None if restrict: if workspace.authorizer: cell = workspace.authorizer.restricted_cell(g.auth_identity, cube=g.cube, cell=cell) setattr(g, target, cell)