def load_space_list_by_dashboard(dashboard, current_user): subject_dict = {} space_dict = {} report_dict = {} space_list = [] if dashboard is not None: # print(dashboard) for dashboard_report in dashboard.reports: report = load_report_by_id(dashboard_report.reportId, current_user) report_dict[report.reportId] = report console_subject = load_console_subject_by_report_id( report.reportId, current_user) subject_dict[console_subject.subjectId] = console_subject console_space = load_console_space_by_subject_id( console_subject.subjectId, current_user) space_dict[console_space.spaceId] = console_space for key, space in space_dict.items(): for subjectId in space.subjectIds: if subjectId in subject_dict: subject = subject_dict[subjectId] for reportId in subject.reportIds: if reportId in report_dict: report = report_dict[reportId] subject.reports.append(report) space.subjects.append(subject) space_list.append(space) return {"dashboard": dashboard, "connectedSpaces": space_list}
def load_chart_dataset_temp(report, current_user): console_subject = load_console_subject_by_report_id( report.reportId, current_user) query = __build_chart_query(report, console_subject, current_user) if query is None or query.get_sql() == "": return [] else: return __load_chart_dataset(query)
def build_query_for_subject_chart(chart_id, report=None): console_subject = load_console_subject_by_report_id(chart_id) columns_dict = column_list_convert_dict(console_subject.dataset.columns) if report is None: report = load_report_by_id(chart_id) if report.chart.type == ChartType.COUNT: q = build_count_query_for_subject_chart(console_subject, columns_dict, report) else: dataset = console_subject.dataset q = _from(dataset.columns[0]) for join in dataset.joins: q = _join(q, join) if dataset.filters: q = _filter(q, dataset.filters) for indicator in report.indicators: q = _indicator(q, indicator, columns_dict.get(indicator.columnId)) truncation = report.chart.settings.get('truncation', None) if truncation is not None: truncation_type = truncation['type'] count = truncation['count'] for dimension in report.dimensions: q = _dimension(q, dimension, columns_dict.get(dimension.columnId)) q = _groupby(q, columns_dict.get(dimension.columnId)) if truncation is not None: if truncation_type == "top": q = _orderby(q, columns_dict.get(dimension.columnId), "asc") if truncation_type == "bottom": q = _orderby(q, columns_dict.get(dimension.columnId), "desc") if truncation_type == "none": q = _orderby(q, columns_dict.get(dimension.columnId), "none") else: q = _orderby(q, columns_dict.get(dimension.columnId), "none") if truncation is not None: q = _limit(q, count) return q
def build_query_for_subject_chart(chart_id, report=None): console_subject = load_console_subject_by_report_id(chart_id) columns_dict = column_list_convert_dict(console_subject.dataset.columns) if report is None: report = load_report_by_id(chart_id) if report.chart.type == ChartType.COUNT: q = build_count_query_for_subject_chart(console_subject, columns_dict, report) else: dataset = console_subject.dataset q = _from(dataset.columns[0]) for join in dataset.joins: q = _join(q, join) if dataset.filters: q = _filter(q, dataset.filters) for indicator in report.indicators: q = _indicator(q, indicator, columns_dict.get(indicator.columnId)) for dimension in report.dimensions: q = _dimension(q, dimension, columns_dict.get(dimension.columnId)) q = _groupby(q, columns_dict.get(dimension.columnId)) q = _orderby(q, columns_dict.get(dimension.columnId)) return q
async def delete_report(report_id, current_user: User = Depends(deps.get_current_user)): subject = load_console_subject_by_report_id(report_id) subject.reportIds.remove(report_id) update_console_subject(subject) delete_report_by_id(report_id)
def build_query_for_chart(chart_id, current_user): console_subject = load_console_subject_by_report_id(chart_id, current_user) report: Report = load_report_by_id(chart_id, current_user) # print(report.dimensions) return __build_chart_query(report, console_subject, current_user)