This commit is contained in:
IDONTSUDO 2024-05-03 21:30:18 +03:00
parent 89d4226ea6
commit 4585d079f6
19 changed files with 149 additions and 30 deletions

View file

@ -20,6 +20,7 @@ export interface ISkillCardProps {
epoch?: number;
onDelete?: (id: string) => void;
datasetName?: string;
epochNextTraining?: number;
}
export const SkillCard = (props: ISkillCardProps) => {
@ -52,7 +53,7 @@ export const SkillCard = (props: ISkillCardProps) => {
backgroundColor: "#f7f2fa",
borderRadius: 10,
padding: 10,
width: 150,
width: 200,
height: "max-content",
alignContent: "center",
display: "flex",
@ -86,7 +87,9 @@ export const SkillCard = (props: ISkillCardProps) => {
<div style={{ display: "flex", flexDirection: "column", margin: 10 }}>
<CoreText text={props.name ?? ""} type={CoreTextType.medium} />
<div style={{ height: 10 }} />
<CoreText text={"Количество эпох: " + props.epoch?.toString() ?? ""} type={CoreTextType.small} />
<CoreText text={"обученных эпох: " + props.epoch?.toString() ?? ""} type={CoreTextType.small} />
<CoreText text={"обучится эпох: " + props.epoch?.toString() ?? ""} type={CoreTextType.small} />
<CoreText text={"Датасет: " + props.datasetName ?? ""} type={CoreTextType.small} />
</div>
<div style={{ height: 10 }}>
@ -120,9 +123,10 @@ export const SkillCard = (props: ISkillCardProps) => {
<CoreButton
text="дообучение"
onClick={() => {
if (props.startOnClick && props.id) props.startOnClick(props.id);
if (props.continueOnClick && props.id) props.continueOnClick(props.id);
}}
/>
<div style={{ height: 10 }} />
<CoreButton
text="заново"
onClick={() => {

View file

@ -1,25 +1,39 @@
import makeAutoObservable from "mobx-store-inheritance";
import { Result } from "../../core/helper/result";
import { ISkils } from "./skills_repository";
import { ISkils } from "./skills_http_repository";
export class SkillModel {
numberOfTrainedEpochs?: number;
id?: string;
constructor(
public name: string,
public datasetId: string,
public project: string,
public epoch: number,
numberOfTrainedEpochs?: number
numberOfTrainedEpochs?: number,
id?: string
) {
this.numberOfTrainedEpochs = numberOfTrainedEpochs;
this.id = id;
makeAutoObservable(this);
}
static fromISkill(model: ISkils) {
return new SkillModel(model.name, model.datasetId._id, model.project._id, model.epoch, model.numberOfTrainedEpochs);
return new SkillModel(
model.name,
model.datasetId._id,
model.project._id,
model.epoch,
model.numberOfTrainedEpochs,
model._id
);
}
static empty() {
return new SkillModel("", "", "", 0);
}
valid(): Result<string, SkillModel> {
if (this.name.isEmpty()) {
return Result.error("введите имя скила");

View file

@ -0,0 +1,31 @@
import { TypedEvent } from "../../core/helper/typed_event";
import { SocketRepository, socketRepository } from "../../core/repository/socket_repository";
import { ProcessStatus } from "../dataset/dataset_model";
export interface ProcessUpdate {
id: string;
status: ProcessStatus;
}
export class SkillSocketRepository extends TypedEvent<ProcessUpdate> {
socketRepository: SocketRepository = socketRepository;
constructor() {
super();
this.socketRepository.on((e) => {
if (e.event === "realtime") {
if (e.payload !== undefined && e.payload.value !== undefined && e.payload.value.id !== undefined) {
this.emit({
id: String(e.payload.value.id),
status: ProcessStatus.END,
});
}
if (e.payload !== undefined && e.payload.error !== undefined && e.payload.error.id !== undefined) {
this.emit({
id: String(e.payload.error.id),
status: ProcessStatus.ERROR,
});
}
}
});
}
}

View file

@ -39,7 +39,7 @@ export const SkillScreen = observer(() => {
<div
style={{
display: "grid",
gridTemplateColumns: "repeat(auto-fill, minmax(150px,1px))",
gridTemplateColumns: "repeat(auto-fill, minmax(220px,1px))",
width: "100%",
gap: 20,
margin: 12,
@ -56,9 +56,11 @@ export const SkillScreen = observer(() => {
processStatus={el.processStatus}
empty={false}
epoch={el.numberOfTrainedEpochs}
epochNextTraining={el.epoch}
startOnClick={(id) => store.execSkill(id)}
continueOnClick={(id) => store.continueSkill(id)}
onEdit={(id) => store.editSkill(id)}
onEdit={(id) => store.fromEditSkill(id)}
onDelete={(id) => store.deleteSkill(id)}
/>
))}
<SkillCard empty={true} emptyOnClick={() => store.edtDrawer(DrawersSkill.NEW_SKILL, true)} />
@ -71,7 +73,14 @@ export const SkillScreen = observer(() => {
onClose={() => store.edtDrawer(DrawersSkill.EDIT_SKILL, false)}
open={store.drawers.find((el) => el.name === DrawersSkill.EDIT_SKILL)?.status}
>
<CoreInput value={(store.skill.epoch ?? "").toString()} label={"добавить эпох"} />
<div style={{ display: "flex", flexDirection: "column", justifyContent: "space-between", height: "100%" }}>
<CoreInput value={(store.skill.epoch ?? "").toString()} label={"добавить эпох"} />
<div style={{ display: "flex" }}>
<CoreButton text="Сохранить" filled={true} onClick={() => store.saveEdiSkill()} />
<div style={{ width: 10 }} />
<CoreButton text="Отмена" onClick={() => store.edtDrawer(DrawersSkill.NEW_SKILL, false)} />
</div>
</div>
</Drawer>
<Drawer
title={store.titleDrawer}

View file

@ -2,12 +2,14 @@ import makeAutoObservable from "mobx-store-inheritance";
import { NavigateFunction } from "react-router-dom";
import { HttpError } from "../../core/repository/http_repository";
import { UiErrorState } from "../../core/store/base_store";
import { ISkils, SkillsHttpRepository } from "./skills_repository";
import { ISkils, SkillsHttpRepository } from "./skills_http_repository";
import { Drawer } from "../dataset/dataset_store";
import { IDatasetModel } from "../dataset/dataset_model";
import { message } from "antd";
import { UUID } from "../all_projects/data/project_repository";
import { SkillModel } from "./skill_model";
import { SocketRepository, socketRepository } from "../../core/repository/socket_repository";
import { ProcessUpdate, SkillSocketRepository } from "./skill_socket_repository";
export enum DrawersSkill {
NEW_SKILL = "Новый навык",
@ -15,11 +17,6 @@ export enum DrawersSkill {
}
export class SkillStore extends UiErrorState<HttpError> {
editSkill(id: string): void {
this.skill = SkillModel.fromISkill(this.getSkillById(id) as ISkils);
this.edtDrawer(DrawersSkill.EDIT_SKILL, true);
}
drawers: Drawer[];
skillsHttpRepository: SkillsHttpRepository;
skils?: ISkils[];
@ -27,6 +24,7 @@ export class SkillStore extends UiErrorState<HttpError> {
activeProjectId?: UUID;
skill: SkillModel;
titleDrawer: string = DrawersSkill.NEW_SKILL;
skillSocketRepository: SkillSocketRepository = new SkillSocketRepository();
constructor() {
super();
@ -38,14 +36,25 @@ export class SkillStore extends UiErrorState<HttpError> {
});
this.skill = SkillModel.empty();
this.skillsHttpRepository = new SkillsHttpRepository();
this.skillSocketRepository.on(this.socketUpdate);
makeAutoObservable(this);
}
socketUpdate = (data: ProcessUpdate) => {
this.skils?.map((el) => {
if (el._id.isEqual(data.id)) {
el.processStatus = data.status;
}
return el;
});
};
getSkillById = (id: string) => this.skils?.find((el) => el._id === id);
continueSkill = async (id: string) => {
const skill = this.getSkillById(id) as ISkils;
skill.processStatus = "new";
skill.processStatus = "before_training";
skill.numberOfTrainedEpochs += skill.epoch;
await this.skillsHttpRepository.editSkill(skill);
this.messageHttp(this.skillsHttpRepository.execSkill(id), {
await this.messageHttp(this.skillsHttpRepository.execSkill(id), {
errorMessage: "Ошибка",
successMessage: "Обучение продолжено",
});
@ -54,6 +63,7 @@ export class SkillStore extends UiErrorState<HttpError> {
execSkill = async (id: string) => {
const skill = this.getSkillById(id) as ISkils;
skill.processStatus = "exec";
skill.numberOfTrainedEpochs = skill.epoch;
await this.skillsHttpRepository.editSkill(skill);
this.messageHttp(this.skillsHttpRepository.execSkill(id), {
errorMessage: "Ошибка",
@ -72,7 +82,6 @@ export class SkillStore extends UiErrorState<HttpError> {
}
changeEpoch(epoch: number) {
this.skill.epoch = epoch;
}
saveSkill() {
this.skill.project = this.activeProjectId?.id ?? "";
@ -94,6 +103,7 @@ export class SkillStore extends UiErrorState<HttpError> {
this.skill.datasetId = id;
}
edtDrawer(drawerName: DrawersSkill, status: boolean): void {
this.titleDrawer = drawerName;
this.drawers = this.drawers.map((el) => {
if (el.name === drawerName) {
el.status = status;
@ -101,4 +111,20 @@ export class SkillStore extends UiErrorState<HttpError> {
return el;
});
}
deleteSkill = async (id: string): Promise<void> => {
await this.skillsHttpRepository.deleteSkill(id);
await this.init();
};
fromEditSkill(id: string): void {
this.skill = SkillModel.fromISkill(this.getSkillById(id) as ISkils);
this.edtDrawer(DrawersSkill.EDIT_SKILL, true);
}
saveEdiSkill = async () => {
const skillOrigin = this.getSkillById(this.skill.id as string) as ISkils;
skillOrigin.numberOfTrainedEpochs = this.skill.epoch;
await this.skillsHttpRepository.editSkill(skillOrigin);
this.edtDrawer(DrawersSkill.EDIT_SKILL, false);
};
}

View file

@ -8,6 +8,9 @@ export interface ISocketListerProps {
}
export const SocketLister = observer((props: ISocketListerProps) => {
React.useEffect(() => {
socketListerStore.init();
}, []);
return (
<div>
{/* {socketListerStore.socketHasDisconnect ? (