Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add:generate-color and name #712

Merged
merged 8 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/test-when-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
paths:
- swanlab/**
- test/**
branches:
- main

jobs:
test:
Expand Down
82 changes: 80 additions & 2 deletions swanlab/data/run/namer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@
命名器、取色器
"""
from typing import Tuple, Optional
import random

prefix_list = [
"swan-", # 天鹅
"rat-", # 鼠
"ox-", # 牛
"tiger-", # 虎
"rabbit-", # 兔
"dragon-", # 龙
"snake-", # 蛇
"horse-", # 马
"goat-", # 羊
"monkey-", # 猴
"rooster-", # 鸡
"dog-", # 狗
"pig-" # 猪
"cat-", # 猫
"elephant-", # 象
"penguin-", # 企鹅
"kangaroo-", # 袋鼠
"monkey-", # 猴
"panda-", # 熊猫
"tiger-", # 虎
"lion-", # 狮
"zebra-", # 斑马
]


def generate_name(index: Optional[int] = None) -> str:
Expand All @@ -16,7 +42,52 @@ def generate_name(index: Optional[int] = None) -> str:
:param index: 生成名称的索引,约定为历史实验数,可以为None
:return: 生成的名称
"""
pass
if index is None:
prefix = random.choice(prefix_list)
return prefix
else:
prefix = prefix_list[index % len(prefix_list)]
return prefix + str(index + 1)


light_colors = [
"#528d59", # 绿色
"#587ad2", # 蓝色
"#c24d46", # 红色
"#9cbe5d", # 青绿色
"#6ebad3", # 天蓝色
"#dfb142", # 橙色
"#6d4ba4", # 紫色
"#8cc5b7", # 淡青绿色
"#892d58", # 紫红色
"#40877c", # 深青绿色
"#d0703c", # 深橙色
"#d47694", # 粉红色
"#e3b292", # 淡橙色
"#b15fbb", # 浅紫红色
"#905f4a", # 棕色
"#989fa3", # 灰色
]

# 黑夜模式的颜色暂时和light_colors保持一致
dark_colors = [
"#528d59", # 绿色
"#587ad2", # 蓝色
"#c24d46", # 红色
"#9cbe5d", # 青绿色
"#6ebad3", # 天蓝色
"#dfb142", # 橙色
"#6d4ba4", # 紫色
"#8cc5b7", # 淡青绿色
"#892d58", # 紫红色
"#40877c", # 深青绿色
"#d0703c", # 深橙色
"#d47694", # 粉红色
"#e3b292", # 淡橙色
"#b15fbb", # 浅紫红色
"#905f4a", # 棕色
"#989fa3", # 灰色
]


def generate_colors(index: Optional[int] = None) -> Tuple[str, str]:
Expand All @@ -25,4 +96,11 @@ def generate_colors(index: Optional[int] = None) -> Tuple[str, str]:
:param index: 生成颜色的索引,约定为历史实验数,可以为None
:return: 生成的颜色,(白天颜色,夜晚颜色)
"""
pass

if index is None:
choice_color = random.choice(light_colors)
return choice_color, choice_color # 随机返回一个颜色
else:
choice_color_light = light_colors[index % len(light_colors)]
choice_color_dark = dark_colors[index % len(dark_colors)]
return choice_color_light, choice_color_dark # 返回对应索引的颜色,如果超出范围则取模
21 changes: 17 additions & 4 deletions test/unit/data/run/test_namer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@


def test_name_no_index():
pass
name = namer.generate_name()
assert isinstance(name, str)


def test_name_with_index():
pass
name = namer.generate_name(4)
assert isinstance(name, str)
# 极大数
name = namer.generate_name(999999999)
assert isinstance(name, str)


def test_color_no_index():
pass
colors = namer.generate_colors()
assert len(colors) == 2
assert isinstance(colors, tuple)


def test_color_with_index():
pass
colors = namer.generate_colors(4)
assert len(colors) == 2
assert isinstance(colors, tuple)
# 极大数
colors = namer.generate_colors(999999999)
assert len(colors) == 2
assert isinstance(colors, tuple)