From ebf9cf267a3dc3ea183a7f479879f195e09dc7ea Mon Sep 17 00:00:00 2001 From: KAAANG <79990647+SAKURA-CAT@users.noreply.github.com> Date: Mon, 9 Dec 2024 20:33:20 +0800 Subject: [PATCH] feat: misc (#23) --- pyproject.toml | 2 +- swankit/callback/models/key.py | 22 +++++++++++++++++++--- swankit/env.py | 8 ++++++++ test/unit/callback/models/test_key.py | 8 +++++++- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1a82f49..8663f1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ build-backend = "hatchling.build" [project] name = "swankit" -version = "0.1.2b4" +version = "0.1.2b5" dynamic = ["readme", "dependencies"] description = "Base toolkit for SwanLab" license = "Apache-2.0" diff --git a/swankit/callback/models/key.py b/swankit/callback/models/key.py index cd55c33..78a74ef 100644 --- a/swankit/callback/models/key.py +++ b/swankit/callback/models/key.py @@ -7,7 +7,7 @@ @Description: 与Key相关的回调函数触发时的模型 """ -from typing import Union, Optional, Dict, List, Literal, Tuple, TypedDict +from typing import Union, Optional, Dict, List, Literal, Tuple from swankit.core import ChartType, ParseErrorInfo, MediaBuffer, ChartReference from urllib.parse import quote @@ -23,28 +23,44 @@ class ColumnConfig: 列信息配置 """ - def __init__(self, y_range: YRange = None, chart_name: Optional[str] = None, metric_name: Optional[str] = None): + def __init__( + self, + y_range: YRange = None, + chart_name: Optional[str] = None, + chart_index: Optional[str] = None, + metric_name: Optional[str] = None, + ): """ 生成的列信息配置对象 :param y_range: y轴范围 :param chart_name: 图表名称 + :param chart_index: 图表索引 :param metric_name: 指标名称 """ self.y_range: YRange = y_range self.chart_name: Optional[str] = chart_name + self.chart_index: Optional[str] = chart_index self.metric_name: Optional[str] = metric_name - def clone(self, y_range: YRange = None, chart_name: Optional[str] = None, metric_name: Optional[str] = None): + def clone( + self, + y_range: YRange = None, + chart_name: Optional[str] = None, + chart_index: Optional[str] = None, + metric_name: Optional[str] = None, + ): """ 克隆一个新的ColumnConfig对象,并且可以修改其中的参数 :param y_range: y轴范围 :param chart_name: 图表名称 + :param chart_index: 图表索引 :param metric_name: 指标名称 """ return ColumnConfig( y_range=y_range if y_range is not None else self.y_range, chart_name=chart_name if chart_name is not None else self.chart_name, metric_name=metric_name if metric_name is not None else self.metric_name, + chart_index=chart_index if chart_index is not None else self.chart_index, ) diff --git a/swankit/env.py b/swankit/env.py index 1e6214b..25bcd34 100644 --- a/swankit/env.py +++ b/swankit/env.py @@ -10,6 +10,7 @@ import os import sys from enum import Enum +from platform import platform from typing import List import datetime @@ -77,6 +78,13 @@ def is_windows() -> bool: raise OSError("Unknown system, not windows or unix-like system") +def is_macos() -> bool: + """判断当前操作系统是否是macos + :return: True表示是macos系统,False表示不是macos系统 + """ + return "mac" in platform().lower() + + def create_time() -> str: """获取当前时间(UTC时区)""" return datetime.datetime.now(datetime.timezone.utc).isoformat() diff --git a/test/unit/callback/models/test_key.py b/test/unit/callback/models/test_key.py index a7774ab..7ee6049 100644 --- a/test/unit/callback/models/test_key.py +++ b/test/unit/callback/models/test_key.py @@ -3,10 +3,11 @@ def test_column_config(): - c = K.ColumnConfig(y_range=(0, 100), chart_name="CPU Utilization (%)") + c = K.ColumnConfig(y_range=(0, 100), chart_name="CPU Utilization (%)", metric_name=None) assert c.y_range == (0, 100) assert c.chart_name == "CPU Utilization (%)" assert c.metric_name is None + clone = c.clone(y_range=None, metric_name="12345") assert clone.y_range == (0, 100) assert clone.chart_name == c.chart_name @@ -15,6 +16,11 @@ def test_column_config(): assert clone.y_range == (0, 50) assert clone.chart_name == c.chart_name assert clone.metric_name == "12345" + c = K.ColumnConfig(y_range=(0, 100), chart_name="CPU Utilization (%)", metric_name="12345", chart_index="1") + assert c.y_range == (0, 100) + assert c.chart_name == "CPU Utilization (%)" + assert c.metric_name == "12345" + assert c.chart_index == "1" def test_column_info():