data_process_config_entity.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: yq
  4. @time: 2024/11/1
  5. @desc: 数据处理配置类
  6. """
  7. import json
  8. import os
  9. from commom import GeneralException
  10. from enums import ResultCodesEnum
  11. class DataProcessConfigEntity():
  12. def __init__(self, y_column: str, fill_method: str, split_method: str):
  13. # 定义y变量
  14. self._y_column = y_column
  15. # 缺失值填充方法
  16. self._fill_method = fill_method
  17. # 数据划分方法
  18. self._split_method = split_method
  19. @property
  20. def y_column(self):
  21. return self._y_column
  22. @property
  23. def fill_method(self):
  24. return self._fill_method
  25. @property
  26. def split_method(self):
  27. return self._split_method
  28. @staticmethod
  29. def from_config(config_path: str):
  30. """
  31. 从配置文件生成实体类
  32. """
  33. if os.path.exists(config_path):
  34. with open(config_path, mode="r", encoding="utf-8") as f:
  35. j = json.loads(f.read())
  36. else:
  37. raise GeneralException(ResultCodesEnum.NOT_FOUND, message=f"指配置文件【{config_path}】不存在")
  38. return DataProcessConfigEntity(**j)
  39. if __name__ == "__main__":
  40. pass