-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptsensor_custom.py
executable file
·69 lines (51 loc) · 2.35 KB
/
ptsensor_custom.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
# Dont touch this file! This is intended to be a template for implementing new custom checks
from inspect import currentframe
from flask import current_app
from .functions import checkData
def ptsensor(all_dfs):
current_function_name = str(currentframe().f_code.co_name)
# function should be named after the dataset in app.datasets in __init__.py
assert current_function_name in current_app.datasets.keys(), \
f"function {current_function_name} not found in current_app.datasets.keys() - naming convention not followed"
expectedtables = set(current_app.datasets.get(current_function_name).get('tables'))
assert expectedtables.issubset(set(all_dfs.keys())), \
f"""In function {current_function_name} - {expectedtables - set(all_dfs.keys())} not found in keys of all_dfs ({','.join(all_dfs.keys())})"""
# define errors and warnings list
errs = []
warnings = []
# since often times checks are done by merging tables (Paul calls those logic checks)
# we assign dataframes of all_dfs to variables and go from there
# This is the convention that was followed in the old checker
# This data type should only have tbl_example
# example = all_dfs['tbl_example']
# Alter this args dictionary as you add checks and use it for the checkData function
# for errors that apply to multiple columns, separate them with commas
# args = {
# "dataframe": example,
# "tablename": 'tbl_example',
# "badrows": [],
# "badcolumn": "",
# "error_type": "",
# "is_core_error": False,
# "error_message": ""
# }
# Example of appending an error (same logic applies for a warning)
# args.update({
# "badrows": df[df.temperature != 'asdf'].index.tolist(),
# "badcolumn": "temperature",
# "error_type" : "Not asdf",
# "error_message" : "This is a helpful useful message for the user"
# })
# errs = [*errs, checkData(**args)]
# return {'errors': errs, 'warnings': warnings}
ptsensorresults = all_dfs['tbl_ptsensorresults']
ptsensorresults_args = {
"dataframe": ptsensorresults,
"tablename": 'tbl_ptsensorresults',
"badrows": [],
"badcolumn": "",
"error_type": "",
"is_core_error": False,
"error_message": ""
}
return {'errors': errs, 'warnings': warnings}