Skip to content

Commit 916adf6

Browse files
add interaction storage
1 parent 35e3f90 commit 916adf6

File tree

8 files changed

+59
-38
lines changed

8 files changed

+59
-38
lines changed
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.nyc_output/c4bd4fa8-e4f6-4862-a8b1-9cdde18ed8e1.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/environment.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function Environment(type) {
55

66
}
77

8+
// simulation run
9+
810
// simulation time
911

1012
module.exports = Environment;

lib/index.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
1+
'use strict'
22
const uuid = require('uuid-v4');
33
const moment = require('moment');
44
const topsis = require('topsis');
5+
const ahp = require('ahp-lite');
56

67
const EventEmitter = require('events');
78

8-
const CapitalizeFirstLetterOfString = require('capitalizefirstletterofstring');
9+
//const CapitalizeFirstLetterOfString = require('capitalizefirstletterofstring');
910

10-
/*
11-
class need {
11+
class Interaction {
12+
constructor(msg,evnt,from,to,time) {
13+
this.from = from;
14+
this.to = to;
15+
this.evnt = evnt;
16+
this.msg = msg;
17+
this.time = time;
18+
}
1219
}
13-
*/
1420

1521
class Agent extends EventEmitter {
1622
constructor(name) {
1723
super();
1824
this.id = uuid();
1925
this.name = name;
20-
this.stimuli = {};
21-
this.message = '';
2226
this.isAlive = false;
27+
this.interactions = new Set();
2328

24-
this.needs = [];
2529
}
2630

27-
/*
28-
addNeed() {
29-
this.needs.push(new need);
30-
}
31-
*/
3231

3332

3433
start() {
@@ -45,32 +44,37 @@ class Agent extends EventEmitter {
4544

4645
tell(evnt, to) {
4746
if (this.isAlive === true) {
48-
console.log(to.name);
49-
to.emit(`${evnt.name}From${CapitalizeFirstLetterOfString(to.name)}`, evnt.msg);
47+
to.emit(evnt.name, evnt.msg);
48+
let time = moment().format();
49+
let interaction = new Interaction(evnt.msg, evnt.name, this.id, to.id, time);
50+
this.interactions.add(interaction);
5051
} else {
5152
return console.log(`Error. ${this.name} is not alive`);
5253
}
5354
}
54-
55+
56+
store(msg, evnt, from, to) {
57+
let time = moment().format();
58+
let interaction = new Interaction(msg, evnt, from, to, time);
59+
this.interactions.add(interaction);
60+
return this.interactions;
61+
}
5562

5663
decide(method, data) {
5764
switch (method) {
5865
case 'topsis':
5966
const result = topsis.getBest(data.m, data.w, data.ia);
6067
return result;
6168
break;
69+
case 'ahp':
70+
const result = ahp.getWeights(data.c);
71+
return result;
72+
break;
6273
}
6374
}
6475

65-
predict(method, data) {
66-
switch (method) {
67-
case 'linear-regression':
6876

69-
break;
70-
}
71-
}
7277

73-
//
7478
} // END AGENT
7579

76-
module.exports = Agent;
80+
module.exports = Agent, Interaction;

package-lock.json

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aopifyjs",
3-
"version": "0.1.7",
3+
"version": "0.1.9",
44
"description": "Agent-oriented programming in Javascript.",
55
"main": "./lib/index.js",
66
"scripts": {
@@ -47,6 +47,7 @@
4747
"nyc": "^13.1.0"
4848
},
4949
"dependencies": {
50+
"ahp-lite": "^1.2.1",
5051
"capitalizefirstletterofstring": "^1.1.0",
5152
"moment": "^2.23.0",
5253
"topsis": "^1.2.11",

test/test.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
const assert = require('assert');
22

3-
const Agent = require('../lib/index.js');
43
const EventEmitter = require('events');
4+
const Agent = require('../lib/index.js');
55

6-
const jorgito = new Agent('jorgito');
7-
const juana = new Agent('juana');
86

97

108

9+
const jorgito = new Agent('jorgito');
10+
const juana = new Agent('juana');
1111

1212

1313

1414
describe('Init', () => {
1515
it('It should create an agent object.', () => {
16-
console.log(jorgito);
16+
console.log(jorgito);
1717
assert.equal(jorgito, jorgito);
1818
});
19-
});
19+
})
20+
2021

21-
describe('EmitbutDeath1', () => {
22-
it('It should return an error alert because Juana is not alive', () => {
23-
console.log('JORGITO: Hola Juana');
24-
assert.equal('test', 'test');
25-
});
26-
});
2722

2823
describe('StartJorgito', () => {
2924
it('It should retrieve a true state.', () => {
@@ -32,11 +27,15 @@ describe('StartJorgito', () => {
3227
});
3328
});
3429

30+
31+
3532
describe('EmitbutDeath2', () => {
3633
it('It should return an error alert because Juana is not alive', () => {
3734
console.log('JORGITO: Hola Juana');
3835
jorgito.tell({name: 'event', msg: 'Hola Juana'}, juana);
3936
assert.equal('test', 'test');
37+
38+
console.log(juana,jorgito);
4039
});
4140
});
4241

@@ -56,6 +55,13 @@ describe('EmitandAlive', () => {
5655
});
5756
});
5857

58+
describe('EmitandAlive', () => {
59+
it('Juan should return the message', () => {
60+
console.log('JORGITO: Hola Juana');
61+
assert.equal('test', 'test');
62+
});
63+
});
64+
5965

6066
describe('Kill', () => {
6167
it('It should retrieve isAlive as false.', () => {

0 commit comments

Comments
 (0)