Skip to content

Commit

Permalink
add experiment types and dto
Browse files Browse the repository at this point in the history
  • Loading branch information
matvey.samokhin committed Mar 21, 2024
1 parent 3565c2c commit 73d6fb2
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/models/experiment.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {ModelInterface} from "../types/model.type";
import {ModelDTO} from "../types/dto/model.dto";
import {EncoderBaseType, ExperimentInterface, ParameterType} from "../types/experiment.type";
import {ExperimentDTO} from "../types/dto/experiment.dto";

export class ExperimentClass implements ExperimentInterface {
uuid: string
featureName: string
encoder: EncoderBaseType
serializedData: string[]

constructor(dto: ExperimentDTO, id?: string) {
this.uuid = dto.uuid || id
this.featureName = dto.featureName || ''
this.encoder = dto.encoder || { name: '', parameters: [] }
this.serializedData = dto.serializedData || []
}
}
20 changes: 20 additions & 0 deletions src/repositories/experiment.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {baseModelUrl} from "../api/constants";
import {BaseRepository, ResolverMethods} from "./base.repository";
import {ModelObjects, ModelObjectsDTO, ModelObjectsType} from "../types/dto/model.dto";
import {ExperimentDTO, ExperimentObject} from "../types/dto/experiment.dto";
import {ExperimentType} from "../types/experiment.type";

export class ExperimentRepository extends BaseRepository {
static readonly defaultUrl = `${baseModelUrl}/models/`;
Expand All @@ -15,6 +17,24 @@ export class ExperimentRepository extends BaseRepository {
ExperimentRepository.controllerCheckStateModel = new AbortController();
}

static addExperiment(id: string) {
return ExperimentRepository.resolve({
url: ``,
queryParams: {experiment_id: id},
method: ResolverMethods.post
})
}

static getExperimentResult(id: string) {
return ExperimentRepository.resolve<ExperimentDTO, ExperimentObject>({
url: ``,
queryParams: {experiment_id: id},
method: ResolverMethods.get,
model: ExperimentObject,
modelType: ExperimentType,
})
}

static getObjects(id: string) {
return ExperimentRepository.resolve<ModelObjectsDTO, ModelObjects>({
url: `${id}`,
Expand Down
15 changes: 15 additions & 0 deletions src/types/dto/experiment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as t from 'io-ts';
import {Experiment, ExperimentType} from "../experiment.type";
import {ExperimentClass} from "../../models/experiment.model";

export type ExperimentDTO = t.TypeOf<typeof ExperimentType>;

class ExperimentObject {
experiments: Experiment;

constructor(dto: ExperimentDTO) {
this.experiments = new ExperimentClass(dto);
}
}

export { ExperimentObject };
44 changes: 44 additions & 0 deletions src/types/experiment.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as t from 'io-ts';

export const ParamType = t.type({
name: t.union([t.string, t.undefined]),
value: t.union([t.string, t.record(t.string, t.string)]),
type: t.union([t.string, t.undefined]),
})

export const EncoderType = t.type({
name: t.string,
parameters: t.array(ParamType),
})

export const ExperimentType = t.type({
uuid: t.string,
featureName: t.string,
encoder: EncoderType,
serializedData: t.array(t.string)
})

export type ParameterType = {
name: string,
value?: string | Record<string, string>,
type?: string,
}

export type EncoderBaseType = {
name: string,
parameters: ParameterType[]
}

export type Experiment = {
uuid: string,
featureName: string,
encoder: EncoderBaseType,
serializedData: string[]
}

export interface ExperimentInterface {
uuid: string,
featureName: string,
encoder: EncoderBaseType,
serializedData: string[]
}

0 comments on commit 73d6fb2

Please sign in to comment.