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

Merge branch 'dmp_refactoring' into 'develop'

dmpscheme refactorings

See merge request !427
parents 51a3f4d7 ac0fe57a
No related branches found
No related tags found
6 merge requests!685Release 2.4,!684Release 2.4,!567Release 2.2.1,!566Release 2.2,!501Release 2.1,!427dmpscheme refactorings
Pipeline #72714 passed with stages
in 7 minutes and 59 seconds
......@@ -78,6 +78,28 @@ class DmpScheme(TranslationScheme):
def __init__(self):
super().__init__(forward=self._FORWARD, backward=self._BACKWARD)
def toHistory(self, field_flags: pd.DataFrame):
"""
Translate a single field of external ``Flags`` to a ``History``
"""
field_history = History(field_flags.index)
for (flag, cause, comment), values in field_flags.groupby(_QUALITY_LABELS):
try:
comment = json.loads(comment)
except json.decoder.JSONDecodeError:
comment = {"test": "unknown", "comment": ""}
histcol = pd.Series(np.nan, index=field_flags.index)
histcol.loc[values.index] = self(flag)
meta = {
"func": comment["test"],
"kwargs": {"comment": comment["comment"], "cause": cause},
}
field_history.append(histcol, meta=meta)
return field_history
def forward(self, df: pd.DataFrame) -> Flags:
"""
Translate from 'external flags' to 'internal flags'
......@@ -96,27 +118,8 @@ class DmpScheme(TranslationScheme):
data = {}
for field in df.columns.get_level_values(0):
field_flags = df[field]
field_history = History(field_flags.index)
for (flag, cause, comment), values in field_flags.groupby(_QUALITY_LABELS):
try:
comment = json.loads(comment)
except json.decoder.JSONDecodeError:
comment = {"test": "unknown", "comment": ""}
histcol = pd.Series(np.nan, index=field_flags.index)
histcol.loc[values.index] = self(flag)
meta = {
"func": comment["test"],
"kwargs": {"comment": comment["comment"], "cause": cause},
}
field_history.append(histcol, meta=meta)
data[str(field)] = field_history
for field in df.columns.get_level_values(0).drop_duplicates():
data[str(field)] = self.toHistory(df[field])
return Flags(data)
......
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