Last active
December 4, 2025 16:32
-
-
Save mkangia/7d4d6ba2b45febb9ec59bd8ba0b6263a to your computer and use it in GitHub Desktop.
Script to test performance of different charts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import csv | |
| import datetime | |
| import requests | |
| import sys | |
| import logging | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(levelname)s - %(message)s' | |
| ) | |
| BASE_URL = "http://172.30.1.17:8088/" | |
| LOGIN_URL = BASE_URL + "/api/v1/security/login" | |
| EXPLORE_URL = BASE_URL + "api/v1/explore" | |
| CHART_DATA_URL = BASE_URL + "api/v1/chart/data" | |
| CSV_FILE_HEADERS = [ | |
| "Date", "Tool", "Chart ID", "Chart Name", "Execution time (seconds)", | |
| "Rows (In Result)" | |
| ] | |
| # chart ID mapped to the data used in data request | |
| # removing the form_data_key in url_params in queries & form_data which is a cache key | |
| CHART_IDS = { | |
| 3: { | |
| "datasource": { | |
| "id": 3, | |
| "type": "table" | |
| }, | |
| "force": False, | |
| "form_data": { | |
| "adhoc_filters": [], | |
| "all_columns": [ | |
| "province", | |
| "subdistrict", | |
| "hiv_test_result", | |
| "condom_use", | |
| "injecting_drug_use", | |
| "multiple_partners", | |
| "partner_hiv_status", | |
| "sex_for_money" | |
| ], | |
| "allow_render_html": True, | |
| "color_pn": True, | |
| "comparison_color_scheme": "Green", | |
| "datasource": "3__table", | |
| "extra_form_data": {}, | |
| "force": False, | |
| "groupby": [], | |
| "include_time": False, | |
| "order_by_cols": [], | |
| "percent_metrics": [], | |
| "query_mode": "raw", | |
| "result_format": "json", | |
| "result_type": "full", | |
| "row_limit": 1000, | |
| "show_cell_bars": True, | |
| "slice_id": 3, | |
| "table_timestamp_format": "smart_date", | |
| "temporal_columns_lookup": {}, | |
| "url_params": { | |
| "slice_id": "3" | |
| }, | |
| "viz_type": "table" | |
| }, | |
| "queries": [ | |
| { | |
| "annotation_layers": [], | |
| "applied_time_extras": {}, | |
| "columns": [ | |
| "province", | |
| "subdistrict", | |
| "hiv_test_result", | |
| "condom_use", | |
| "injecting_drug_use", | |
| "multiple_partners", | |
| "partner_hiv_status", | |
| "sex_for_money" | |
| ], | |
| "custom_form_data": {}, | |
| "custom_params": {}, | |
| "extras": { | |
| "having": "", | |
| "where": "" | |
| }, | |
| "filters": [], | |
| "order_desc": True, | |
| "orderby": [], | |
| "post_processing": [], | |
| "row_limit": 1000, | |
| "series_limit": 0, | |
| "time_offsets": [], | |
| "url_params": { | |
| "slice_id": "3" | |
| } | |
| } | |
| ], | |
| "result_format": "json", | |
| "result_type": "full" | |
| }, | |
| 4: { | |
| "datasource": { | |
| "id": 4, | |
| "type": "table" | |
| }, | |
| "force": False, | |
| "form_data": { | |
| "adhoc_filters": [], | |
| "all_columns": [ | |
| "province_name", | |
| "subdistrict_name", | |
| "client_id", | |
| "phq9_1_count", | |
| "phq9_2_count", | |
| "phq9_3_count", | |
| "phq9_4_count", | |
| "phq9_5_count", | |
| "phq9_6_count", | |
| "phq9_7_count", | |
| "phq9_8_count", | |
| "phq9_9_count", | |
| "phq9_score", | |
| "depression_severity" | |
| ], | |
| "allow_render_html": True, | |
| "color_pn": True, | |
| "comparison_color_scheme": "Green", | |
| "conditional_formatting": [], | |
| "datasource": "4__table", | |
| "extra_form_data": {}, | |
| "force": False, | |
| "groupby": [], | |
| "include_time": False, | |
| "order_by_cols": [], | |
| "percent_metrics": [], | |
| "query_mode": "raw", | |
| "result_format": "json", | |
| "result_type": "full", | |
| "row_limit": 1000, | |
| "show_cell_bars": True, | |
| "slice_id": 4, | |
| "table_timestamp_format": "smart_date", | |
| "temporal_columns_lookup": {}, | |
| "url_params": { | |
| "slice_id": "4" | |
| }, | |
| "viz_type": "table" | |
| }, | |
| "queries": [ | |
| { | |
| "annotation_layers": [], | |
| "applied_time_extras": {}, | |
| "columns": [ | |
| "province_name", | |
| "subdistrict_name", | |
| "client_id", | |
| "phq9_1_count", | |
| "phq9_2_count", | |
| "phq9_3_count", | |
| "phq9_4_count", | |
| "phq9_5_count", | |
| "phq9_6_count", | |
| "phq9_7_count", | |
| "phq9_8_count", | |
| "phq9_9_count", | |
| "phq9_score", | |
| "depression_severity" | |
| ], | |
| "custom_form_data": {}, | |
| "custom_params": {}, | |
| "extras": { | |
| "having": "", | |
| "where": "" | |
| }, | |
| "filters": [], | |
| "order_desc": True, | |
| "orderby": [], | |
| "post_processing": [], | |
| "row_limit": 1000, | |
| "series_limit": 0, | |
| "time_offsets": [], | |
| "url_params": { | |
| "slice_id": "4" | |
| } | |
| } | |
| ], | |
| "result_format": "json", | |
| "result_type": "full" | |
| }, | |
| 5: { | |
| "datasource": { | |
| "id": 5, | |
| "type": "table" | |
| }, | |
| "force": False, | |
| "form_data": { | |
| "adhoc_filters": [], | |
| "align_pn": True, | |
| "all_columns": [], | |
| "allow_rearrange_columns": False, | |
| "allow_render_html": True, | |
| "color_pn": True, | |
| "comparison_color_scheme": "Green", | |
| "comparison_type": "values", | |
| "conditional_formatting": [], | |
| "datasource": "5__table", | |
| "extra_form_data": {}, | |
| "force": False, | |
| "groupby": [ | |
| "province", | |
| "subdistrict", | |
| "HTN Status: Normal", | |
| "HTN Status: Stage 1", | |
| "HTN Status: Stage 2", | |
| "HTN Status: Elevated", | |
| "Diabetes Status: Normal", | |
| "Diabetes Status: Impaired", | |
| "CVD Risk: Low", | |
| "CVD Risk: Moderate", | |
| "CVD Risk: High", | |
| "CVD Risk: Very High" | |
| ], | |
| "include_search": True, | |
| "metrics": [], | |
| "order_by_cols": [], | |
| "percent_metrics": [], | |
| "query_mode": "aggregate", | |
| "result_format": "json", | |
| "result_type": "full", | |
| "row_limit": 1000, | |
| "show_cell_bars": True, | |
| "show_totals": False, | |
| "slice_id": 5, | |
| "table_timestamp_format": "smart_date", | |
| "temporal_columns_lookup": {}, | |
| "url_params": { | |
| "slice_id": "5" | |
| }, | |
| "viz_type": "table" | |
| }, | |
| "queries": [ | |
| { | |
| "annotation_layers": [], | |
| "applied_time_extras": {}, | |
| "columns": [ | |
| "province", | |
| "subdistrict", | |
| "HTN Status: Normal", | |
| "HTN Status: Stage 1", | |
| "HTN Status: Stage 2", | |
| "HTN Status: Elevated", | |
| "Diabetes Status: Normal", | |
| "Diabetes Status: Impaired", | |
| "CVD Risk: Low", | |
| "CVD Risk: Moderate", | |
| "CVD Risk: High", | |
| "CVD Risk: Very High" | |
| ], | |
| "custom_form_data": {}, | |
| "custom_params": {}, | |
| "extras": { | |
| "having": "", | |
| "where": "" | |
| }, | |
| "filters": [], | |
| "metrics": [], | |
| "order_desc": True, | |
| "orderby": [], | |
| "post_processing": [], | |
| "row_limit": 1000, | |
| "series_limit": 0, | |
| "time_offsets": [], | |
| "url_params": { | |
| "slice_id": "5" | |
| } | |
| } | |
| ], | |
| "result_format": "json", | |
| "result_type": "full" | |
| }, | |
| 6: { | |
| "datasource": { | |
| "id": 7, | |
| "type": "table" | |
| }, | |
| "force": False, | |
| "form_data": { | |
| "adhoc_filters": [], | |
| "all_columns": [], | |
| "allow_render_html": True, | |
| "color_pn": True, | |
| "comparison_color_scheme": "Green", | |
| "comparison_type": "values", | |
| "conditional_formatting": [], | |
| "datasource": "7__table", | |
| "extra_form_data": {}, | |
| "force": False, | |
| "groupby": [ | |
| "province_name", | |
| "subdistrict_name", | |
| "facility", | |
| "Number of services rendered" | |
| ], | |
| "include_search": True, | |
| "order_by_cols": [], | |
| "percent_metrics": [], | |
| "query_mode": "aggregate", | |
| "result_format": "json", | |
| "result_type": "full", | |
| "row_limit": 1000, | |
| "show_cell_bars": True, | |
| "slice_id": 6, | |
| "table_timestamp_format": "smart_date", | |
| "temporal_columns_lookup": {}, | |
| "url_params": { | |
| "slice_id": "6" | |
| }, | |
| "viz_type": "table" | |
| }, | |
| "queries": [ | |
| { | |
| "annotation_layers": [], | |
| "applied_time_extras": {}, | |
| "columns": [ | |
| "province_name", | |
| "subdistrict_name", | |
| "facility", | |
| "Number of services rendered" | |
| ], | |
| "custom_form_data": {}, | |
| "custom_params": {}, | |
| "extras": { | |
| "having": "", | |
| "where": "" | |
| }, | |
| "filters": [], | |
| "metrics": [], | |
| "order_desc": True, | |
| "orderby": [], | |
| "post_processing": [], | |
| "row_limit": 1000, | |
| "series_limit": 0, | |
| "time_offsets": [], | |
| "url_params": { | |
| "slice_id": "6" | |
| } | |
| } | |
| ], | |
| "result_format": "json", | |
| "result_type": "full" | |
| }, | |
| 7: { | |
| "datasource": { | |
| "id": 8, | |
| "type": "table" | |
| }, | |
| "force": False, | |
| "form_data": { | |
| "adhoc_filters": [], | |
| "all_columns": [ | |
| "province", | |
| "subdistrict", | |
| "client_type", | |
| "gender_female", | |
| "gender_male" | |
| ], | |
| "allow_render_html": True, | |
| "color_pn": True, | |
| "comparison_color_scheme": "Green", | |
| "datasource": "8__table", | |
| "extra_form_data": {}, | |
| "force": False, | |
| "groupby": [], | |
| "include_time": False, | |
| "order_by_cols": [], | |
| "percent_metrics": [], | |
| "query_mode": "raw", | |
| "result_format": "json", | |
| "result_type": "full", | |
| "row_limit": 1000, | |
| "show_cell_bars": True, | |
| "slice_id": 7, | |
| "table_timestamp_format": "smart_date", | |
| "temporal_columns_lookup": {}, | |
| "url_params": { | |
| "slice_id": "7" | |
| }, | |
| "viz_type": "table" | |
| }, | |
| "queries": [ | |
| { | |
| "annotation_layers": [], | |
| "applied_time_extras": {}, | |
| "columns": [ | |
| "province", | |
| "subdistrict", | |
| "client_type", | |
| "gender_female", | |
| "gender_male" | |
| ], | |
| "custom_form_data": {}, | |
| "custom_params": {}, | |
| "extras": { | |
| "having": "", | |
| "where": "" | |
| }, | |
| "filters": [], | |
| "order_desc": True, | |
| "orderby": [], | |
| "post_processing": [], | |
| "row_limit": 1000, | |
| "series_limit": 0, | |
| "time_offsets": [], | |
| "url_params": { | |
| "slice_id": "7" | |
| } | |
| } | |
| ], | |
| "result_format": "json", | |
| "result_type": "full" | |
| }, | |
| 8: { | |
| "datasource": { | |
| "id": 9, | |
| "type": "table" | |
| }, | |
| "force": False, | |
| "form_data": { | |
| "adhoc_filters": [], | |
| "all_columns": [], | |
| "allow_render_html": True, | |
| "color_pn": True, | |
| "comparison_color_scheme": "Green", | |
| "comparison_type": "values", | |
| "datasource": "9__table", | |
| "extra_form_data": {}, | |
| "force": False, | |
| "groupby": [ | |
| "Province", | |
| "Subdistrict", | |
| "Client Id", | |
| "Age", | |
| "LMP Date", | |
| "LMP Date: Ethiopian", | |
| "EDD Date", | |
| "EDD Date Ethiopian", | |
| "ANC Visit Count", | |
| "ANC 1 Ultrasound Done", | |
| "ANC 1 Diastolic BP", | |
| "ANC Visit 1 Systolic BP", | |
| "ANC 1 Weight", | |
| "ANC 1 Visit Date", | |
| "ANC 1 Visit Date Ethiopian", | |
| "ANC 2 Ultrasound Done", | |
| "ANC 2 Diastolic BP", | |
| "ANC 2 Systolic BP", | |
| "ANC 2 Weight", | |
| "ANC 2 Visit Date", | |
| "ANC 2 Visit Date Ethiopian", | |
| "ANC 3 Ultrasound Done", | |
| "ANC 3 Diastolic BP", | |
| "ANC 3 Systolic BP", | |
| "ANC 3 Weight", | |
| "ANC 3 Visit Date", | |
| "ANC 3 Visit Date Ethiopian", | |
| "ANC 4 Ultrasound Done", | |
| "ANC 4 Diastolic BP", | |
| "ANC 4 Systolic BP", | |
| "ANC 4 Weight", | |
| "ANC 4 Visit Date", | |
| "ANC 4 Visit Date Ethiopian", | |
| "Pregnancy Risk: BP" | |
| ], | |
| "order_by_cols": [], | |
| "percent_metrics": [], | |
| "query_mode": "aggregate", | |
| "result_format": "json", | |
| "result_type": "full", | |
| "row_limit": 1000, | |
| "show_cell_bars": True, | |
| "slice_id": 8, | |
| "table_timestamp_format": "smart_date", | |
| "temporal_columns_lookup": {}, | |
| "url_params": { | |
| "slice_id": "8" | |
| }, | |
| "viz_type": "table" | |
| }, | |
| "queries": [ | |
| { | |
| "annotation_layers": [], | |
| "applied_time_extras": {}, | |
| "columns": [ | |
| "Province", | |
| "Subdistrict", | |
| "Client Id", | |
| "Age", | |
| "LMP Date", | |
| "LMP Date: Ethiopian", | |
| "EDD Date", | |
| "EDD Date Ethiopian", | |
| "ANC Visit Count", | |
| "ANC 1 Ultrasound Done", | |
| "ANC 1 Diastolic BP", | |
| "ANC Visit 1 Systolic BP", | |
| "ANC 1 Weight", | |
| "ANC 1 Visit Date", | |
| "ANC 1 Visit Date Ethiopian", | |
| "ANC 2 Ultrasound Done", | |
| "ANC 2 Diastolic BP", | |
| "ANC 2 Systolic BP", | |
| "ANC 2 Weight", | |
| "ANC 2 Visit Date", | |
| "ANC 2 Visit Date Ethiopian", | |
| "ANC 3 Ultrasound Done", | |
| "ANC 3 Diastolic BP", | |
| "ANC 3 Systolic BP", | |
| "ANC 3 Weight", | |
| "ANC 3 Visit Date", | |
| "ANC 3 Visit Date Ethiopian", | |
| "ANC 4 Ultrasound Done", | |
| "ANC 4 Diastolic BP", | |
| "ANC 4 Systolic BP", | |
| "ANC 4 Weight", | |
| "ANC 4 Visit Date", | |
| "ANC 4 Visit Date Ethiopian", | |
| "Pregnancy Risk: BP" | |
| ], | |
| "custom_form_data": {}, | |
| "custom_params": {}, | |
| "extras": { | |
| "having": "", | |
| "where": "" | |
| }, | |
| "filters": [], | |
| "metrics": [], | |
| "order_desc": True, | |
| "orderby": [], | |
| "post_processing": [], | |
| "row_limit": 1000, | |
| "series_limit": 0, | |
| "time_offsets": [], | |
| "url_params": { | |
| "slice_id": "8" | |
| } | |
| } | |
| ], | |
| "result_format": "json", | |
| "result_type": "full" | |
| }, | |
| 9: { | |
| "datasource": { | |
| "id": 3, | |
| "type": "table" | |
| }, | |
| "force": False, | |
| "form_data": { | |
| "adhoc_filters": [], | |
| "annotation_layers": [], | |
| "color_scheme": "supersetColors", | |
| "contributionMode": None, | |
| "datasource": "3__table", | |
| "extra_form_data": {}, | |
| "force": False, | |
| "groupby": [], | |
| "legendOrientation": "top", | |
| "legendType": "scroll", | |
| "metrics": [ | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "hiv_test_result", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 132, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "HIV Positive", | |
| "optionName": "metric_bo4ox8mb5g8_at53wa6duu7", | |
| "sqlExpression": None | |
| }, | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "partner_hiv_status", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 136, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "Condom Use", | |
| "optionName": "metric_yjfux6pfd1f_ntjd6mp27ah", | |
| "sqlExpression": None | |
| }, | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "condom_use", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 133, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "Imjecting Drug Use", | |
| "optionName": "metric_wwkk8qa48f_blwa5okav8u", | |
| "sqlExpression": None | |
| }, | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "injecting_drug_use", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 134, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "Multiple Partners", | |
| "optionName": "metric_2foq61wvq3v_len487sokp", | |
| "sqlExpression": None | |
| }, | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "multiple_partners", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 135, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": False, | |
| "label": "SUM(multiple_partners)", | |
| "optionName": "metric_ojtcisrqa6n_qt3o6smonn", | |
| "sqlExpression": None | |
| }, | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "sex_for_money", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 137, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "Sex for Money", | |
| "optionName": "metric_8h1umxuofui_b6cg9glvpim", | |
| "sqlExpression": None | |
| } | |
| ], | |
| "only_total": True, | |
| "orientation": "vertical", | |
| "result_format": "json", | |
| "result_type": "full", | |
| "rich_tooltip": True, | |
| "row_limit": 1000, | |
| "show_empty_columns": False, | |
| "show_legend": True, | |
| "show_value": False, | |
| "showTooltipTotal": True, | |
| "slice_id": 9, | |
| "sort_series_type": "sum", | |
| "time_shift_color": True, | |
| "tooltipTimeFormat": "smart_date", | |
| "truncate_metric": False, | |
| "truncateXAxis": True, | |
| "url_params": { | |
| "slice_id": "9" | |
| }, | |
| "viz_type": "echarts_timeseries_bar", | |
| "x_axis": "province", | |
| "x_axis_sort_series": "name", | |
| "x_axis_sort_series_ascending": True, | |
| "x_axis_time_format": "smart_date", | |
| "x_axis_title_margin": 15, | |
| "y_axis_bounds": [ | |
| None, | |
| None | |
| ], | |
| "y_axis_format": "SMART_NUMBER", | |
| "y_axis_title_margin": 30, | |
| "y_axis_title_position": "Left", | |
| "zoomable": True | |
| }, | |
| "queries": [ | |
| { | |
| "annotation_layers": [], | |
| "applied_time_extras": {}, | |
| "columns": [ | |
| { | |
| "columnType": "BASE_AXIS", | |
| "expressionType": "SQL", | |
| "label": "province", | |
| "sqlExpression": "province" | |
| } | |
| ], | |
| "custom_form_data": {}, | |
| "custom_params": {}, | |
| "extras": { | |
| "having": "", | |
| "where": "" | |
| }, | |
| "filters": [], | |
| "metrics": [ | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "hiv_test_result", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 132, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "HIV Positive", | |
| "optionName": "metric_bo4ox8mb5g8_at53wa6duu7", | |
| "sqlExpression": None | |
| }, | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "partner_hiv_status", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 136, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "Condom Use", | |
| "optionName": "metric_yjfux6pfd1f_ntjd6mp27ah", | |
| "sqlExpression": None | |
| }, | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "condom_use", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 133, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "Imjecting Drug Use", | |
| "optionName": "metric_wwkk8qa48f_blwa5okav8u", | |
| "sqlExpression": None | |
| }, | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "injecting_drug_use", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 134, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "Multiple Partners", | |
| "optionName": "metric_2foq61wvq3v_len487sokp", | |
| "sqlExpression": None | |
| }, | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "multiple_partners", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 135, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": False, | |
| "label": "SUM(multiple_partners)", | |
| "optionName": "metric_ojtcisrqa6n_qt3o6smonn", | |
| "sqlExpression": None | |
| }, | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "sex_for_money", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 137, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "Sex for Money", | |
| "optionName": "metric_8h1umxuofui_b6cg9glvpim", | |
| "sqlExpression": None | |
| } | |
| ], | |
| "order_desc": True, | |
| "orderby": [ | |
| [ | |
| { | |
| "aggregate": "SUM", | |
| "column": { | |
| "advanced_data_type": None, | |
| "certification_details": None, | |
| "certified_by": None, | |
| "column_name": "hiv_test_result", | |
| "description": None, | |
| "expression": None, | |
| "filterable": True, | |
| "groupby": True, | |
| "id": 132, | |
| "is_certified": False, | |
| "is_dttm": False, | |
| "python_date_format": None, | |
| "type": "LONGINTEGER", | |
| "type_generic": 0, | |
| "verbose_name": None, | |
| "warning_markdown": None | |
| }, | |
| "datasourceWarning": False, | |
| "expressionType": "SIMPLE", | |
| "hasCustomLabel": True, | |
| "label": "HIV Positive", | |
| "optionName": "metric_bo4ox8mb5g8_at53wa6duu7", | |
| "sqlExpression": None | |
| }, | |
| False | |
| ] | |
| ], | |
| "post_processing": [ | |
| { | |
| "operation": "pivot", | |
| "options": { | |
| "aggregates": { | |
| "Condom Use": { | |
| "operator": "mean" | |
| }, | |
| "HIV Positive": { | |
| "operator": "mean" | |
| }, | |
| "Imjecting Drug Use": { | |
| "operator": "mean" | |
| }, | |
| "Multiple Partners": { | |
| "operator": "mean" | |
| }, | |
| "Sex for Money": { | |
| "operator": "mean" | |
| }, | |
| "SUM(multiple_partners)": { | |
| "operator": "mean" | |
| } | |
| }, | |
| "columns": [], | |
| "drop_missing_columns": True, | |
| "index": [ | |
| "province" | |
| ] | |
| } | |
| }, | |
| { | |
| "operation": "flatten" | |
| } | |
| ], | |
| "row_limit": 1000, | |
| "series_columns": [], | |
| "series_limit": 0, | |
| "time_offsets": [], | |
| "url_params": { | |
| "slice_id": "9" | |
| } | |
| } | |
| ], | |
| "result_format": "json", | |
| "result_type": "full" | |
| }, | |
| 11: { | |
| "datasource": { | |
| "id": 10, | |
| "type": "table" | |
| }, | |
| "force": False, | |
| "form_data": { | |
| "adhoc_filters": [], | |
| "all_columns": [], | |
| "allow_render_html": True, | |
| "color_pn": True, | |
| "comparison_color_scheme": "Green", | |
| "comparison_type": "values", | |
| "datasource": "10__table", | |
| "extra_form_data": {}, | |
| "force": False, | |
| "groupby": [ | |
| "Province", | |
| "Subdistrict", | |
| "Facility", | |
| "# Female", | |
| "# Male", | |
| " # HTN Status: Normal", | |
| " # HTN Status: Stage 1", | |
| "# HTN Status: Stage 2", | |
| "# HTN Status: Elevated", | |
| "# Diabetes Status: Impaired", | |
| "# CVD Risk: Low", | |
| "# CVD Risk: Moderate", | |
| "# CVD Risk: High", | |
| " # Ever Tested for HIV", | |
| "# HIV Positive (Latest)", | |
| "# TB Symptoms (any)", | |
| "# TB Symptom: Night Sweats", | |
| "# TB Symptom: Cough", | |
| "# TB Symptom: Fever", | |
| "# TB Symptom: Weight Loss", | |
| "# Smoker (flag)", | |
| "# Family History: HTN", | |
| "# Family History: Diabetes", | |
| "# Family History: CVD" | |
| ], | |
| "order_by_cols": [], | |
| "percent_metrics": [], | |
| "query_mode": "aggregate", | |
| "result_format": "json", | |
| "result_type": "full", | |
| "row_limit": 1000, | |
| "show_cell_bars": True, | |
| "slice_id": 11, | |
| "table_timestamp_format": "smart_date", | |
| "temporal_columns_lookup": {}, | |
| "url_params": { | |
| "slice_id": "11" | |
| }, | |
| "viz_type": "table" | |
| }, | |
| "queries": [ | |
| { | |
| "annotation_layers": [], | |
| "applied_time_extras": {}, | |
| "columns": [ | |
| "Province", | |
| "Subdistrict", | |
| "Facility", | |
| "# Female", | |
| "# Male", | |
| " # HTN Status: Normal", | |
| " # HTN Status: Stage 1", | |
| "# HTN Status: Stage 2", | |
| "# HTN Status: Elevated", | |
| "# Diabetes Status: Impaired", | |
| "# CVD Risk: Low", | |
| "# CVD Risk: Moderate", | |
| "# CVD Risk: High", | |
| " # Ever Tested for HIV", | |
| "# HIV Positive (Latest)", | |
| "# TB Symptoms (any)", | |
| "# TB Symptom: Night Sweats", | |
| "# TB Symptom: Cough", | |
| "# TB Symptom: Fever", | |
| "# TB Symptom: Weight Loss", | |
| "# Smoker (flag)", | |
| "# Family History: HTN", | |
| "# Family History: Diabetes", | |
| "# Family History: CVD" | |
| ], | |
| "custom_form_data": {}, | |
| "custom_params": {}, | |
| "extras": { | |
| "having": "", | |
| "where": "" | |
| }, | |
| "filters": [], | |
| "metrics": [], | |
| "order_desc": True, | |
| "orderby": [], | |
| "post_processing": [], | |
| "row_limit": 1000, | |
| "series_limit": 0, | |
| "time_offsets": [], | |
| "url_params": { | |
| "slice_id": "11" | |
| } | |
| } | |
| ], | |
| "result_format": "json", | |
| "result_type": "full" | |
| } | |
| } | |
| login_data = { | |
| "username": "[email protected]", | |
| "password": "password", | |
| "provider": "db", | |
| "refresh": True | |
| } | |
| def login(): | |
| return requests.post(LOGIN_URL, json=login_data) | |
| login_response = login() | |
| logging.debug(login_response.json()) | |
| access_token = login_response.json()["access_token"] | |
| headers = {"Authorization": f"Bearer {access_token}"} | |
| def get_chart_explore_info(chart_id): | |
| return requests.get(EXPLORE_URL, params={"slice_id": chart_id}, headers=headers) | |
| def get_chart_data(chart_id): | |
| return requests.post(CHART_DATA_URL, headers=headers, json=CHART_IDS[chart_id]) | |
| def run(): | |
| csv_file_name = f'superset-chart-performance-{datetime.datetime.now()}.csv' | |
| with open(f"/home/ubuntu/superset/superset_performance/files/{csv_file_name}", 'w', newline='') as csv_file: | |
| csv_file_writer = csv.writer(csv_file) | |
| csv_file_writer.writerow(CSV_FILE_HEADERS) | |
| for chart_id in CHART_IDS: | |
| logging.info(f"Getting metadata for chart ID: {chart_id}") | |
| chart_explore_info = get_chart_explore_info(chart_id).json() | |
| chart_name = chart_explore_info['result']['slice']['slice_name'] | |
| logging.info(f"Chart name: {chart_name}") | |
| logging.info(f"Getting chart data for chart ID: {chart_id}") | |
| chart_data_response = get_chart_data(chart_id) | |
| chart_data = chart_data_response.json() | |
| # logging.debug(chart_data) # too noisy so uncomment if really needed | |
| number_of_rows = chart_data['result'][0]['rowcount'] | |
| time_taken = chart_data_response.elapsed.total_seconds() | |
| logging.info(f"Fetched {number_of_rows} rows in {time_taken} seconds") | |
| csv_file_writer.writerow([ | |
| datetime.date.today(),'superset',chart_id,chart_name,time_taken,number_of_rows | |
| ]) | |
| run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment