CleanRs70.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Mon Sep 30 10:11:55 2019
  5. @author: tanya
  6. """
  7. import pandas as pd
  8. import os
  9. import sys
  10. sys.path.append(os.getcwd())
  11. from libraries.import_process_instances.CleanProcessTable import CleanProcessTable
  12. class CleanRs70(CleanProcessTable):
  13. '''
  14. '''
  15. def __init__(self):
  16. '''
  17. '''
  18. super().__init__(
  19. mapping_path=os.path.join(".", "migration_mappings",
  20. "rs70_mapping.json"),
  21. inconsist_report_table="inconsist_rs70",
  22. sort_columns=["radsatznummer", "eingabe_datum"],
  23. index_columns=["radsatznummer", "eingabe_datum"],
  24. log_name="CleanRs70")
  25. def filter_invalid_schadcode(self, data: pd.DataFrame) -> pd.DataFrame:
  26. '''
  27. In the configuration we store a list of schadcodes assignment
  28. of which means that the product is scrap. No more schadcodes after
  29. this schadcode should be assigned.
  30. '''
  31. from libraries.configuration import default as cfg
  32. self.error_column_abscence(columns=["radsatznummer", "schadcode"],
  33. data=data)
  34. data.sort_values(by=self._sort_columns, inplace=True)
  35. is_last_schadcode = (data["radsatznummer"] !=
  36. data["radsatznummer"].shift(-1))
  37. is_invalid = (~is_last_schadcode &
  38. data["schadcode"].isin(cfg.schrott_schadcodes))
  39. data = self._filter_invalid_data(
  40. data=data,
  41. invalid_mask=is_invalid,
  42. reason="invalid schadcode")
  43. # XXX temporary here
  44. # data["eingabe_datum"] = pd.to_datetime(data["eingabe_datum"])
  45. return data