# -*- coding: utf-8 -*-
"""
@author: yq
@time: 2024/11/1
@desc: 
"""
import pandas as pd

from data import DataLoaderBase, DataLoaderExcel
from entitys import MetricFucResultEntity
from metrics import MetricBase, f_register_metric_func
from monitor import MonitorMetric


class AMetric(MetricBase):

    def __init__(self, file_path: str, sheet_name: str = 0, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._file_path = file_path
        self._sheet_name = sheet_name

    def _load_data(self, data_loader: DataLoaderBase, *args, **kwargs) -> pd.DataFrame:
        data = data_loader.get_data(self._file_path, self._sheet_name)
        return data

    def calculate(self, *args, **kwargs) -> MetricFucResultEntity:
        data = self._load_data(*args, **kwargs)
        return MetricFucResultEntity(table=data, value='1', image_path='cache/image/t1.png')

class BMetric(MetricBase):

    def __init__(self, v: str, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._v = v

    def calculate(self, *args, **kwargs) -> MetricFucResultEntity:
        if ".png" in self._v:
            return MetricFucResultEntity(image_path=self._v)
        else:
            return MetricFucResultEntity(value=self._v)


if __name__ == "__main__":
    f_register_metric_func(AMetric)
    f_register_metric_func(BMetric)
    data_loader = DataLoaderExcel()

    a = data_loader.get_data("cache/t1.xlsx")
    # a.writr("cache/a.xlsx")


    monitor_metric = MonitorMetric("./cache/model_monitor_config1.json")
    monitor_metric.calculate_metric(data_loader=data_loader)
    monitor_metric.generate_report()
