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

from data import DataLoaderMysql
from entitys import MetricFucResultEntity,DbConfigEntity
from metrics import MetricBase, f_register_metric_func
from monitor import MonitorMetric


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(BMetric)
    data_loader = DataLoaderMysql(DbConfigEntity.from_config("config/demo/mysql_config.json"))
    monitor_metric = MonitorMetric("config/demo/monitor_config_template_excel.json")
    monitor_metric.calculate_metric(data_loader=data_loader)
    monitor_metric.generate_report()
