def compute_aggregates(self): '''\ This method has to be called as the last method when using the loader. It will add additional, required data to the database. ''' log.debug("updating distinct values...") update_distincts(self.dataset.name) log.debug("updating all cubes...") Cube.update_all_cubes(self.dataset)
def _make_cube(self): h.load_fixture('cube_test') ds = model.dataset.find_one() cube = Cube.configure_default_cube(ds) cube.compute() return cube
def test_compute_cube(self): h.load_fixture('cra') cra = model.dataset.find_one() cube = Cube.configure_default_cube(cra) cube.compute() h.assert_true('cubes.cra.default' in mongo.db.collection_names())
def test_compute_cube(self): from openspending.model import Dataset cra = h.load_fixture('cra') cube = Cube.configure_default_cube(cra) cube.compute() h.assert_true('cubes.cra.default' in mongo.db().collection_names())
def test_default_dimensons(self): # test the dimensions for a default cube. # We exclude 'name', 'label' and 'time'. # But include 'to' and 'from', 'year', and if necessary 'name'. cube = self._make_cube() h.assert_equal(sorted(cube.dimensions), ['from', 'to', 'year']) dataset = cube.dataset dataset['time_axis'] = u'time.from.month' new_default_cube = Cube.configure_default_cube(dataset) h.assert_equal(sorted(new_default_cube.dimensions), ['from', 'month', 'to', 'year'])
def test_fallback_for_missing_entity_name(self): # We use the stringified objectid of an entity as a fallback # value for 'name' h.load_fixture('cube_test_missing_name') ds = model.dataset.find_one() cube = Cube.configure_default_cube(ds) cube.compute() cube_collection = mongo.db[cube.collection_name] h.assert_equal(cube_collection.find().count(), 1) cube_from = cube_collection.find_one()['from'] h.assert_equal(cube_from['name'], str(cube_from['_id']))
def test_fallback_for_missing_entity_name(self): # We use the objectid of an entity as a fallback value for 'name' loader = self._make_loader() loader.create_dimension('name', 'Name', '') loader.create_dimension('label', 'Label', '') loader.create_dimension('from', 'From', '') from_entity = self._make_entity(loader, name="", label='Entity w/o name') entry = {'name': 'Entry', 'label': 'Entry Label', 'from': from_entity, 'time': {'from': {'year': 2009, 'day': 20090101}}} self._make_entry(loader, **entry) cube = Cube.configure_default_cube(loader.dataset) cube.compute() cube_collection = mongo.db()[cube.collection_name] h.assert_equal(cube_collection.find().count(), 1) cube_from = cube_collection.find_one()['from'] h.assert_equal(cube_from['name'], cube_from['_id'])
def _make_cube(self): loader = self._make_loader() loader.create_dimension('name', 'Name', '') loader.create_dimension('label', 'Label', '') loader.create_dimension('from', 'From', '') from_entity_a = self._make_entity(loader, name="a") from_entity_b = self._make_entity(loader, name="b") from_entity_c = self._make_entity(loader, name="c") to_entity_a = self._make_entity(loader, name="a") to_entity_b = self._make_entity(loader, name="b") to_entity_c = self._make_entity(loader, name="c") self._make_entry(loader, **{'name': '_', 'from': from_entity_a, 'to': to_entity_b}) self._make_entry(loader, **{'name': '__', 'from': from_entity_a, 'to': to_entity_b}) self._make_entry(loader, **{'name': '___', 'from': from_entity_b, 'to': to_entity_c}) self._make_entry(loader, **{'name': '____', 'from': from_entity_b, 'to': to_entity_b}) self._make_entry(loader, **{'name': '_____', 'from': from_entity_c, 'to': to_entity_a}) self._make_entry(loader, **{'name': '______', 'from': from_entity_c, 'to': to_entity_b}) cube = Cube.configure_default_cube(loader.dataset) cube.compute() return cube
def compute(self): # TODO: decide if this is a good idea if not find_cube(self.dataset, self.full_dimensions): Cube.define_cube(self.dataset, self.signature, self.full_dimensions)
def test_wont_compute_with_amount(self): h.load_fixture('cube_test_amount') ds = model.dataset.find_one() cube = Cube.configure_default_cube(ds) cube.compute()