Skip to content
Snippets Groups Projects
Commit 8c05686f authored by Ugo Albanese's avatar Ugo Albanese
Browse files

Merged in revert-NRRPLT-8011 (pull request #115)

Revert "Merged in NRRPLT-8011 (pull request #113)"

This reverts commit eba68361.

Approved-by: Stefano Nardo
Approved-by: Manos Angelidis
parent eba68361
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
REPOSITORY=$1
FILENAME_XSD=$2
TOPIC_BRANCH=$3
wget https://api.bitbucket.org/2.0/repositories/hbpneurorobotics/${REPOSITORY}/src/${TOPIC_BRANCH}/${FILENAME_XSD} -O ${FILENAME_XSD} \
&& echo ${FILENAME_XSD}:${TOPIC_BRANCH}
...@@ -12,16 +12,6 @@ if [ -f .ci/env ]; then ...@@ -12,16 +12,6 @@ if [ -f .ci/env ]; then
source '.ci/env' source '.ci/env'
fi fi
# Obtain schemas
mkdir -p xsds && cd xsds
REPOSITORY=experiments
[ -z "$(git ls-remote --heads https://bitbucket.org/hbpneurorobotics/${REPOSITORY}.git ${TOPIC_BRANCH})" ] \
&& CO_BRANCH="${DEFAULT_BRANCH}" \
|| CO_BRANCH="${TOPIC_BRANCH}"
bash ../.ci/bitbucket_api_get.bash "${REPOSITORY}" ExDConfFile.xsd "${CO_BRANCH}"
cat ExDConfFile.xsd
cd ..
. $HOME/.bashrc . $HOME/.bashrc
source $HOME/.nvm/nvm.sh && nvm alias default 8 && nvm use default source $HOME/.nvm/nvm.sh && nvm alias default 8 && nvm use default
......
...@@ -33,7 +33,6 @@ pipeline { ...@@ -33,7 +33,6 @@ pipeline {
stages { stages {
stage('Code checkout') { stage('Code checkout') {
steps { steps {
sh 'rm -rf *'
// Notify BitBucket on the start of the job // Notify BitBucket on the start of the job
// The Bitbucket Build Status Notifier is used // The Bitbucket Build Status Notifier is used
// REF: https://plugins.jenkins.io/bitbucket-build-status-notifier/ // REF: https://plugins.jenkins.io/bitbucket-build-status-notifier/
...@@ -66,9 +65,9 @@ pipeline { ...@@ -66,9 +65,9 @@ pipeline {
} }
post { post {
// always { always {
// cleanWs() cleanWs()
// } }
aborted { aborted {
bitbucketStatusNotify(buildState: 'FAILED', buildDescription: 'Build aborted!') bitbucketStatusNotify(buildState: 'FAILED', buildDescription: 'Build aborted!')
} }
......
...@@ -12,15 +12,14 @@ ...@@ -12,15 +12,14 @@
"body-parser": "^1.17.2", "body-parser": "^1.17.2",
"csv-stringify": "^2.0.4", "csv-stringify": "^2.0.4",
"dateformat": "2.0.0", "dateformat": "2.0.0",
"express": "^4.17.1", "express": "4.14.1",
"file-base64": "1.0.0", "file-base64": "1.0.0",
"firebase-admin": "^6.0.0", "firebase-admin": "^6.0.0",
"fs-extra": "^5.0.0", "fs-extra": "^5.0.0",
"glob": "7.1.1", "glob": "7.1.1",
"iplocation": "^5.0.1", "iplocation": "^5.0.1",
"jszip": "^3.1.5", "jszip": "^3.1.5",
"libxmljs2-xsd": "^0.26.5", "lodash": "4.17.4",
"lodash": "^4.17.20",
"log-prefix": "0.0.0", "log-prefix": "0.0.0",
"mime-types": "^2.1.17", "mime-types": "^2.1.17",
"minimist": "^1.2.0", "minimist": "^1.2.0",
...@@ -34,12 +33,13 @@ ...@@ -34,12 +33,13 @@
"rewire": "^2.5.2", "rewire": "^2.5.2",
"rmdir": "^1.2.0", "rmdir": "^1.2.0",
"shelljs": "^0.8.1", "shelljs": "^0.8.1",
"tingodb": "^0.6.1", "tingodb": "^0.5.1",
"tmp": "0.0.33", "tmp": "0.0.33",
"uuid": "^3.2.1", "uuid": "^3.2.1",
"walk": "^2.3.14", "walk": "^2.3.14",
"x2js": "^3.2.3", "x2js": "^3.2.3",
"xml2js": "0.4.17", "xml2js": "0.4.17",
"xml4js": "^0.1.3",
"zip-a-folder": "0.0.8" "zip-a-folder": "0.0.8"
}, },
"devDependencies": { "devDependencies": {
......
...@@ -35,8 +35,7 @@ let utils = require('../storage/FS/utils').default, ...@@ -35,8 +35,7 @@ let utils = require('../storage/FS/utils').default,
const fs = require('fs'), const fs = require('fs'),
q = require('q'), q = require('q'),
path = require('path'), path = require('path'),
readFile = q.denodeify(fs.readFile), readFile = q.denodeify(fs.readFile);
xsd = require('libxmljs2-xsd');
configurationManager.initialize(); configurationManager.initialize();
let storageRequestHandler; let storageRequestHandler;
...@@ -117,19 +116,7 @@ export default class ExperimentsService { ...@@ -117,19 +116,7 @@ export default class ExperimentsService {
? utils.storagePath ? utils.storagePath
: this.experimentsPath, : this.experimentsPath,
expPath = path.dirname(fileConfigPath); expPath = path.dirname(fileConfigPath);
// TODO: Parse the exc and bibi with the proper nodeJS xsd parser
// XSD validation and parsing if possible
let xsdSchemaLocation;
try {
xsdSchemaLocation = `${__dirname}/../xsds/ExDConfFile.xsd`;
const schema = xsd.parseFile(xsdSchemaLocation);
const validationErrors = schema.validate(experimentContent);
if (validationErrors)
console.warn(`Warning, xml validation of file ${fileName} against the xsd schema ${xsdSchemaLocation} failed due to Error: ${validationErrors}. XSD or XML are likely malformed. Falling back to parsing the xml without xsd validation.`);
} catch (err) {
console.warn(`Could not parse xsd with location ${xsdSchemaLocation}. Error that was thrown: ${err}`);
}
const exc: any = new X2JS().xml2js(experimentContent); const exc: any = new X2JS().xml2js(experimentContent);
return q.when(exc.ExD) return q.when(exc.ExD)
.then(exc => .then(exc =>
......
<?xml version="1.0" encoding="utf-8"?>
<ExD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.humanbrainproject.eu/SP10/2014/ExDConfig"
xsi:schemaLocation="http://schemas.humanbrainproject.eu/SP10/2014/ExDConfig ../ExDConfFile.xsd">
<name>Template Husky in empty environment</name>
<thumbnail>test.png</thumbnail>
<description>This experiment loads the Husky robot in an empty world, with an idle brain and basic transfer functions. You are free to edit it.</description>
<timeout>840</timeout>
<configuration type="3d-settings" src="ExDTemplateHusky.3ds"/>
<maturity>production</maturity>
<environmentModel src="environments/biologylab_world/model.config">
<robotPose robotId="test" x="0.0" y="0.0" z="0.5" ux="0.0" uy="0.0" uz="0.0" theta="0.0"/>
</environmentModel>
<bibiConf src="template_husky.bibi"/>
<test>test</test>
<cameraPose>
<cameraPosition x="4.5" y="0" z="1.8"/>
<cameraLookAt x="0" y="0" z="0.6"/>
</cameraPose>
</ExD>
<?xml version="1.0" encoding="UTF-8"?>
<bibi xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.humanbrainproject.eu/SP10/2014/BIBI" xsi:schemaLocation="http://schemas.humanbrainproject.eu/SP10/2014/BIBI ../bibi_configuration.xsd">
<brainModel>
<file>brains/braitenberg.py</file>
<populations population="sensors" xsi:type="Range" from="0" to="5"/>
<populations population="actors" xsi:type="Range" from="5" to="8"/>
<populations population="record" xsi:type="Range" from="0" to="8"/>
</brainModel>
<bodyModel robotId="test">robots/husky_model/model.config</bodyModel>
<transferFunction xsi:type="Neuron2Monitor" name="all_neurons_spike_monitor">
<device name="all_neurons" type="SpikeRecorder">
<neurons xsi:type="Range" population="record" from="0" to="8" step="1"/>
</device>
</transferFunction>
<transferFunction xsi:type="PythonTransferFunction" src="braitenberg_husky_linear_twist.py"/>
<transferFunction xsi:type="PythonTransferFunction" src="tf_folder/nested_tf.py"/>
<transferFunction xsi:type="PythonTransferFunction">
#<![CDATA[
@nrp.MapRobotSubscriber("camera", Topic('/husky/camera', sensor_msgs.msg.Image))
@nrp.MapSpikeSource("red_left_eye", nrp.brain.sensors[slice(0, 3, 2)], nrp.poisson)
@nrp.MapSpikeSource("red_right_eye", nrp.brain.sensors[slice(1, 4, 2)], nrp.poisson)
@nrp.MapSpikeSource("green_blue_eye", nrp.brain.sensors[4], nrp.poisson)
@nrp.Robot2Neuron()
def eye_sensor_transmit(t, camera, red_left_eye, red_right_eye, green_blue_eye):
"""
This transfer function uses OpenCV to compute the percentages of red pixels
seen by the robot on his left and on his right. Then, it maps these percentages
(see decorators) to the neural network neurons using a Poisson generator.
"""
bridge = CvBridge()
red_left = red_right = green_blue = 0.0
if not isinstance(camera.value, type(None)):
# Boundary limits of what we consider red (in HSV format)
lower_red = np.array([0, 30, 30])
upper_red = np.array([0, 255, 255])
# Get an OpenCV image
cv_image = bridge.imgmsg_to_cv2(camera.value, "rgb8")
# Transform image to HSV (easier to detect colors).
hsv_image = cv2.cvtColor(cv_image, cv2.COLOR_RGB2HSV)
# Create a mask where every non red pixel will be a zero.
mask = cv2.inRange(hsv_image, lower_red, upper_red)
image_size = (cv_image.shape[0] * cv_image.shape[1])
if (image_size > 0):
# Since we want to get left and right red values, we cut the image
# in 2.
half = cv_image.shape[1] // 2
# Get the number of red pixels in the image.
red_left = cv2.countNonZero(mask[:, :half])
red_right = cv2.countNonZero(mask[:, half:])
# We have to multiply the red rates by 2 since it is for an
# half image only. We also multiply all of them by 1000 so that
# we have enough spikes produced by the Poisson generator
red_left_eye.rate = 2 * 1000 * (red_left / float(image_size))
red_right_eye.rate = 2 * 1000 * (red_right / float(image_size))
green_blue_eye.rate = 75 * ((image_size - (red_left + red_right)) / float(image_size))
#]]>
</transferFunction>
</bibi>
...@@ -3,12 +3,9 @@ ...@@ -3,12 +3,9 @@
const chai = require('chai'), const chai = require('chai'),
rewire = require('rewire'), rewire = require('rewire'),
path = require('path'), path = require('path'),
sinon = require('sinon'),
expect = chai.expect; expect = chai.expect;
let consoleMock = { warn: sinon.spy(), log: sinon.spy() };
const experimentsPaths = 'test/data/experiments'; const experimentsPaths = 'test/data/experiments';
const experimentWithMalformedEXC = 'test/data/experiments/malformedExc';
const expectedExp1 = { const expectedExp1 = {
id: 'ExDTemplateHusky', id: 'ExDTemplateHusky',
...@@ -49,26 +46,6 @@ const expectedExp2 = { ...@@ -49,26 +46,6 @@ const expectedExp2 = {
visualModel: undefined, visualModel: undefined,
visualModelParams: undefined visualModelParams: undefined
}; };
const expectedExpMalformed = {
id: 'ExDMalformed',
name: 'Template Husky in empty environment',
isShared: false,
thumbnail: 'test.png',
path: 'experiment1',
tags: [],
description:
'This experiment loads the Husky robot in an empty world, with an idle brain and basic transfer functions. You are free to edit it.',
experimentConfiguration: 'experiment1/ExDMalformed.exc',
maturity: 'production',
timeout: 840,
physicsEngine: 'ode',
robotPaths: { test: 'robots/husky_model/model.config' },
brainProcesses: 1,
cameraPose: [4.5, 0, 1.8, 0, 0, 0.6],
visualModel: undefined,
visualModelParams: undefined
};
let confFilePath = path.join(__dirname, '../utils/config.json'), let confFilePath = path.join(__dirname, '../utils/config.json'),
configurationManagerRewire = rewire('../../utils/configurationManager'), configurationManagerRewire = rewire('../../utils/configurationManager'),
configurationManager = configurationManagerRewire.default; configurationManager = configurationManagerRewire.default;
...@@ -114,12 +91,6 @@ describe('TemplateExperimentsService', () => { ...@@ -114,12 +91,6 @@ describe('TemplateExperimentsService', () => {
visualModelParams: undefined visualModelParams: undefined
}; };
beforeEach(() => {
ExperimentsService.__set__('console', consoleMock);
consoleMock.warn.reset();
consoleMock.log.reset();
});
it('should get the shared experiment path properly', () => { it('should get the shared experiment path properly', () => {
var expectedResult = var expectedResult =
'test/data/sharedExperiments/experimentPath/experimentFile'; 'test/data/sharedExperiments/experimentPath/experimentFile';
...@@ -189,19 +160,4 @@ describe('TemplateExperimentsService', () => { ...@@ -189,19 +160,4 @@ describe('TemplateExperimentsService', () => {
return expect(experiments[1]).to.deep.equal(expectedExp2); return expect(experiments[1]).to.deep.equal(expectedExp2);
}); });
}); });
it('should test that the xsd validation throws a warning if the .exc is not valid', () => {
experimentsService = new ExperimentsService.default(
confMock,
experimentWithMalformedEXC
);
return experimentsService.loadExperiments().then(experiments => {
sinon.assert.calledWithMatch(
consoleMock.warn,
'XSD or XML are likely malformed.'
);
return expect(experiments[0]).to.deep.equal(expectedExpMalformed);
});
});
}); });
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment