MCWS mit JAM (Stefan Bosse) [8.2020] |
1
2
3
Shell({
verbose:1
});
▸
|
✗
|
1
2
3
4
port(DIR.IP('https://localhost:*'));
locate(print);
connect(DIR.IP('https://ag-0.de:30101?secure=12:34:56:78'));
start()
▸
|
✗
|
Der Explorationagent besucht über den Relaisknoten alle verbundenen Geräte (Smartphones, Notebooks, usw.) nach einander!
Da die JAM Plattform im WEB Browser ausgeführt wird (Endgeräte), kann es passieren dass die Seite (App) mit einem oder mehreren Explorationsagenten "darin" geschlossen wird. Die Agenten sind verloren!
Damit Zwischenergebnisse der Exploration gesichert werden repliziert sich der Explorationagent bevor er einen neuen Knoten besucht.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function explorer (options) {
// 1. Körpervariablen (Inhalte sind mobil)
this.rootNode=null;
this.visited=[];
// Sensors of current node
this.sensors={};
// Hier werden alle Sensor- und Umfrageergebnisse gesammelt
this.collect=[];
this.verbose = 1;
this.currentNode = null;
this.path = [];
this.nextNode = null;
this.hops = 0;
this.maxHops = 200;
this.timeout = options.timeout||30000;
this.todo = null;
this.alreadyVisited = false;
// Optional survey script
this.survey = options.survey;
// Dialog Map mit zusätzlichen Labelreferenzen
this.dialog = null;
this.index = 0;
this.token = null;
this.tokenTrials = 0;
// Antworten werden zu this.sensors.answers hinzugefügt
// Dialog Label Mapper
this.dialogMap = function (dialog) {
var map={};
iter(dialog,function (entry,index) {
map[index]=entry;
if (entry.label) map[entry.label]=entry;
});
return map;
}
// 2. Aktivitäten
this.act = {
init : function () {
this.rootNode = myNode();
log('Starting on '+this.rootNode);
this.path.push(this.rootNode);
this.sensors={};
if (this.survey)
this.dialog = this.dialogMap(this.survey.dialog);
},
percept : function () {
var loc,self=this;
this.currentNode = myNode();
log('PERCEPT on '+this.currentNode);
this.tokenTrials=0;
this.alreadyVisited=contains(this.visited,this.currentNode);
if (!this.alreadyVisited) {
// Neuer Knoten
this.visited.push(this.currentNode);
this.sensors = {};
this.sensors.clock=clock(true);
this.sensors.path=copy(this.path);
this.sensors.node=this.currentNode;
this.sensors.chat=test(['CHAT',_]);
// Infos von der aktuellen Plattform?
loc=info('node').location;
if (loc && loc.gps)
this.sensors.gps=[loc.gps.lat,loc.gps.lon,'@IP'];
loc=info('node').location;
if (loc && loc.gps5)
this.sensors.gps5=[loc.gps5.lat,loc.gps5.lon];
loc=info('node').location;
if (loc && loc.geo)
this.sensors.location=[loc.geo.city,
loc.geo.zip,
_,_,
loc.geo.country];
loc=info('node').location;
if (loc && loc.geo5)
this.sensors.location5=[loc.geo5.city,
loc.geo5.zip,
loc.geo5.street,
loc.geo5.number,
loc.geo5.country];
this.collect.push(this.sensors);
} else this.sensors={};
var next = filter(link(DIR.IP('%')),this.visited);
if (next.length) {
// explore next node
this.nextNode=random(next);
} else {
// go one step back
this.nextNode=null;
}
},
explore : function () {
if (link(DIR.NODE(this.nextNode))) {
log('GO to '+this.nextNode);
this.hops++;
this.path.push(this.nextNode);
moveto(DIR.NODE(this.nextNode));
▸
|
✗
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
survey = {
author : 'Student',
// Ab hier kommt der Dialog:
dialog : [
{label:'QA', question: 'Wie alt sind Sie?', range:[1,99], step:1 },
{label:'QF', question: 'Welche Speisen essen Sie?',
choices: ['vegetarisch',
'vegan',
'Fleisch',
'Fisch'],
cond: function (dialog) {
return dialog.QA.answer>=18
}},
{label:'QL', question: 'Nennen Sie Ihre Lieblingsspeise:' },
{message:'Danke!'},
],
}
print('Done.')
▸
|
✗
|
1
2
3
4
create('explorer',{
survey:survey,
timeout:60000,
},1);
▸
|
✗
|
DELIVER #
) können die Ergebenisse aus dem Tupelraum entnommen werden1
2
3
4
var results = inp(['COLLECT',_,_]);
if (results) results=results[2];
global.results=results;
print(results);
▸
|
✗
|
1
2
3
4
5
6
7
8
var results = global.results.map(function (sample) {
var sample=copy(sample);
if (sample.answers) sample=Object.assign(sample,sample.answers);
return sample;
});
Table(results,
['location','location5','gps','gps5','clock',
'QA','QF','QL']);
▸
|
✗
|
1
2
3
if (typeof counter == 'undefined') counter=0;
counter++;
Save(global.results,'survey'+counter+'.json')
▸
|
✗
|