progress
This commit is contained in:
parent
e005a42254
commit
e155b4a2a1
26 changed files with 468 additions and 36 deletions
|
@ -1,9 +1,15 @@
|
|||
import { BehaviorTreesPresentation } from "../../features/behavior_trees/behavior_trees";
|
||||
import { DatasetsPresentation } from "../../features/datasets/datasets_presentation";
|
||||
import { WeightsPresentation } from "../../features/weights/weights_presentation";
|
||||
import { ProjectsPresentation } from "../../features/projects/projects_presentation";
|
||||
import { extensions } from "../extensions/extensions";
|
||||
import { Routes } from "../interfaces/router";
|
||||
|
||||
extensions();
|
||||
|
||||
export const httpRoutes: Routes[] = [new ProjectsPresentation(), new DatasetsPresentation(), new BehaviorTreesPresentation()].map((el) => el.call());
|
||||
export const httpRoutes: Routes[] = [
|
||||
new ProjectsPresentation(),
|
||||
new DatasetsPresentation(),
|
||||
new BehaviorTreesPresentation(),
|
||||
new WeightsPresentation(),
|
||||
].map((el) => el.call());
|
||||
|
|
|
@ -9,11 +9,15 @@ import { IProjectModel, ProjectDBModel } from "../../_projects/models/project_da
|
|||
import { DatasetDBModel } from "../models/dataset_database_model";
|
||||
import { DatasetValidationModel, ProcessStatus } from "../models/dataset_validation_model";
|
||||
|
||||
export class ProcessWatcherAndDatabaseUpdateService extends TypedEvent<Result<ExecError | SpawnError, ExecutorResult>> {
|
||||
export class ProcessWatcherAndDatabaseUpdateService<A> extends TypedEvent<
|
||||
Result<ExecError | SpawnError, ExecutorResult>
|
||||
> {
|
||||
databaseId: ObjectId;
|
||||
constructor(databaseId: ObjectId) {
|
||||
model: A;
|
||||
constructor(databaseId: ObjectId, model: A) {
|
||||
super();
|
||||
this.databaseId = databaseId;
|
||||
this.model = model;
|
||||
this.on((event) => this.lister(event));
|
||||
}
|
||||
|
||||
|
@ -21,7 +25,9 @@ export class ProcessWatcherAndDatabaseUpdateService extends TypedEvent<Result<Ex
|
|||
event.fold(
|
||||
async (success) => {
|
||||
if (success.event == EXEC_EVENT.END) {
|
||||
const dbModel = await DatasetDBModel.findById(this.databaseId);
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
const dbModel = await this.model.findById(this.databaseId);
|
||||
if (dbModel !== null) {
|
||||
dbModel.local_path;
|
||||
dbModel.processStatus = ProcessStatus.END;
|
||||
|
@ -31,7 +37,9 @@ export class ProcessWatcherAndDatabaseUpdateService extends TypedEvent<Result<Ex
|
|||
}
|
||||
},
|
||||
async (error) => {
|
||||
const dbModel = await DatasetDBModel.findById(this.databaseId);
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
const dbModel = await this.model.findById(this.databaseId);
|
||||
if (dbModel !== null) {
|
||||
dbModel.processStatus = ProcessStatus.ERROR;
|
||||
dbModel.processLogs = error.message;
|
||||
|
|
|
@ -14,14 +14,13 @@ export class ExecDatasetProcessScenario extends CallbackStrategyWithIdQuery {
|
|||
return (await new ReadByIdDataBaseModelUseCase<IDatasetModel>(DatasetDBModel).call(id)).map(async (model) => {
|
||||
return (await new IsHaveActiveProcessUseCase().call()).map(async () => {
|
||||
await DatasetDBModel.findById(id).updateOne({ processStatus: "RUN" });
|
||||
console.log(`blenderproc run $PYTHON_BLENDER_PROC --cfg '${JSON.stringify(model)}'`);
|
||||
return new ExecProcessUseCase().call(
|
||||
`${model.project.rootDir}/`,
|
||||
`blenderproc run $PYTHON_BLENDER_PROC --cfg '${JSON.stringify(model)}'`,
|
||||
id,
|
||||
new ProcessWatcherAndDatabaseUpdateService(id as unknown as ObjectId)
|
||||
new ProcessWatcherAndDatabaseUpdateService(id as unknown as ObjectId, DatasetDBModel)
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Mongoose, Schema, model } from "mongoose";
|
||||
import { Schema, model } from "mongoose";
|
||||
import { IDatasetModel } from "./dataset_validation_model";
|
||||
import { projectSchema } from "../../_projects/models/project_database_model";
|
||||
|
||||
|
||||
export const DatasetSchema = new Schema({
|
||||
name: {
|
||||
type: String,
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
import { ObjectId } from "mongoose";
|
||||
import { CallbackStrategyWithIdQuery, ResponseBase } from "../../../core/controllers/http_controller";
|
||||
import { Result } from "../../../core/helpers/result";
|
||||
import { ExecProcessUseCase, IsHaveActiveProcessUseCase } from "../../../core/usecases/exec_process_usecase";
|
||||
import { ReadByIdDataBaseModelUseCase } from "../../../core/usecases/read_by_id_database_model_usecase";
|
||||
import { MongoIdValidation } from "../../../core/validations/mongo_id_validation";
|
||||
import { ProcessWatcherAndDatabaseUpdateService } from "../../datasets/domain/create_dataset_scenario";
|
||||
import { WeightDBModel, IWeightModel } from "../models/weights_validation_model";
|
||||
|
||||
export class ExecWeightProcessScenario extends CallbackStrategyWithIdQuery {
|
||||
idValidationExpression = new MongoIdValidation();
|
||||
call = async (id: string): ResponseBase => {
|
||||
return (await new ReadByIdDataBaseModelUseCase<IWeightModel>(WeightDBModel).call(id)).map(async (model) => {
|
||||
return (await new IsHaveActiveProcessUseCase().call()).map(async () => {
|
||||
await WeightDBModel.findById(id).updateOne({ processStatus: "RUN" });
|
||||
|
||||
if (typeof model.project === "object" && typeof model.datasetId === "object") {
|
||||
console.log(
|
||||
`python3 $PYTHON_EDUCATION --path ${model.project.rootDir} --name ${model.name} --datasetName ${model.datasetId.name}`
|
||||
);
|
||||
return new ExecProcessUseCase().call(
|
||||
`${model.project.rootDir}/`,
|
||||
`python3 $PYTHON_EDUCATION --path ${model.project.rootDir} --name ${model.name} --datasetName ${model.datasetId.name}`,
|
||||
id,
|
||||
new ProcessWatcherAndDatabaseUpdateService(id as unknown as ObjectId, WeightDBModel)
|
||||
);
|
||||
}
|
||||
return Result.error("model project is not object");
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
11
server/src/features/weights/models/weights_database_model.ts
Normal file
11
server/src/features/weights/models/weights_database_model.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { IsMongoId, IsString } from "class-validator";
|
||||
import { IWeightModel } from "./weights_validation_model";
|
||||
|
||||
export class WeightValidationModel implements IWeightModel {
|
||||
@IsString()
|
||||
public name: string;
|
||||
@IsMongoId()
|
||||
public datasetId: string;
|
||||
@IsMongoId()
|
||||
public project: string;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
import { Schema, model } from "mongoose";
|
||||
import { IProjectModel, projectSchema } from "../../_projects/models/project_database_model";
|
||||
import { datasetSchema } from "../../datasets/models/dataset_database_model";
|
||||
import { IDatasetModel } from "../../datasets/models/dataset_validation_model";
|
||||
|
||||
export interface IWeightModel {
|
||||
name: string;
|
||||
datasetId: string | IDatasetModel;
|
||||
project: string | IProjectModel;
|
||||
}
|
||||
export const WeightSchema = new Schema({
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
local_path: {
|
||||
type: String,
|
||||
},
|
||||
neuralNetworkName: {
|
||||
type: String,
|
||||
},
|
||||
processStatus: {
|
||||
type: String,
|
||||
default: "none",
|
||||
},
|
||||
// the user selects
|
||||
isFinished: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
datasetId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: datasetSchema,
|
||||
autopopulate: true,
|
||||
require: true,
|
||||
},
|
||||
project: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: projectSchema,
|
||||
autopopulate: true,
|
||||
require: true,
|
||||
},
|
||||
processLogs: {
|
||||
type: String,
|
||||
},
|
||||
}).plugin(require("mongoose-autopopulate"));
|
||||
|
||||
export const weightSchema = "Weight";
|
||||
|
||||
export const WeightDBModel = model<IWeightModel>(weightSchema, WeightSchema);
|
19
server/src/features/weights/weights_presentation.ts
Normal file
19
server/src/features/weights/weights_presentation.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { CrudController } from "../../core/controllers/crud_controller";
|
||||
import { ExecWeightProcessScenario } from "./domain/exec_weights_process_scenario";
|
||||
import { WeightValidationModel } from "./models/weights_database_model";
|
||||
import { WeightDBModel } from "./models/weights_validation_model";
|
||||
|
||||
export class WeightsPresentation extends CrudController<WeightValidationModel, typeof WeightDBModel> {
|
||||
constructor() {
|
||||
super({
|
||||
url: "weights",
|
||||
validationModel: WeightValidationModel,
|
||||
databaseModel: WeightDBModel,
|
||||
});
|
||||
this.subRoutes.push({
|
||||
method: "GET",
|
||||
subUrl: "exec",
|
||||
fn: new ExecWeightProcessScenario(),
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue