Skip to content

Commit

Permalink
Added region to input.
Browse files Browse the repository at this point in the history
  • Loading branch information
rok-povsic committed Apr 9, 2018
1 parent d45a914 commit ddee366
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"del": "^2.0.2",
"envify": "^3.4.0",
"git-branch": "^0.3.0",
"gulp": "^3.9.0",
"gulp": "^3.9.1",
"gulp-awspublish": "^3.0.1",
"gulp-babel": "^6.1.2",
"gulp-browserify": "^0.5.1",
Expand Down
4 changes: 4 additions & 0 deletions src/Input.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let axios = require('axios');
let Concepts = require('./Concepts');
let Regions = require('./Regions');
let {API} = require('./constants');
let {INPUTS_PATH} = API;

Expand All @@ -13,6 +14,9 @@ class Input {
this.createdAt = data.created_at || data.createdAt;
this.imageUrl = data.data.image.url;
this.concepts = new Concepts(_config, data.data.concepts);
if (data.data.regions) {
this.regions = new Regions(_config, data.data.regions);
}
this.score = data.score;
this.metadata = data.data.metadata;
if (data.data.geo && data.data.geo['geo_point']) {
Expand Down
2 changes: 1 addition & 1 deletion src/Inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class Inputs {
}

/**
* @param {object[]} inputs List of concepts to update (max of 128 inputs/call; passing > 128 will throw an exception)
* @param {object[]} inputs List of inputs to update (max of 128 inputs/call; passing > 128 will throw an exception)
* @param {object} inputs[].input
* @param {string} inputs[].input.id The id of the input to update
* @param {object} inputs[].input.metadata Object with key values to attach to the input (optional)
Expand Down
16 changes: 16 additions & 0 deletions src/Region.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Region / bounding box. Region points are percentages from the edge.
* E.g. top of 0.2 means the cropped input will start 20% down from the original edge.
* @class
*/
class Region {
constructor(_config, data) {
this.id = data.id;
this.top = data.region_info.bounding_box.top_row;
this.left = data.region_info.bounding_box.left_col;
this.bottom = data.region_info.bounding_box.bottom_row;
this.right = data.region_info.bounding_box.right_col;
}
}

module.exports = Region;
25 changes: 25 additions & 0 deletions src/Regions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let Region = require('./Region');

/**
* A collection of regions.
* @class
*/
class Regions {
constructor(_config, rawData = []) {
this._config = _config;
this.rawData = rawData;
rawData.forEach((regionData, index) => {
this[index] = new Region(this._config, regionData);
});
this.length = rawData.length;
}

[Symbol.iterator]() {
let index = -1;
return {
next: () => ({ value: this[++index], done: index >= this.length })
};
};
}

module.exports = Regions;

0 comments on commit ddee366

Please sign in to comment.