forked from tl-its-umich-edu/unizin-validation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbqueries.py
75 lines (55 loc) · 1.82 KB
/
dbqueries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Standard modules
from datetime import datetime, timezone
from typing import Callable, Literal, TypedDict, Union
# Local modules
from data_sources import DataSourceName
# Types
class CheckData(TypedDict):
color: Literal['YELLOW', 'RED']
condition: Union[Callable[[str], bool], Callable[[int], bool]]
rows_to_ignore: list[str]
class QueryData(TypedDict):
output_file_name: str
data_source: DataSourceName
query_name: str
checks: dict[str, CheckData]
class StandardQueryData(QueryData):
type: Literal['standard']
query: str
class TableRecordCountsQueryData(QueryData):
type: Literal['table_record_counts']
tables: list[str]
class QueryDict(TypedDict):
udp_context_store_view_counts: TableRecordCountsQueryData
QueryName = Literal[
'udp_context_store_view_counts'
]
# Check functions
NOT_ZERO: Callable[[int], bool] = (lambda x: x != 0)
LESS_THAN_TWO: Callable[[int], bool] = (lambda x: x < 2)
LESS_THAN_TWO_DAYS: Callable[[str], bool] = (lambda x: (datetime.now(tz=timezone.utc) - datetime.fromisoformat(x)).days < 2)
# Queries configuration
QUERIES: QueryDict = {
'udp_context_store_view_counts': {
'output_file_name': 'udp_context_store_view_counts.csv',
'data_source': 'UDP_Context_Store',
'query_name': 'UDP Context Store View Record Counts',
'type': 'table_record_counts',
'tables': [
'entity.learner_activity',
'entity.course_offering',
'entity.course_grade',
'entity.academic_term',
'entity.annotation',
'entity.learner_activity_result',
'entity.person',
],
'checks': {
'not_zero': {
'color': 'YELLOW',
'condition': NOT_ZERO,
'rows_to_ignore': []
}
}
}
}