ts.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from pathlib import Path
  15. import numpy as np
  16. import pandas as pd
  17. from ...utils import logging
  18. from ..utils.io import TSWriter
  19. from .base import BaseResult
  20. class TSFcResult(BaseResult):
  21. def __init__(self, data):
  22. super().__init__(data)
  23. self._writer = TSWriter(backend="pandas")
  24. def save_to_csv(self, save_path):
  25. """write ts"""
  26. if not save_path.endswith(".csv"):
  27. save_path = Path(save_path) / f"{Path(self['ts_path']).stem}.csv"
  28. self._writer.write(save_path, self["forecast"])
  29. logging.info(f"The result has been saved in {save_path}.")
  30. class TSClsResult(BaseResult):
  31. def __init__(self, data):
  32. super().__init__(data)
  33. self._writer = TSWriter(backend="pandas")
  34. def save_to_csv(self, save_path):
  35. """write ts"""
  36. if not save_path.endswith(".csv"):
  37. save_path = Path(save_path) / f"{Path(self['ts_path']).stem}.csv"
  38. self._writer.write(save_path, self["classification"])
  39. logging.info(f"The result has been saved in {save_path}.")
  40. class TSAdResult(BaseResult):
  41. def __init__(self, data):
  42. super().__init__(data)
  43. self._writer = TSWriter(backend="pandas")
  44. def save_to_csv(self, save_path):
  45. """write ts"""
  46. if not save_path.endswith(".csv"):
  47. save_path = Path(save_path) / f"{Path(self['ts_path']).stem}.csv"
  48. self._writer.write(save_path, self["anomaly"])
  49. logging.info(f"The result has been saved in {save_path}.")