Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2f770eb
feat(Chart): 可以记录状态,但是所有分块同时打开或关闭
little1d Mar 4, 2024
2769f5c
feat(ChartsPage.vue): dashboard Charts页面实现
little1d Mar 4, 2024
882f34e
feat:(ChatsPage): dashboard 界面响应式更新状态
little1d Mar 5, 2024
0d4c0d7
feat(ChartPage): 单个实验页面实现记忆图表展开关闭
little1d Mar 5, 2024
97969ae
feat(ChartPage): comment format
little1d Mar 5, 2024
2df86b8
bugfix(ChartPage.vue): 以实验名称构造二级对象,控制开关
little1d Mar 5, 2024
e899e51
Update ChartsContainer.vue
little1d Mar 5, 2024
6ead436
Update ChartsPage.vue
little1d Mar 5, 2024
b7795cb
Update ChartsContainer.vue
little1d Mar 5, 2024
28344dc
Update ChartPage.vue
little1d Mar 5, 2024
fd6b346
Update ChartPage.vue
little1d Mar 5, 2024
545fc70
Update ChartsPage.vue
little1d Mar 5, 2024
b10870e
migrate: add opened
SAKURA-CAT Mar 5, 2024
89db644
Merge branch 'main' into bugfix/group-folding
SAKURA-CAT Mar 7, 2024
4763761
refactor opened status
SAKURA-CAT Mar 7, 2024
fd95ff4
feat(experiment.py): namespace router and methods
little1d Mar 8, 2024
d5a7f0b
feat(ChartsDashboard): patch
little1d Mar 8, 2024
b4225a9
feat(namespace.py): add files
little1d Mar 8, 2024
eb95c18
feat(app.py): add namespace router
little1d Mar 8, 2024
9760171
bugfix(app.py): prefix refactor
little1d Mar 8, 2024
c01f455
feat(namespace): interface set properly
little1d Mar 8, 2024
3e5f396
feat(namespace): comment fixed
little1d Mar 8, 2024
30f4c06
Update ChartsPage.vue
SAKURA-CAT Mar 8, 2024
ba7c059
Merge branch 'bugfix/group-folding' of https://github.com/SwanHubX/sw…
SAKURA-CAT Mar 8, 2024
69e70b6
Update namespace.py
SAKURA-CAT Mar 8, 2024
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
6 changes: 5 additions & 1 deletion swanlab/db/db_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..env import get_db_path
import os
from peewee import SqliteDatabase
from .table_config import tables, Tag, Experiment
from .table_config import tables, Tag, Experiment, Namespace
from .migrate import *

# 判断是否已经binded了
Expand Down Expand Up @@ -57,6 +57,10 @@ def connect(autocreate=False) -> SqliteDatabase:
swandb.bind(tables)
swandb.create_tables(tables)
swandb.close()
# 完成数据迁移,如果namespace表中没有opened字段,则添加
if not Namespace.field_exists("opened"):
# 不启用外键约束
add_opened(SqliteDatabase(path))
# 完成数据迁移,如果experiment表中没有finish_time字段,则添加
if not Experiment.field_exists("finish_time"):
# 不启用外键约束
Expand Down
1 change: 1 addition & 0 deletions swanlab/db/migrate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
"""
from .tag_sort import add_sort
from .exp_finish_time import add_finish_time
from .namespace_opened import add_opened
21 changes: 21 additions & 0 deletions swanlab/db/migrate/namespace_opened.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r"""
@DATE: 2024-03-05 19:42:52
@File: swanlab/db/migrate/namespace_opened.py
@IDE: vscode
@Description:
为namespace增加opened字段
"""
from peewee import SqliteDatabase, IntegerField
from playhouse.migrate import migrate, SqliteMigrator


def add_opened(db):
"""
为数据库的namespace表添加opened字段,用于记录命名空间是否已经被打开
默认值为False
"""
migrator = SqliteMigrator(db)
opened = IntegerField(default=1)
migrate(migrator.add_column("namespace", "opened", opened))
4 changes: 3 additions & 1 deletion swanlab/db/models/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Meta:
"""命名空间描述,可为空"""
sort = IntegerField()
"""命名空间索引,用于排序,同一个项目/实验下,命名空间索引不能重复,索引越小,排序越靠前,索引>=0"""
opened = IntegerField(default=1)
"""命名空间是否已经被打开,默认为1,表示已经被打开,0表示未被打开"""
more = TextField(default=None, null=True)
"""更多信息配置,json格式,将在表函数中检查并解析"""
create_time = CharField(max_length=30, null=False)
Expand All @@ -68,7 +70,7 @@ class Meta:
def __dict__(self):
return {
"id": self.id,
"experiment_id": self.experiment_id,
"experiment_id": self.experiment_id.__dict__(),
"project_id": self.project_id,
"name": self.name,
"description": self.description,
Expand Down
2 changes: 2 additions & 0 deletions swanlab/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ async def _(*args, **kwargs):
# 导入数据相关的路由
from .router.experiment import router as experiment
from .router.project import router as project
from .router.namespace import router as namespace

# 媒体文件路由,允许前端获取其他产生的媒体文件
from .router.media import router as media
Expand All @@ -94,3 +95,4 @@ async def _(*args, **kwargs):
app.include_router(project, prefix=prefix + "/project")
app.include_router(experiment, prefix=prefix + "/experiment")
app.include_router(media, prefix=prefix + "/media")
app.include_router(namespace, prefix=prefix + "/namespace")
46 changes: 46 additions & 0 deletions swanlab/server/controller/namespace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import ujson
import shutil
from ..module.resp import SUCCESS_200, DATA_ERROR_500, CONFLICT_409, NOT_FOUND_404
from fastapi import Request

import yaml
from typing import List, Dict

from ...db import connect, NotExistedError

from ...db import (
Namespace,
)


__to_list = Namespace.search2list


# 修改namespace可见性
def change_namespace_visibility(namespace_id: int, opened: int):
"""修改namespace可见性

Parameters
----------
namespace_id : int
_description_
opened : int
在一个实验下,该namespace是否可见,true -> 1 , false -> 0

Returns
-------
_type_:dict
当前namespace信息
"""
try:
namespace = Namespace.get_by_id(namespace_id)
except NotExistedError:
return NOT_FOUND_404("Namespace with id {} does not exist.".format(namespace_id))
if opened:
namespace.opened = 1
else:
namespace.opened = 0
namespace.save()
print(namespace_id, namespace.opened, opened)
return SUCCESS_200({"namespace": namespace.__dict__()})
34 changes: 34 additions & 0 deletions swanlab/server/router/namespace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from fastapi import APIRouter
from ..module.resp import PARAMS_ERROR_422

from ..controller.namespace import (
# 修改namespace可见性
change_namespace_visibility,
)
from fastapi import Request
from urllib.parse import quote

router = APIRouter()


# 修改namespace可见性
@router.patch("/{namespace_id}/opened")
async def _(namespace_id: int, request: Request):
"""修改namespace可见性

Parameters
----------
experiment_id : int
实验id
request : Request
请求体,包含 opened 字段
Returns
-------
experiment : dict
当前实验信息
"""

opened = (await request.json()).get("opened")
if opened is None:
return PARAMS_ERROR_422("Request parameter 'show'")
return change_namespace_visibility(namespace_id, opened)
15 changes: 15 additions & 0 deletions vue/src/charts/ChartsDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
:key="group.name"
:label="getNamespaces(group.name)"
:charts="getCharts(group)"
:opened="!!group.opened"
@switch="(opened) => debouncedHandleSwitch(group.id, opened)"
/>
</template>

Expand All @@ -22,6 +24,8 @@
import ChartsContainer from './components/ChartsContainer.vue'
import { t } from '@swanlab-vue/i18n'
import SmoothButton from './components/SmoothButton.vue'
import { debounce } from '@swanlab-vue/utils/common'
import http from '@swanlab-vue/api/http'
const props = defineProps({
// 整个图表列表集合
groups: {
Expand Down Expand Up @@ -66,6 +70,17 @@ const handleSmooth = (method) => {
})
})
}

// ---------------------------------- 在此处处理命名空间打开和关闭 ----------------------------------
const handleSwitch = (id, opened) => {
console.log('namespace click', id, opened)
// 向后端更新展开状态
http.patch('/namespace/' + id + '/opened', {
opened
})
}

const debouncedHandleSwitch = debounce(handleSwitch, 300)
</script>

<style lang="scss" scoped>
Expand Down
14 changes: 9 additions & 5 deletions vue/src/charts/components/ChartsContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- 控制栏 -->
<div class="flex items-center">
<!-- 关闭、展开按钮 -->
<button class="flex items-center gap-1 relative" @click="handleExpand">
<button class="flex items-center gap-1 relative" @click="handleNamespaceClick">
<SLIcon icon="down" class="w-6 h-6 absolute -left-6" :class="{ '-rotate-90': !isExpand }" />
{{ label }}
<span class="px-3 bg-highest text-sm rounded-full ml-2 text-difault">{{ charts.length || 0 }}</span>
Expand Down Expand Up @@ -43,15 +43,19 @@ const props = defineProps({
charts: {
type: Array,
required: true
},
opened: {
type: Boolean,
required: true
}
})

const emit = defineEmits(['switch'])
// ---------------------------------- 控制展开和关闭的状态 ----------------------------------
const isExpand = ref(props.opened)

const isExpand = ref(true)

const handleExpand = () => {
const handleNamespaceClick = () => {
isExpand.value = !isExpand.value
emit('switch', isExpand.value)
}

// ---------------------------------- charts组件列表 ----------------------------------
Expand Down
2 changes: 1 addition & 1 deletion vue/src/views/charts/ChartsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const generateGroups = () => {
const groups = []
namespaces.value.forEach((namespace) => {
const group = {
name: namespace.name,
...namespace,
charts: []
}
namespace.charts.forEach((chart_id) => {
Expand Down
3 changes: 2 additions & 1 deletion vue/src/views/charts/components/ChartsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @since: 2024-02-06 17:17:55
**/
import { useProjectStore } from '@swanlab-vue/store'
import { provide, onUnmounted } from 'vue'
import { provide, onUnmounted, onMounted } from 'vue'
import http from '@swanlab-vue/api/http'
import ChartsDashboard from '@swanlab-vue/charts/ChartsDashboard.vue'
const props = defineProps({
Expand All @@ -25,6 +25,7 @@ const props = defineProps({
required: true
}
})

const projectStore = useProjectStore()

// ---------------------------------- 轮询器 ----------------------------------
Expand Down