Skip to content

Commit

Permalink
refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
visualDust committed Dec 21, 2023
1 parent e1be05a commit 8e301b1
Show file tree
Hide file tree
Showing 31 changed files with 130 additions and 116 deletions.
20 changes: 10 additions & 10 deletions docs/docs/develop/daemon/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class WsMsg:

```json
{
"event-type" : ...,
"eventType" : ...,
"payload" : ...,
"event-id" : ...
"eventId" : ...
}
```

Expand Down Expand Up @@ -73,12 +73,12 @@ for instance, frontend connected to server. frontend should report connection ty

```json
{
"event-type": "handshake",
"eventType": "handshake",
"name": "project name",
"payload": {
"who": "web"
},
"event-id": X
"eventId": X
}
```

Expand All @@ -90,12 +90,12 @@ cli sents log(s) via websocket, server will receives and broadcast this message

```json
{
"event-type": "log",
"eventType": "log",
"name": "project name",
"payload": {
"log" : {...json representing log data...}
},
"event-id": -1
"eventId": -1
}
```

Expand All @@ -107,12 +107,12 @@ frontend send action request to server, and server will forwards the message to

```json
{
"event-type" : "action",
"eventType" : "action",
"name": "project name",
"payload" : {
"action" : {...json representing action trigger...}
},
"event-id" : x
"eventId" : x
}
```

Expand All @@ -124,12 +124,12 @@ cli execute action query(s) from frontend, and gives response by sending ack:

```json
{
"event-type" : "ack",
"eventType" : "ack",
"name": "project name",
"payload" : {
"action" : {...json representing action result...}
},
"event-id" : x
"eventId" : x
}
```

Expand Down
24 changes: 12 additions & 12 deletions frontend/src/components/dashboard/project/runSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ export const RunSelect = memo((props: any) => {
<>
{isOnlineRun ? (
<Tag color="green">Online</Tag>
) : runId != items[0].runid ? (
) : runId != items[0].runId ? (
<Tag color="orange">History</Tag>
) : (
<Tag color="red">Offline</Tag>
)}
{items.find((x) => x.runid == p.value)?.timestamp}
{items.find((x) => x.runId == p.value)?.timestamp}
</>
)}
>
Expand All @@ -63,12 +63,12 @@ export const RunSelect = memo((props: any) => {
style={{ gap: "5px" }}
// workaround for semi-design select: won't update label unless key changed
// https://github.com/DouyinFE/semi-design/blob/c7982af07ad92e6cafe72d96604ed63a8ca595d6/packages/semi-ui/select/index.tsx#L640
key={item.runid + "-" + item.metadata?.name + "-" + item.online}
value={item.runid}
key={item.runId + "-" + item.metadata?.name + "-" + item.online}
value={item.runId}
>
<span style={{ fontFamily: "monospace", fontSize: 12 }}>{item.timestamp}</span>
<span style={{ fontFamily: "monospace", fontSize: 12 }}>
({item.metadata?.name ?? item.runid})
({item.metadata?.name ?? item.runId})
</span>
<span style={{ flex: 1 }}></span>
<Button
Expand All @@ -91,18 +91,18 @@ export const RunSelect = memo((props: any) => {
closeDropDown();
Modal.error({
title: "Are you sure?",
content: `Deleting run ${item.timestamp} (${item.runid})`,
content: `Deleting run ${item.timestamp} (${item.runId})`,
centered: true,
onOk: async () => {
if (item.runid === runId) {
const existedId = runIds.find((x) => x.runid !== runId);
if (item.runId === runId) {
const existedId = runIds.find((x) => x.runId !== runId);
if (existedId) {
setRunId(existedId);
} else {
navigate("/");
}
}
await fetcher(`/project/${projectId}/run/${item.runid}`, { method: "DELETE" });
await fetcher(`/project/${projectId}/run/${item.runId}`, { method: "DELETE" });
mutateRunIds();
Toast.success({
content: `Deleted ${item.timestamp}`,
Expand All @@ -113,7 +113,7 @@ export const RunSelect = memo((props: any) => {
/>
)}
{item.online ? <Tag color="green">Online</Tag> : <Tag color="red">Offline</Tag>}
<HyperParams projectId={projectId} runId={item.runid} trigger="hover" position="leftTop" />
<HyperParams projectId={projectId} runId={item.runId} trigger="hover" position="leftTop" />
</Select.Option>
);
})}
Expand Down Expand Up @@ -157,7 +157,7 @@ const RunEditor = memo((props: { data: any; onResult: (edited: boolean) => void
onCancel={() => props.onResult(false)}
onOk={async () => {
const values = formRef.current.formApi.getValues();
await fetcher(`/project/${projectId}/run/${data.runid}`, {
await fetcher(`/project/${projectId}/run/${data.runId}`, {
method: "PUT",
headers: { "content-type": "application/json" },
body: JSON.stringify({
Expand All @@ -170,7 +170,7 @@ const RunEditor = memo((props: { data: any; onResult: (edited: boolean) => void
centered
>
<Form initValues={data} ref={formRef as any}>
<Form.Input field="runid" label="ID" disabled></Form.Input>
<Form.Input field="runId" label="ID" disabled></Form.Input>
<Form.Input field="metadata.name" label="Name"></Form.Input>
</Form>
</Modal>
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/hooks/useProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export function useProjectWebSocketReady(id: string) {
return useAtom(project.wsClient.isReady.atom)[0];
}

export function useProjectWebSocket<T extends WsMsg["event-type"]>(
export function useProjectWebSocket<T extends WsMsg["eventType"]>(
id: string,
type: T | null,
onMessage: (msg: Extract<WsMsg, { "event-type": T }>) => void,
onMessage: (msg: Extract<WsMsg, { eventType: T }>) => void,
) {
const project = getProject(id);
useEffect(() => {
const handle: typeof onMessage = (msg) => {
if (!type || msg["event-type"] == type) {
if (!type || msg.eventType == type) {
onMessage(msg);
}
};
Expand All @@ -58,7 +58,7 @@ export function useProjectWebSocket<T extends WsMsg["event-type"]>(
export function useProjectSeries(projectId: string, runId: string, type: string) {
return useProjectData({
type: `${type}`,
url: `/project/${projectId}/series/${type}?${new URLSearchParams({ runid: runId })}`,
url: `/project/${projectId}/series/${type}?${new URLSearchParams({ runId: runId })}`,
projectId,
runId,
transformWS: (msg) => msg.series,
Expand Down Expand Up @@ -140,8 +140,8 @@ export function useProjectData<T = any>(options: {

const handleWs = (msg: WsMsg) => {
if (
type === msg["event-type"] &&
(!runId || msg.runid == runId) &&
type === msg.eventType &&
(!runId || msg.runId == runId) &&
(!options.conditions?.series || options.conditions.series === msg.series) &&
(!options.filterWS || options.filterWS(msg))
) {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/console/projectDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function ProjectDashboard() {
const runIds = status?.runids;
const lastRunId = runIds ? runIds[runIds.length - 1] : undefined;
const paramRun = searchParams.get("run");
const paramRunFound = runIds?.find((x) => x.runid == paramRun);
const paramRunFound = runIds?.find((x) => x.runId == paramRun);
const runInfo = paramRunFound ?? lastRunId;
const runId = runInfo?.runid;
const runId = runInfo?.runId;
const isOnlineRun = Boolean(runInfo?.online);

useEffect(() => {
Expand All @@ -54,7 +54,7 @@ function ProjectDashboard() {
}, [!!runIds, paramRun, paramRunFound]);

const setRunId = (id: string) => {
if (id === lastRunId.runid) {
if (id === lastRunId.runId) {
setSearchParams({});
} else {
setSearchParams({ run: id });
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/console/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function ConsoleNavBar() {
icon: <IconListView />,
itemKey: "projects",
items: data
? data.map(({ projectid: id, name, online }) => ({
? data.map(({ projectId: id, name, online }) => ({
text: (
<Space style={{ width: "100%", minWidth: "140px" }}>
<Typography.Text
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/services/projectWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { Project } from "./projects";
import { ImageMetadata } from "./types";

export interface WsMsgBase<Type extends string = string, Payload = undefined> {
"event-type": Type;
eventType: Type;
name: string;
payload: Payload;
"event-id": number;
eventId: number;
who: "web" | "cli";
projectid: string;
runid: string;
projectId: string;
runId: string;
timestamp: string;
series?: string;
}
Expand Down Expand Up @@ -49,7 +49,7 @@ export class WsClient {
console.info("ws open");
this.send(
{
"event-type": "handshake",
eventType: "handshake",
who: "web",
},
(msg) => {
Expand All @@ -69,8 +69,8 @@ export class WsClient {
this.ws.onmessage = (e) => {
const json = JSON.parse(e.data) as WsMsg;
// console.debug("ws receive", json);
const eventId = json["event-id"];
const eventType = json["event-type"];
const eventId = json.eventId;
const eventType = json.eventType;
if (this.callbacks.has(eventId)) {
this.callbacks.get(eventId)!(json);
this.callbacks.delete(eventId);
Expand Down Expand Up @@ -103,8 +103,8 @@ export class WsClient {
const eventId = this.nextId++;
const json = {
...msg,
projectid: this.project.id,
"event-id": eventId,
projectId: this.project.id,
eventId: eventId,
};
console.info("ws send", json);
this.ws.send(JSON.stringify(json));
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/services/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class Project {
) {
this.wsClient.send(
{
"event-type": "action",
runid: runId,
eventType: "action",
runId: runId,
payload: {
name: action,
args,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export interface Condition {
series?: string;
order?: Record<string, "ASC" | "DESC">;
limit?: number;
runid?: string;
runId?: string;
runId?: string;
}

export function createCondition(condition: Condition) {
if (condition.runId) {
condition.runid = condition.runId;
condition.runId = condition.runId;

Check failure on line 15 in frontend/src/utils/condition.ts

View workflow job for this annotation

GitHub Actions / build

'condition.runId' is assigned to itself
delete condition.runId;
}
return new URLSearchParams({ condition: JSON.stringify({ ...condition }) }).toString();
Expand Down
2 changes: 1 addition & 1 deletion neetbox.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "neetbox"
version = "0.3.3"
projectid = "e1b97d6a-089c-433a-a8a5-95be751932fc"
projectId = "e1b97d6a-089c-433a-a8a5-95be751932fc"

[logging]
level = "INFO"
Expand Down
14 changes: 7 additions & 7 deletions neetbox/_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from enum import Enum
from importlib.metadata import version
from typing import Any, Union
from importlib.metadata import version

VERSION = version("neetbox")

Expand All @@ -19,16 +18,17 @@
ID_KEY = "id"
NAME_KEY = "name"
ARGS_KEY = "args"
PROJECT_ID_KEY = WORKSPACE_ID_KEY = "projectid"
RUN_ID_KEY = "runid"
MACHINE_ID_KEY = "machineId"
PROJECT_ID_KEY = WORKSPACE_ID_KEY = "projectId"
RUN_ID_KEY = "runId"
SERIES_KEY = "series"
EVENT_TYPE_KEY = "event-type"
EVENT_ID_KEY = "event-id"
EVENT_TYPE_KEY = "eventType"
EVENT_ID_KEY = "eventId"
WHO_KEY = "who"
PAYLOAD_KEY = "payload"
METADATA_KEY = "metadata"
TIMESTAMP_KEY = "timestamp"
HISTORY_LEN_KEY = "history-len"
HISTORY_LEN_KEY = "historyLen"
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f" # YYYY-MM-DDTHH:MM:SS.SSS


Expand Down Expand Up @@ -152,4 +152,4 @@ def merge(cls, x: Union["EventMsg", dict], y: Union["EventMsg", dict]):

NEETBOX_VERSION = version("neetbox")
HISTORY_FILE_ROOT = ".neethistory"
HISTORY_FILE_TYPE_NAME = "neetory"
HISTORY_FILE_TYPE_NAME = "neetory"
4 changes: 2 additions & 2 deletions neetbox/cli/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from rich.console import Console
from rich.table import Table

import neetbox.config._cli_user_config as cliconfig
from neetbox.client._client_web_apis import *
import neetbox.config._global as global_config
from neetbox.client.api._client_web_apis import *
from neetbox.config._workspace import (
_get_module_level_config,
_init_workspace,
Expand Down
12 changes: 6 additions & 6 deletions neetbox/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# Github: github.com/visualDust
# Date: 20231206

from ._action_agent import _NeetActionManager as NeetActionManager
from ._client import connection
from ._image import add_figure, add_image
from ._plot import add_hyperparams, add_scalar
from ._progress import Progress as progress
from ._signal_and_slot import listen, watch
from .api._action_agent import _NeetActionManager as NeetActionManager
from .api._client import connection
from .api._image import add_figure, add_image
from .api._plot import add_hyperparams, add_scalar
from .api._progress import Progress as progress
from .api._signal_and_slot import listen, watch

action = NeetActionManager.register
ws_subscribe = connection.ws_subscribe
Expand Down
File renamed without changes.
Loading

0 comments on commit 8e301b1

Please sign in to comment.