Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4 from moserle/master
Browse files Browse the repository at this point in the history
add new 'createImagesAction'
  • Loading branch information
0x00b1 authored Jun 16, 2019
2 parents 6da82bc + adf687a commit ccce0d7
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/actions/classifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const createImageAction = createAction(
'create-image'
);

export const createImagesAction = createAction(
'create-images'
);

export const createImageScoreAction = createAction(
'create-image-score'
);
Expand Down
2 changes: 2 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
createCategoryAction,
createImageAction,
createImagesAction,
createImageScoreAction,
createClassifierAction,
openClassifierAction,
Expand All @@ -20,6 +21,7 @@ import {
export {
createCategoryAction,
createImageAction,
createImagesAction,
createImageScoreAction,
createClassifierAction,
openClassifierAction,
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
createCategoryAction,
createImageAction,
createImagesAction,
createImageScoreAction,
createClassifierAction,
deleteImageAction,
Expand All @@ -26,6 +27,7 @@ export {
createCategoryAction,
createClassifierAction,
createImageAction,
createImagesAction,
createImageScoreAction,
deleteCategoryAction,
deleteImageAction,
Expand Down
135 changes: 135 additions & 0 deletions src/reducers/classifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createClassifierAction,
openClassifierAction,
createImageAction,
createImagesAction,
createImageScoreAction,
deleteCategoryAction,
deleteImageAction,
Expand Down Expand Up @@ -334,6 +335,140 @@ describe('classifierReducer', () => {
expect(reducer).toEqual(expected);
});

it('createImagesAction', () => {
const state: Classifier = {
categories: [
{
description: 'Unknown',
identifier: '00000000-0000-0000-0000-000000000000',
index: 0,
visualization: {
color: 'rgb(233, 165, 177)',
visible: true
}
}
],
images: [
{
categoryIdentifier: '00000000-0000-0000-0000-000000000000',
checksum: '',
data: '',
identifier: '11111111-1111-1111-1111-11111111111',
partition: Partition.Training,
scores: [],
visualization: {
brightness: 0,
contrast: 0,
visible: true,
visibleChannels: []
}
}
],
name: 'Untitled classifier'
};

const images: Image[] = [
{
categoryIdentifier: '00000000-0000-0000-0000-000000000000',
checksum: '',
data: '',
identifier: '11111111-1111-1111-2222-11111111111',
partition: Partition.Training,
scores: [],
visualization: {
brightness: 0,
contrast: 0,
visible: true,
visibleChannels: []
}
},
{
categoryIdentifier: '00000000-0000-0000-0000-000000000000',
checksum: '',
data: '',
identifier: '11111111-1111-1111-333-11111111111',
partition: Partition.Training,
scores: [],
visualization: {
brightness: 0,
contrast: 0,
visible: true,
visibleChannels: []
}
}
];

const payload = {
images: images
};

const action = createImagesAction(payload);

const reducer = classifierReducer(state, action);

const expected: Classifier = {
categories: [
{
description: 'Unknown',
identifier: '00000000-0000-0000-0000-000000000000',
index: 0,
visualization: {
color: 'rgb(233, 165, 177)',
visible: true
}
}
],
images: [
{
categoryIdentifier: '00000000-0000-0000-0000-000000000000',
checksum: '',
data: '',
identifier: '11111111-1111-1111-1111-11111111111',
partition: Partition.Training,
scores: [],
visualization: {
brightness: 0,
contrast: 0,
visible: true,
visibleChannels: []
}
},
{
categoryIdentifier: '00000000-0000-0000-0000-000000000000',
checksum: '',
data: '',
identifier: '11111111-1111-1111-2222-11111111111',
partition: Partition.Training,
scores: [],
visualization: {
brightness: 0,
contrast: 0,
visible: true,
visibleChannels: []
}
},
{
categoryIdentifier: '00000000-0000-0000-0000-000000000000',
checksum: '',
data: '',
identifier: '11111111-1111-1111-333-11111111111',
partition: Partition.Training,
scores: [],
visualization: {
brightness: 0,
contrast: 0,
visible: true,
visibleChannels: []
}
}
],
name: 'Untitled classifier'
};

expect(reducer).toEqual(expected);
});


it('createImageScoreAction', () => {
const state: Classifier = {
categories: [
Expand Down
6 changes: 6 additions & 0 deletions src/reducers/classifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
createClassifierAction,
openClassifierAction,
createImageAction,
createImagesAction,
createImageScoreAction,
deleteCategoryAction,
deleteImageAction,
Expand Down Expand Up @@ -89,6 +90,11 @@ export const classifierReducer = createReducer(initialState, {

state.images.push(image);
},
[createImagesAction.toString()]: (state, action) => {
const { images } = action.payload;

images.forEach( (image: Image) => state.images.push(image));
},
[createImageScoreAction.toString()]: (state, action) => {
const { identifier, score } = action.payload;

Expand Down

0 comments on commit ccce0d7

Please sign in to comment.