Skip to content

Commit e1d8d17

Browse files
authored
Merge pull request #1060 from saraburns1/in_context_upadtes_423
feat: Updates to In-Context analytics dashboards
2 parents 59bc5dd + f95c351 commit e1d8d17

30 files changed

+826
-784
lines changed

tutoraspects/asset_command_helpers.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
"openedx-assets",
3333
"assets",
3434
)
35+
QUERIES_PATH = os.path.join(
36+
os.path.dirname(os.path.abspath(__file__)), "templates", "openedx-assets", "queries"
37+
)
3538

3639

3740
def str_presenter(dumper, data):
@@ -595,3 +598,42 @@ def delete_aspects_unused_assets(echo):
595598
for asset_type, uuids in unused_uuids.items():
596599
for uuid, data in uuids.items():
597600
echo(f'{asset_type} {data.get("name")} (UUID: {uuid})')
601+
602+
603+
def find_unused_queries(echo):
604+
"""
605+
Compare all sql files in openedx-assets/queries to the file names referenced
606+
in each dataset's yaml. List any .sql files that are not referenced as
607+
possible unused queries. Ignore any sql files listed in `aspects_asset_list`
608+
under ignored_files.
609+
"""
610+
dataset_query_list = []
611+
for query_file in glob.iglob(QUERIES_PATH + "/*.sql", recursive=True):
612+
match = re.search(r"\w+\b.sql", query_file)
613+
if match:
614+
dataset_query_list.append(match.group())
615+
616+
for file_name in glob.iglob(ASSETS_PATH + "/datasets/*.yaml", recursive=True):
617+
with open(file_name, "r", encoding="utf-8") as file:
618+
# We have to remove the jinja for it to parse
619+
file_str = file.read()
620+
file_str = file_str.replace("{{", "").replace("}}", "")
621+
asset = yaml.safe_load(file_str)
622+
sql = asset["sql"].strip()
623+
match = re.search(r"\w+\b.sql", sql)
624+
if match:
625+
dataset_query_list.remove(match.group())
626+
627+
# Remove uuids from 'all' list that are in ignored yaml
628+
with open(ASPECT_ASSET_LIST, "r", encoding="utf-8") as file:
629+
aspects_assets = yaml.safe_load(file)
630+
631+
ignored_uuids = aspects_assets.get("ignored_files")
632+
if ignored_uuids["queries"]:
633+
for file_name in ignored_uuids["queries"]:
634+
dataset_query_list.remove(file_name)
635+
636+
if dataset_query_list:
637+
echo(click.style("Potentially unused query files detected:"))
638+
for file in dataset_query_list:
639+
echo(f"{file}")

tutoraspects/commands_v1.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
deduplicate_superset_assets,
1515
import_superset_assets,
1616
delete_aspects_unused_assets,
17+
find_unused_queries,
1718
)
1819

1920

@@ -366,6 +367,7 @@ def serialize_zip(file, base_assets_path):
366367
click.echo()
367368
deduplicate_superset_assets(click.echo)
368369
delete_aspects_unused_assets(click.echo)
370+
find_unused_queries(click.echo)
369371

370372
click.echo()
371373
click.echo("Asset merge complete!")
@@ -385,6 +387,7 @@ def check_superset_assets():
385387
"""
386388
deduplicate_superset_assets(click.echo)
387389
delete_aspects_unused_assets(click.echo)
390+
find_unused_queries(click.echo)
388391

389392
click.echo()
390393
click.echo(

tutoraspects/templates/aspects/apps/superset/pythonpath/aspects_asset_list.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ ignored_uuids:
1818
datasets:
1919
charts:
2020
- bb13bb31-c797-4ed3-a7f9-7825cc6dc482 # "Query performance" needed for the performance_metrics script
21+
22+
ignored_files:
23+
queries:
24+
# These queries are used in other query files
25+
- user_filters.sql
26+
- common_filters.sql
27+
- at_risk_learner_filter.sql

tutoraspects/templates/aspects/build/aspects-superset/openedx-assets/assets/charts/Final_Response_Results_ab43eb.yaml

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@ certified_by: null
55
dataset_uuid: e6134213-e7f4-4081-9861-356c93f376dc
66
description: null
77
params:
8-
adhoc_filters:
9-
- clause: WHERE
10-
comparator: No filter
11-
expressionType: SIMPLE
12-
operator: TEMPORAL_RANGE
13-
subject: emission_time
8+
adhoc_filters: []
149
annotation_layers: []
15-
color_scheme: supersetColors
10+
color_scheme: aspects_default
1611
extra_form_data: {}
1712
groupby:
18-
- datasourceWarning: false
13+
- datasourceWarning: true
1914
expressionType: SQL
2015
label: success
2116
sqlExpression: |-
@@ -55,47 +50,43 @@ params:
5550
rich_tooltip: true
5651
row_limit: 10000
5752
show_empty_columns: true
58-
show_legend: true
53+
show_legend: false
5954
sort_series_type: sum
6055
stack: Stack
6156
tooltipTimeFormat: smart_date
6257
truncateXAxis: false
6358
truncateYAxis: false
6459
truncate_metric: true
6560
viz_type: echarts_timeseries_bar
66-
x_axis: problem_name
61+
x_axis: subsection_number
6762
x_axis_sort_series: name
6863
x_axis_sort_series_ascending: true
6964
x_axis_time_format: smart_date
70-
x_axis_title_margin: 15
65+
x_axis_title: Subsection
66+
x_axis_title_margin: 30
7167
y_axis_bounds:
7268
- null
7369
- null
7470
y_axis_format: SMART_NUMBER
7571
y_axis_title: Respondents
76-
y_axis_title_margin: 30
77-
y_axis_title_position: Left
72+
y_axis_title_margin: 15
73+
y_axis_title_position: Top
7874
query_context:
7975
datasource:
80-
id: 725
76+
id: 644
8177
type: table
8278
force: false
8379
form_data:
84-
adhoc_filters:
85-
- clause: WHERE
86-
comparator: No filter
87-
expressionType: SIMPLE
88-
operator: TEMPORAL_RANGE
89-
subject: emission_time
80+
adhoc_filters: []
9081
annotation_layers: []
91-
color_scheme: supersetColors
82+
color_scheme: aspects_default
9283
dashboards:
93-
- 124
94-
datasource: 725__table
84+
- 4741
85+
datasource: 644__table
9586
extra_form_data: {}
9687
force: false
9788
groupby:
98-
- datasourceWarning: false
89+
- datasourceWarning: true
9990
expressionType: SQL
10091
label: success
10192
sqlExpression: |-
@@ -137,36 +128,37 @@ query_context:
137128
rich_tooltip: true
138129
row_limit: 10000
139130
show_empty_columns: true
140-
show_legend: true
141-
slice_id: 1670
131+
show_legend: false
132+
slice_id: 1341
142133
sort_series_type: sum
143134
stack: Stack
144135
tooltipTimeFormat: smart_date
145136
truncateXAxis: false
146137
truncateYAxis: false
147138
truncate_metric: true
148139
viz_type: echarts_timeseries_bar
149-
x_axis: problem_name
140+
x_axis: subsection_number
150141
x_axis_sort_series: name
151142
x_axis_sort_series_ascending: true
152143
x_axis_time_format: smart_date
153-
x_axis_title_margin: 15
144+
x_axis_title: Subsection
145+
x_axis_title_margin: 30
154146
y_axis_bounds:
155147
- null
156148
- null
157149
y_axis_format: SMART_NUMBER
158150
y_axis_title: Respondents
159-
y_axis_title_margin: 30
160-
y_axis_title_position: Left
151+
y_axis_title_margin: 15
152+
y_axis_title_position: Top
161153
queries:
162154
- annotation_layers: []
163155
applied_time_extras: {}
164156
columns:
165157
- columnType: BASE_AXIS
166158
expressionType: SQL
167-
label: problem_name
168-
sqlExpression: problem_name
169-
- datasourceWarning: false
159+
label: subsection_number
160+
sqlExpression: subsection_number
161+
- datasourceWarning: true
170162
expressionType: SQL
171163
label: success
172164
sqlExpression: |-
@@ -176,10 +168,7 @@ query_context:
176168
extras:
177169
having: ''
178170
where: ''
179-
filters:
180-
- col: emission_time
181-
op: TEMPORAL_RANGE
182-
val: No filter
171+
filters: []
183172
metrics:
184173
- aggregate: COUNT_DISTINCT
185174
column:
@@ -244,7 +233,7 @@ query_context:
244233
- success
245234
drop_missing_columns: false
246235
index:
247-
- problem_name
236+
- subsection_number
248237
- operation: rename
249238
options:
250239
columns:
@@ -254,7 +243,7 @@ query_context:
254243
- operation: flatten
255244
row_limit: 10000
256245
series_columns:
257-
- datasourceWarning: false
246+
- datasourceWarning: true
258247
expressionType: SQL
259248
label: success
260249
sqlExpression: |-

0 commit comments

Comments
 (0)