Skip to content
Snippets Groups Projects
Commit ae940be4 authored by David Schäfer's avatar David Schäfer
Browse files

only assign to a new variable if the new flag parameter 'assign_to' is

explicitly given
parent 7991d1c1
No related branches found
No related tags found
No related merge requests found
......@@ -13,10 +13,10 @@
+ test name and parameter object/dictionary need to be seperated by comma
- Example: `limits, {min: 0, max: 100}`
#### Optional Test Parameters
- flag:
- `flag`:
The value to set (more precisely the value to pass to the flagging component) if the tests
does not pass
- flag_period:
- `flag_period`:
+ if a value is flagged, so is the given time period following the timestamp of that value
+ Number followed by a frequency specification, e.g. '5min', '6D'.
A comprehensive list of the supported frequies can be found in the table 'Offset Aliases' in the [Pandas Docs](http://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#dateoffset-objects "Pandas Docs"). The (probably) most common options are also listed below:
......@@ -27,10 +27,12 @@
| `H` | one hour |
| `T` or `min` | one minute |
| `S` | one second |
- flag_values:
- `flag_values`:
+ Number
+ if a value is flagged, so are the next n previously unflagged values
- `assign_to`:
+ String
+ Assign the test result to a new columns given as a value to assign
### Predefined Tests
| name | required parameters | optional parameters | description |
......
......@@ -12,6 +12,13 @@ from dsl import parseFlag
from flagger import PositionalFlagger, BaseFlagger
class FlagParams:
FLAG = "flag"
PERIODE = "flag_period"
VALUES = "flag_values"
ASSIGN = "assign_to"
def _inferFrequency(data):
return pd.tseries.frequencies.to_offset(pd.infer_freq(data.index))
......@@ -67,15 +74,21 @@ def runner(meta, flagger, data, flags=None, nodata=np.nan):
if pd.isnull(flag_test):
continue
func_name, flag_params = parseFlag(flag_test)
assign_to = flag_params.get(FlagParams.ASSIGN)
if assign_to:
dummy = pd.DataFrame(index=data.index, columns=[assign_to])
flags = flags.join(flagger.emptyFlags(dummy))
varname, start_date, end_date = configrow[fields]
if varname not in data:
# add a new variable
dummy = pd.DataFrame(index=data.index, columns=[varname])
flags = flags.join(flagger.emptyFlags(dummy))
continue
dchunk = data.loc[start_date:end_date]
if dchunk.empty:
continue
# NOTE:
# within the activation period of a variable, the flag will
# be initialized if necessary
......@@ -83,7 +96,6 @@ def runner(meta, flagger, data, flags=None, nodata=np.nan):
.loc[start_date:end_date]
.fillna({varname: flagger.no_flag}))
func_name, flag_params = parseFlag(flag_test)
try:
dchunk, fchunk = flagDispatch(func_name,
dchunk, fchunk, varname,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment