Skip to content

Commit d6cd331

Browse files
committed
Merge branch 'dev'
2 parents 7a337dd + 3b0e24e commit d6cd331

9 files changed

Lines changed: 44 additions & 44 deletions

File tree

‎app/public/js/runExperiment/preRun/selectExperiment.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ const runExperiment = () => {
3838
let experiments = experimentPagination.results;
3939
let experiment = experiments[selectedExperimentIndex];
4040

41-
console.log(dummyConfiguration);
42-
43-
InitSimulation.prepareAndRunSimulation(dummyConfiguration);
41+
InitSimulation.prepareAndRunSimulation(experiment);
4442
}
4543

4644
// EVENTS

‎app/public/js/runExperiment/simulator/init/Init.js‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
const canvas = document.querySelector('canvas');
44
const c = canvas.getContext('2d');
55
const WORLD = new World();
6+
const EXPERIMENT_DETAILS = {
7+
id : undefined, name : undefined
8+
};
69

710
const colorPalettes = [
811
['skyblue','rgba(0,0,255,0.1)' ],
912
['orange' ,'rgba(255,100,0,0.1)' ],
1013
['lawngreen' , 'rgba(0,255,0,0.1)' ],
1114
['violet' , 'rgba(255,0,200,0.1)' ],
1215
['red' , 'rgba(200,0,0,0.1)' ]
13-
14-
1516
];
1617

1718
var ECOSYSTEM;
@@ -29,16 +30,23 @@ class Init{
2930

3031
}
3132

32-
prepareAndRunSimulation(experimentSetUp){
33+
prepareAndRunSimulation(experiment){
34+
35+
// Relevant details for identification
3336

34-
this.setColorToSpecies(experimentSetUp.species);
35-
36-
console.log(experimentSetUp.species);
37+
EXPERIMENT_DETAILS.id = experiment._id;
38+
EXPERIMENT_DETAILS.name = experiment.name;
39+
40+
this.setColorToSpecies(experiment.species);
41+
42+
// Data models and schemas initialization
3743

3844
this.initAgentTypes();
3945
this.initCollections();
4046

41-
ECOSYSTEM = new Ecosystem(WORLD, experimentSetUp);
47+
ECOSYSTEM = new Ecosystem(WORLD, experiment);
48+
49+
// Functional modules and communication logic initialization
4250

4351
this.initServices();
4452
this.initEvents();

‎app/public/js/runExperiment/simulator/init/initAgentTypes.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Init.prototype.initAgentTypes = () => {
2-
2+
3+
//NOTE: It would be better to have explicit data types for each field, as that would make agents less prone to having fields with incorrect data
4+
35
WORLD.registerAgentType('Consumer', {
46
info: {
57
pos : {x : 0, y : 0},
@@ -11,8 +13,16 @@ Init.prototype.initAgentTypes = () => {
1113
foodFee : 1,
1214
foodCount : 0,
1315

16+
// used to choose which prey to chase
17+
18+
targetPrey : undefined,
19+
shortestDistanceToPrey : undefined,
20+
1421
maxEnergy : 30000,
1522
energy : 30000,
23+
24+
// inheritable traits
25+
1626
maxSpeed : 0,
1727
sensitivity : 0
1828
},

‎app/public/js/runExperiment/simulator/init/initEvents.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ Init.prototype.initEvents = () => {
1212
WORLD.registerEvent('newGenerationReady');
1313
WORLD.registerServiceToEvent('AgentBehaviour','newGenerationReady');
1414

15-
WORLD.registerEvent('Test');
16-
WORLD.registerServiceToEvent('AgentBehaviour','Test');
17-
1815
WORLD.registerEvent('simulationOver');
16+
WORLD.registerServiceToEvent('DataSend','simulationOver');
1917
}
2018

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Init.prototype.initServices = () => {
22

3-
WORLD.registerService('Renderer', new Renderer(c));
4-
WORLD.registerService('Motion', new Motion());
3+
WORLD.registerService('Renderer', new Renderer(c));
4+
WORLD.registerService('Motion', new Motion());
55
WORLD.registerService('AgentBehaviour', new AgentBehaviour(ECOSYSTEM));
6-
WORLD.registerService('Statistics' , new Statistics(ECOSYSTEM));
6+
WORLD.registerService('Statistics' , new Statistics(ECOSYSTEM));
77
WORLD.registerService('Generations', new Generations(ECOSYSTEM));
8-
8+
WORLD.registerService('DataSend', new DataSend(ECOSYSTEM));
99
}

‎app/public/js/runExperiment/simulator/layers/Ecosystem/Ecosystem.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// NOTE: Ecosystem is a layer built over the framework utilized: CASES, if there is a problem with the framework or it isn't present, the logic at Ecosystem wont work
2+
13
class Ecosystem {
24

35
#species;

‎app/public/js/runExperiment/simulator/layers/Ecosystem/OrganismBuilder.js‎

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ class OrganismBuilder {
4040

4141
TreeObject.addChild(organism,'sensitivityRange',sensitivityRange);
4242
}
43+
4344
// Has movement ?
4445

45-
if(organism.maxSpeed > 0){
46-
this.world.addToCollection('Kinetics',organism);
47-
}
46+
if(organism.maxSpeed > 0) this.world.addToCollection('Kinetics',organism);
4847

4948
// aspect
5049

@@ -96,29 +95,10 @@ class OrganismBuilder {
9695

9796
var specieAttributes = this.ecosystem.getSpecie(specieName);
9897

99-
if(specieAttributes.organismType == 'consumer'){
100-
return this.generateConsumer(specieName, attributes);
101-
}
102-
if(specieAttributes.organismType == 'producer'){
103-
return this.generateProducer(specieName);
104-
}
105-
106-
107-
// Organism aspect
108-
109-
let aspect = WORLD.createAgent('Circle', {
110-
'info' : {
111-
pos: organism.pos,
112-
background : specieAttributes.colorA
113-
}
114-
});
115-
116-
TreeObject.addChild(organism,'aspect',aspect);
117-
118-
98+
if(specieAttributes.organismType == 'consumer') return this.generateConsumer(specieName, attributes);
99+
if(specieAttributes.organismType == 'producer') return this.generateProducer(specieName);
119100

120-
organism.specie = specieName;
121-
return organism;
101+
throw Error(`An invalid organism type was specified for specie '${specieName}'; it is not either producer or consumer`);
122102
}
123103

124104

‎app/public/js/runExperiment/simulator/services/DataSend.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ class DataSend extends Service{
1515
'Content-Type' : 'application/json'
1616
},
1717
body : JSON.stringify({
18-
experimentID : '1234',
18+
19+
// NOTE: there is coupling between the Datasend module and EXPERIMENT_DETAILS
20+
21+
experimentID : EXPERIMENT_DETAILS.id,
1922
results : data,
2023
date : new Date()
2124
})

‎app/views/runExperiment.ejs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<script src="/js/runExperiment/simulator/services/AgentBehaviour.js"></script>
7878
<script src="/js/runExperiment/simulator/services/Generations.js"></script>
7979
<script src="/js/runExperiment/simulator/services/Statistics.js"></script>
80+
<script src="/js/runExperiment/simulator/services/DataSend.js"></script>
8081

8182
<!--utils-->
8283

0 commit comments

Comments
 (0)