def _create_unicode_dashboard(slice_title: str, position: str) -> Dashboard: table = create_table_metadata(UNICODE_TBL_NAME, get_example_database()) table.fetch_metadata() if slice_title: slice = _create_and_commit_unicode_slice(table, slice_title) return create_dashboard("unicode-test", "Unicode Test", position, [slice])
def create_dashboard_for_loaded_data(): with app.app_context(): table = create_table_metadata(WB_HEALTH_POPULATION, get_example_database()) slices = _create_world_bank_slices(table) dash = _create_world_bank_dashboard(table, slices) slices_ids_to_delete = [slice.id for slice in slices] dash_id_to_delete = dash.id return dash_id_to_delete, slices_ids_to_delete
def _create_table( table_name: str, database: "Database", fetch_values_predicate: Optional[str] = None, ): table = create_table_metadata( table_name=table_name, database=database, fetch_values_predicate=fetch_values_predicate, ) from superset.examples.birth_names import _add_table_metrics, _set_table_metadata _set_table_metadata(table, database) _add_table_metrics(table) db.session.commit() return table
def _create_energy_table(): table = create_table_metadata( table_name=ENERGY_USAGE_TBL_NAME, database=get_example_database(), table_description="Energy consumption", ) table.fetch_metadata() if not any(col.metric_name == "sum__value" for col in table.metrics): col = str(column("value").compile(db.engine)) table.metrics.append( SqlMetric(metric_name="sum__value", expression=f"SUM({col})")) db.session.merge(table) db.session.commit() table.fetch_metadata() for slice_data in _get_energy_slices(): _create_and_commit_energy_slice( table, slice_data["slice_title"], slice_data["viz_type"], slice_data["params"], )