Add re-flagging based on multiple filters#30
Conversation
cb24699 to
003d5ad
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## emmleroy-v1.0.0 #30 +/- ##
===================================================
- Coverage 96.57% 95.49% -1.08%
===================================================
Files 17 18 +1
Lines 846 932 +86
===================================================
+ Hits 817 890 +73
- Misses 29 42 +13
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| # i.e. are flag names and values different for database vs rawSD data? | ||
| FLAGS = {} | ||
|
|
||
| FLAGS["v100"] = [ |
There was a problem hiding this comment.
We can remove all references to ARISense
| df["flag"] = df["flag"].astype(int, errors='ignore') | ||
|
|
||
| # Drop NaNs | ||
| df = df.dropna(how='any', subset=["flag"]) |
There was a problem hiding this comment.
Definitely want to log this, as it should never occur (for future PR)
| for item in data: | ||
| click.echo(item) | ||
|
|
||
| echo_flag_table(df) |
There was a problem hiding this comment.
This will be removed once we have logging implemented
| from quantaq_cli.exceptions import InvalidFileExtension, InvalidArgument, InvalidDeviceModel | ||
|
|
||
|
|
||
| def add_flag(df, flag_name, flag_value, criterion): |
There was a problem hiding this comment.
Let's make sure we add docstrings that describe types and what the purpose of the function is.
| tscol = determine_timestamp_column(df) | ||
|
|
||
| # Force timestamp type | ||
| df[tscol] = df[tscol].map(pd.to_datetime) |
There was a problem hiding this comment.
Should check the type first and only do this if it's not already a datetime
| def infer_data_source(df): | ||
| # Determine the best timestamp column and sort | ||
| tscol = determine_timestamp_column(df) | ||
| df[tscol] = pd.to_datetime(df[tscol]) |
There was a problem hiding this comment.
Should only do this if needed
There was a problem hiding this comment.
We also have this in several places, so probably a good idea to create a helper function
| has_1min = 60.0 in tdiffs | ||
| has_5sec = 5.0 in tdiffs | ||
|
|
||
| if has_1min and has_5sec: |
There was a problem hiding this comment.
So, it's highly, highly likely that you're always going to have some sort of mixed tdiffs. It is likely rarer for you to encounter both 1min and 5s exactly, but it's definitely within the realm of possibility. We way want to be a bit more lenient and just look at the frequency of tdiffs? Similarly, the UFP data is 10s on the SD card, not 1min.
There was a problem hiding this comment.
Changed this to most common tdiff in d838aaa (in PR#32) and added logging
| MOD-X-00993 -> modulair-x | ||
| MOD-X-PM-01685 -> modulair-x-pm | ||
| """ | ||
| prefix, _, _ = device_sn.rpartition("-") |
There was a problem hiding this comment.
Will this catch MOD-UFP-XXXXX? We should probably add to the docstring at minimum.
There was a problem hiding this comment.
It will! Added to docstring and tests in 2ca1564(PR#32)
| Flag("FLAG_BAT", 2048, ["bat_voltage", "soc", "vbat"]), | ||
| ] | ||
|
|
||
| SUPPORTED_MODELS = ("modulair", "modulair-x", "modulair-pm", "modulair-x-pm") |
There was a problem hiding this comment.
Sounds good, will hold off for now until I add modulair-ufp flagging logic (at least for database/api data)
| Range = namedtuple("Range", ["column", "lo", "hi"]) | ||
| Gap = namedtuple("Gap", ["gap_in_seconds", "post_gap_flag_length_seconds"]) | ||
|
|
||
| FLAG_CRITERIA = { |
There was a problem hiding this comment.
I think it might be easiest to just go over the criteria before dumping too much time into this part. The SD and db sides are fairly different and the logic may be difficult to capture in this way, though I could be wrong.
Summary
This PR adds re-flagging of QuantAQ data based on multiple flag criteria (filters)
Changes
Testing
poetry run pytest --cov=./ --cov-report=xml -rPpassesOther notes