-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f70407
commit 03c98af
Showing
15 changed files
with
318 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import API from '../../APICore'; | ||
import Resource from '../Resource'; | ||
import {MLModelCreated, RegistrationModel} from './MachineLearningInterfaces'; | ||
import ModelInformation from './ModelInformation/ModelInformation'; | ||
import Models from './Models/Models'; | ||
|
||
export default class MachineLearning extends Resource { | ||
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/machinelearning`; | ||
|
||
models: Models; | ||
modelInfo: ModelInformation; | ||
|
||
constructor(protected api: API) { | ||
super(api); | ||
|
||
this.models = new Models(api); | ||
this.modelInfo = new ModelInformation(api); | ||
} | ||
|
||
register(registration: RegistrationModel) { | ||
return this.api.post<MLModelCreated>(`${MachineLearning.baseUrl}/model`, registration); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/resources/MachineLearning/MachineLearningInterfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {IdAndDisplayNameModel} from '../BaseInterfaces'; | ||
import {MLModel} from './Models/ModelsInterfaces'; | ||
|
||
export interface RegistrationModel { | ||
engineId: string; | ||
modelName: string; | ||
modelDisplayName?: string; | ||
exportPeriod: string; | ||
intervalTime: number; | ||
intervalUnit: 'DAY' | 'WEEK' | 'MONTH'; | ||
exportOffset?: string; | ||
apiKeysThatCanEdit?: IdAndDisplayNameModel[]; | ||
groupsThatCanEdit?: IdAndDisplayNameModel[]; | ||
commandLineParameters?: string[]; | ||
commonFilter?: string; | ||
customEventFilter?: string; | ||
searchEventFilter?: string; | ||
viewEventFilter?: string; | ||
versionMatcher?: string; | ||
} | ||
|
||
export interface MLModelCreated extends MLModel { | ||
endTime?: number; | ||
startTime?: number; | ||
resourceId?: string; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/resources/MachineLearning/ModelInformation/ModelInformation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import API from '../../../APICore'; | ||
import Resource from '../../Resource'; | ||
import {RegistrationModel} from '../MachineLearningInterfaces'; | ||
import {MLModel} from '../Models/ModelsInterfaces'; | ||
import {MLModelInfo} from './ModelInformationInterfaces'; | ||
|
||
export default class ModelInformation extends Resource { | ||
static getBaseUrl = (engineId: string, modelName: string) => | ||
`/rest/organizations/${API.orgPlaceholder}/machinelearning/engines/${engineId}/models/${modelName}`; | ||
|
||
get(engineId: string, modelName: string) { | ||
return this.api.get<MLModelInfo>(`${ModelInformation.getBaseUrl(engineId, modelName)}/details`); | ||
} | ||
|
||
delete(engineId: string, modelName: string) { | ||
return this.api.delete(ModelInformation.getBaseUrl(engineId, modelName)); | ||
} | ||
|
||
update(engineId: string, modelName: string, modelInformation: RegistrationModel) { | ||
return this.api.put<Partial<MLModel>>(ModelInformation.getBaseUrl(engineId, modelName), modelInformation); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/resources/MachineLearning/ModelInformation/ModelInformationInterfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface MLModelInfo { | ||
id: string; | ||
info?: {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './ModelInformation'; | ||
export * from './ModelInformationInterfaces'; |
57 changes: 57 additions & 0 deletions
57
src/resources/MachineLearning/ModelInformation/tests/ModelInformation.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import API from '../../../../APICore'; | ||
import {RegistrationModel} from '../../MachineLearningInterfaces'; | ||
import ModelInformation from '../ModelInformation'; | ||
|
||
jest.mock('../../../../APICore'); | ||
|
||
const APIMock: jest.Mock<API> = API as any; | ||
|
||
describe('ModelInformation', () => { | ||
let modelInfo: ModelInformation; | ||
const api = new APIMock() as jest.Mocked<API>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
modelInfo = new ModelInformation(api); | ||
}); | ||
|
||
describe('get', () => { | ||
it('should make a GET call to the specific ModelInformation url', () => { | ||
const engineId = 'O. O'; | ||
const modelName = 'O .O'; | ||
|
||
modelInfo.get(engineId, modelName); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${ModelInformation.getBaseUrl(engineId, modelName)}/details`); | ||
}); | ||
}); | ||
|
||
describe('delete', () => { | ||
it('should make a DELETE call to the specific ModelInformation url', () => { | ||
const engineId = 'OAO'; | ||
const modelName = 'QAQ'; | ||
|
||
modelInfo.delete(engineId, modelName); | ||
expect(api.delete).toHaveBeenCalledTimes(1); | ||
expect(api.delete).toHaveBeenCalledWith(ModelInformation.getBaseUrl(engineId, modelName)); | ||
}); | ||
}); | ||
|
||
describe('update', () => { | ||
it('should make a PUT call to the specific ModelInformation url', () => { | ||
const engineId = '-_-'; | ||
const modelName = '@_@'; | ||
const modelInformation: RegistrationModel = { | ||
engineId: 'O_O', | ||
modelName: 'mini model', | ||
exportPeriod: 'XYZ', | ||
intervalTime: 999, | ||
intervalUnit: 'WEEK', | ||
}; | ||
|
||
modelInfo.update(engineId, modelName, modelInformation); | ||
expect(api.put).toHaveBeenCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith(ModelInformation.getBaseUrl(engineId, modelName), modelInformation); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import API from '../../../APICore'; | ||
import Resource from '../../Resource'; | ||
import {MLModelInfo} from '../ModelInformation/ModelInformationInterfaces'; | ||
import {MLModel} from './ModelsInterfaces'; | ||
|
||
export default class Models extends Resource { | ||
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/machinelearning/models`; | ||
|
||
list() { | ||
return this.api.get<MLModel[]>(Models.baseUrl); | ||
} | ||
|
||
listDetails() { | ||
return this.api.get<MLModel[]>(`${Models.baseUrl}/details`); | ||
} | ||
|
||
get(modelId: string) { | ||
return this.api.get<MLModelInfo>(`${Models.baseUrl}/${modelId}/details`); | ||
} | ||
|
||
delete(modelId: string) { | ||
return this.api.delete(`${Models.baseUrl}/${modelId}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {IdAndDisplayNameModel} from '../../BaseInterfaces'; | ||
import {MLModelInfo} from '../ModelInformation/ModelInformationInterfaces'; | ||
|
||
export interface MLModel extends MLModelInfo { | ||
orgId: string; | ||
id: string; | ||
engineId: string; | ||
modelName: string; | ||
modelDisplayName?: string; | ||
modelCreationTime: number; | ||
nextModelUpdateTime?: number; | ||
modelVersion?: string; | ||
engineVersion?: string; | ||
platformVersion?: 1 | 2; | ||
versionMatcher?: string; | ||
apiKeysThatCanEdit?: IdAndDisplayNameModel[]; | ||
groupsThatCanEdit?: IdAndDisplayNameModel[]; | ||
modelErrorDescription?: ModelErrorDescription; | ||
previousModelUpdateTime?: number; | ||
intervalTime: number; | ||
intervalUnit: 'DAY' | 'WEEK' | 'MONTH'; | ||
exportPeriod: string; | ||
exportOffset?: string; | ||
status: | ||
| 'DELETED' | ||
| 'SCHEDULING' | ||
| 'SCHEDULED' | ||
| 'ERROR' | ||
| 'PENDING' | ||
| 'REGISTERED' | ||
| 'PAUSED' | ||
| 'REGISTERING' | ||
| 'IN_PROGRESS' | ||
| 'ERROR_DELETING' | ||
| 'ONLINE' | ||
| 'OFFLINE' | ||
| 'IN_CREATION'; | ||
commandLineParameters?: string[]; | ||
commonFilter?: string; | ||
customEventFilter?: string; | ||
searchEventFilter?: string; | ||
viewEventFilter?: string; | ||
} | ||
|
||
export interface ModelErrorDescription { | ||
customer_errors?: CustomerError[]; | ||
} | ||
|
||
export interface CustomerError { | ||
description?: string; | ||
errorCode?: string; | ||
errorType?: string; | ||
precision?: string; | ||
troubleshoot?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './Models'; | ||
export * from './ModelsInterfaces'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import API from '../../../../APICore'; | ||
import Models from '../Models'; | ||
|
||
jest.mock('../../../../APICore'); | ||
|
||
const APIMock: jest.Mock<API> = API as any; | ||
|
||
describe('Models', () => { | ||
let models: Models; | ||
const api = new APIMock() as jest.Mocked<API>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
models = new Models(api); | ||
}); | ||
|
||
describe('list', () => { | ||
it('should make a GET call to the Models base url', () => { | ||
models.list(); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(Models.baseUrl); | ||
}); | ||
}); | ||
|
||
describe('listDetails', () => { | ||
it('should make a GET call to the specific Models url', () => { | ||
models.listDetails(); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Models.baseUrl}/details`); | ||
}); | ||
}); | ||
|
||
describe('get', () => { | ||
it('should make a GET call to the specific Models url', () => { | ||
const modelId = 'O. O'; | ||
|
||
models.get(modelId); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Models.baseUrl}/${modelId}/details`); | ||
}); | ||
}); | ||
|
||
describe('delete', () => { | ||
it('should make a DELETE call to the specific Models url', () => { | ||
const modelId = 'O .O'; | ||
|
||
models.delete(modelId); | ||
expect(api.delete).toHaveBeenCalledTimes(1); | ||
expect(api.delete).toHaveBeenCalledWith(`${Models.baseUrl}/${modelId}`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './MachineLearning'; | ||
export * from './MachineLearningInterfaces'; | ||
export * from './Models/'; | ||
export * from './ModelInformation/'; |
33 changes: 33 additions & 0 deletions
33
src/resources/MachineLearning/tests/MachineLearning.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import API from '../../../APICore'; | ||
import MachineLearning from '../MachineLearning'; | ||
import {RegistrationModel} from '../MachineLearningInterfaces'; | ||
|
||
jest.mock('../../../APICore'); | ||
|
||
const APIMock: jest.Mock<API> = API as any; | ||
|
||
describe('MachineLearning', () => { | ||
let ml: MachineLearning; | ||
const api = new APIMock() as jest.Mocked<API>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
ml = new MachineLearning(api); | ||
}); | ||
|
||
describe('register', () => { | ||
it('should make a POST call to the specific MachineLearning url', () => { | ||
const registration: RegistrationModel = { | ||
engineId: 'OvO', | ||
modelName: 'super model', | ||
exportPeriod: 'ABC', | ||
intervalTime: 666, | ||
intervalUnit: 'DAY', | ||
}; | ||
|
||
ml.register(registration); | ||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith(`${MachineLearning.baseUrl}/model`, registration); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters