Skip to content

Commit 301fe2f

Browse files
authored
Merge pull request #1751 from cmu-delphi/flash_eval
Revised: Basic FlaSH Implementation
2 parents ac10f61 + b5c9c93 commit 301fe2f

File tree

137 files changed

+190024
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+190024
-11
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# FlaSH System
2+
3+
THIS README IS IN PROGRESS
4+
5+
FlaSH is a real-time point-outlier detection system. We add the daily evaluation step to this indicators package (retraining is done offline).
6+
7+
FlaSH produces a list of data points that are unusual or surprising so that stakeholders are aware of points that warrant further inspection.
8+
9+
The guiding principles for the system are:
10+
- Flag relevant data points as soon as possible (ideally in an online setting)
11+
- Be aware of the false positive/false negative rates
12+
- Reduce cognitive load on data evaluators
13+
14+
Types of outliers/changes FlaSH intends to catch are:
15+
- Out-of-range points
16+
- Large spikes
17+
- Points that are interesting for a particular weekday
18+
- Points that are interesting with respect to a particular stream's history
19+
- Points that are interesting with respect to all other streams
20+
- Change in data reporting schedule
21+
- Changes in health condition [ex: new variant]
22+
23+
## Running FlaSH-eval
24+
25+
First, run the indicator so that there are files for FlaSH to check.
26+
27+
You can excecute the Python module contained in this
28+
directory from the main directory of the indicator of interest.
29+
30+
The safest way to do this is to create a virtual environment,
31+
and install the common DELPHI tools, including flash, and the
32+
flash module and its dependencies to the virtual environment.
33+
34+
To do this, navigate to the main directory of the indicator of interest and run the following code:
35+
36+
```
37+
python -m venv env
38+
source env/bin/activate
39+
pip install ../_delphi_utils_python/.
40+
pip install .
41+
```
42+
43+
To execute the module run the indicator to generate data files and then run
44+
the flash system , as follows:
45+
46+
```
47+
env/bin/python -m delphi_INDICATORNAME
48+
env/bin/python -m delphi_utils.flash_eval
49+
50+
```
51+
52+
Once you are finished with the code, you can deactivate the virtual environment
53+
and (optionally) remove the environment itself.
54+
55+
```
56+
deactivate
57+
rm -r env
58+
```
59+
60+
### Customization
61+
62+
All of the user-changable parameters are stored in the `flash` field of the indicator's `params.json` file. If `params.json` does not already include a `flash` field, please copy that provided in this module's `params.json.template`.
63+
64+
Please update the follow settings:
65+
- signals: a list of which signals for that indicator go through FlaSH.
66+
67+
## Testing the code
68+
69+
To test the code, please create a new virtual environment in the main module directory using the following procedure, similar to above:
70+
71+
```
72+
make install
73+
```
74+
75+
To do a static test of the code style, it is recommended to run **pylint** on
76+
the module. To do this, run the following from the main module directory:
77+
78+
```
79+
make lint
80+
```
81+
82+
The most aggressive checks are turned off; only relatively important issues
83+
should be raised and they should be manually checked (or better, fixed).
84+
85+
Unit tests are also included in the module. To execute these, run the following command from this directory:
86+
87+
```
88+
make test
89+
```
90+
91+
or
92+
93+
```
94+
(cd tests && ../env/bin/pytest test_file.py --cov=delphi_utils --cov-report=term-missing)
95+
```
96+
97+
The output will show the number of unit tests that passed and failed, along with the percentage of code covered by the tests. None of the tests should fail and the code lines that are not covered by unit tests should be small and should not include critical sub-routines.
98+
99+
100+
## Adding checks
101+
102+
To add a new validation check. Each check should append a descriptive error message to the `raised` attribute if triggered. All checks should allow the user to override exception raising for a specific file using the `suppressed_errors` setting in `params.json`.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Code Review (Python)
2+
3+
A code review of this module should include a careful look at the code and the
4+
output. To assist in the process, but certainly not in replace of it, please
5+
check the following items.
6+
7+
**Documentation**
8+
9+
- [] the README.md file template is filled out and currently accurate; it is
10+
possible to load and test the code using only the instructions given
11+
- [] minimal docstrings (one line describing what the function does) are
12+
included for all functions; full docstrings describing the inputs and expected
13+
outputs should be given for non-trivial functions
14+
15+
**Structure**
16+
17+
- [] code should use 4 spaces for indentation; other style decisions are
18+
flexible, but be consistent within a module
19+
- [] any required metadata files are checked into the repository and placed
20+
within the directory `static`
21+
- [] any intermediate files that are created and stored by the module should
22+
be placed in the directory `cache`
23+
- [] final expected output files to be uploaded to the API are placed in the
24+
`receiving` directory; output files should not be committed to the respository
25+
- [] all options and API keys are passed through the file `params.json`
26+
- [] template parameter file (`params.json.template`) is checked into the
27+
code; no personal (i.e., usernames) or private (i.e., API keys) information is
28+
included in this template file
29+
30+
**Testing**
31+
32+
- [] module can be installed in a new virtual environment
33+
- [] pylint with the default `.pylint` settings run over the module produces
34+
minimal warnings; warnings that do exist have been confirmed as false positives
35+
- [] reasonably high level of unit test coverage covering all of the main logic
36+
of the code (e.g., missing coverage for raised errors that do not currently seem
37+
possible to reach are okay; missing coverage for options that will be needed are
38+
not)
39+
- [] all unit tests run without errors
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
"""Module to flagging interesting or unusual data points.
3+
4+
This file defines the functions that are made public by the module. As the
5+
module is intended to be executed though the main method, these are primarily
6+
for testing.
7+
"""
8+
from __future__ import absolute_import
9+
from .constants import HTML_LINK
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Call the function run_module when executed.
2+
3+
This file indicates that calling the module (`python -m MODULE_NAME`) will
4+
call the function `run_module` found within the run.py file. There should be
5+
no need to change this template.
6+
"""
7+
8+
from delphi_utils import read_params
9+
from .run import run_module # pragma: no cover
10+
11+
run_module(read_params()) # pragma: no cover
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Constants used in FlaSH."""
2+
3+
#Regions considered under states
4+
STATES = ['ak', 'al', 'ar', 'as', 'az', 'ca', 'co', 'ct', 'dc', 'de', 'fl', 'ga',
5+
'gu', 'hi', 'ia', 'id', 'il', 'in', 'ks', 'ky', 'la',
6+
'ma', 'md', 'me', 'mi', 'mn', 'mo', 'mp', 'ms', 'mt', 'nc',
7+
'nd', 'ne', 'nh', 'nj', 'nm', 'nv', 'ny', 'oh', 'ok',
8+
'or', 'pa', 'pr', 'ri', 'sc', 'sd', 'tn', 'tx', 'ut', 'va', 'vi', 'vt',
9+
'wa', 'wi', 'wv', 'wy']
10+
11+
#HTML Link for the visualization tool alerts
12+
HTML_LINK = "<https://ananya-joshi-visapp-vis-523f3g.streamlitapp.com/?params="

0 commit comments

Comments
 (0)