forked from Noxeangel/DEMOG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment.js
203 lines (184 loc) · 6.81 KB
/
experiment.js
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
function ISODateString(d){
function pad(n){return n<10 ? '0'+n : n}
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
+ pad(d.getUTCDate())+'T'
+ pad(d.getUTCHours())+':'
+ pad(d.getUTCMinutes())+':'
+ pad(d.getUTCSeconds())+'Z'
}
var Experiment = function (xpName, xpType, xpMaxIter,xpGame,lang,timeout)
{
this.GAME_TYPES = ["space_coop","rabbits","dg"];
this.TYPES = ["local","amazon","web"];
this.LANG = ["fr","en"];
this.xpName = xpName;
this.xpType = undefined;
this.xpGame = undefined;
this.isRunning = false;
this.launchDate = ISODateString(new Date());
this.timeout = timeout * 1000; // to get timeout in ms
this.language = this.LANG[1];
this.result = new XPResults();
for(var i = 0 ; i < this.TYPES.length ; i++)
{
if(xpType == this.TYPES[i]) { this.xpType = xpType; }
}
for(var i = 0 ; i < this.GAME_TYPES.length ; i++)
{
if(xpGame == this.GAME_TYPES[i]) { this.xpGame = xpGame; }
}
for(var i = 0 ; i < this.LANG.length ; i++)
{
if(lang == this.LANG[i]) { this.language = lang; }
}
if(xpMaxIter > 0) { this.xpMaxIter = xpMaxIter; }
else { this.xpMaxIter = 1; }
if(this.xpType == undefined) { throw("Experiment type unrecognized. Unable to create. \n Try with one of these types : " + this.TYPES.toString()); }
if(this.xpGame == undefined) { throw("Game unrecognized. Unable to create. \n Try with one of these games : " + this.GAME_TYPES.toString()); }
this.xpLink = this.generateLink();
};
Experiment.prototype.generateLink = function ()
{
if(this.xpGame == "space_coop")
{
return ('/home1');
}
else if(this.xpGame == "rabbits")
{
return ('/home3');
}
else if(this.xpGame == "dg")
{
return ('/home5');
}
};
Experiment.prototype.startXP = function()
{
this.isRunning = true;
this.launchDate = ISODateString(new Date());
this.initResults(this.xpName, this.xpType, this.xpMaxIter, this.xpGame, this.launchDate);
};
Experiment.prototype.stopXP = function()
{
this.isRunning = false;
this.result.endDate = new Date();
};
Experiment.prototype.exportResults = function()
{
if(this.isRunning == true)
{
console.log("////////////////////XP RESULTS////////////////////");
console.log("/////////////////////WARNING//////////////////////");
console.log("// THIS EXPERIMENT IS STILL RUNNING !!")
console.log("/////////////////////WARNING//////////////////////");
console.log(this.result);
console.log("////////////////////////END///////////////////////");
}
else
{
console.log("////////////////////XP RESULTS////////////////////");
console.log(this.result);
for(var i = 0 ; i < this.result.playerResults.length; i ++)
{
console.log(this.result.playerResults[i]);
}
console.log("////////////////////////END///////////////////////");
}
};
Experiment.prototype.initResults = function(xpName, xpType, xpMaxIter, xpGame, xpDate)
{
this.result.xpName = xpName;
this.result.xpType = xpType;
this.result.xpGame = xpGame;
this.result.xpMaxIter = xpMaxIter;
this.result.beginDate = xpDate;
this.result.playerResults = [];
this.result.gameResults = [];
};
Experiment.prototype.addPlayerResults = function(playerResults)
{
this.result.playerResults.push(playerResults);
};
Experiment.prototype.addGameResultsRabbits = function(gameId, gamescore, player1, player2, sharer, given, kept,inputP1,inputP2,p1MissedSeesaw,p2MissedSeesaw,p1DistanceSeesaw,p2DistanceSeesaw, p1BalloonsPopped,p2BalloonsPopped, gameLength, shareSteps, p1AmazonId, p2AmazonId, proposerMturkId, responderMturkId)
{
this.result.gameResults.push(new gameResultRabbits(gameId, gamescore, player1, player2, sharer, given, kept,inputP1,inputP2,p1MissedSeesaw,p2MissedSeesaw,p1DistanceSeesaw,p2DistanceSeesaw, p1BalloonsPopped,p2BalloonsPopped, gameLength, shareSteps, p1AmazonId, p2AmazonId, proposerMturkId, responderMturkId));
};
Experiment.prototype.addGameResultsSpace = function(gameId, gamescore, player1, player2, sharer, given, kept,inputP1,inputP2, p1ShotsFired, p2ShotsFired, p1EnemyKilled, p2EnemyKilled, p1DistanceToMothership, p2DistanceToMothership, gameLength, gotMothership, shareSteps, p1amazonId, p2amazonId, proposerMturkId, responderMturkId)
{
this.result.gameResults.push(new gameResultSpace(gameId, gamescore, player1, player2, sharer, given, kept,inputP1,inputP2, p1ShotsFired, p2ShotsFired, p1EnemyKilled, p2EnemyKilled, p1DistanceToMothership, p2DistanceToMothership, gameLength, gotMothership, shareSteps, p1amazonId, p2amazonId, proposerMturkId, responderMturkId));
};
Experiment.prototype.returnOldCLientsNum = function()
{
if(this.result.playerResults.length)
{
return(this.result.playerResults.length);
}
else
{
return(0);
}
};
function XPResults()
{
this.xpName ;
this.xpType ;
this.xpGame ;
this.xpMaxIter ;
this.beginDate ;
this.endDate = undefined;
this.playerResults;
this.gameResults;
}
var gameResultRabbits = function(gameId, gameScore, player1, player2, sharer, given, kept, inputP1, inputP2, p1MissedSeesaw, p2MissedSeesaw, p1DistanceSeesaw, p2DistanceSeesaw, p1BalloonsPopped, p2BalloonsPopped, gameLength, shareSteps, p1AmazonId, p2AmazonId, proposerMturkId, responderMturkId)
{
this.gameId = gameId;
this.date = ISODateString(new Date());
this.p1Id = player1;
this.p2Id = player2;
this.p1MturkId = p1AmazonId;
this.p2MturkId = p2AmazonId;
this.proposerId = sharer;
this.proposerMturkId = proposerMturkId;
this.responderMturkId = responderMturkId;
this.given = given;
this.kept = kept;
this.p1MissedSeesaw = p1MissedSeesaw;
this.p2MissedSeesaw = p2MissedSeesaw;
this.p1DistanceSeesaw = p1DistanceSeesaw;
this.p2DistanceSeesaw = p2DistanceSeesaw;
this.p1BalloonsPopped = p1BalloonsPopped;
this.p2BalloonsPopped = p2BalloonsPopped;
this.gameLength = gameLength;
this.shareSteps = shareSteps;
this.p1Input = inputP1;
this.p2Input = inputP2;
};
var gameResultSpace = function(gameId, gameScore, player1, player2, sharer, given, kept, inputP1, inputP2, p1ShotsFired, p2ShotsFired, p1EnemyKilled, p2EnemyKilled, p1DistanceToMothership, p2DistanceToMothership, gameLength, gotMothership, shareSteps, p1AmazonId, p2AmazonId, proposerMturkId, responderMturkId)
{
this.gameId = gameId;
this.date = ISODateString(new Date());
this.p1Id = player1;
this.p2Id = player2;
this.p1MturkId = p1AmazonId;
this.p2MturkId = p2AmazonId;
this.proposerId = sharer;
this.proposerMturkId = proposerMturkId;
this.responderMturkId = responderMturkId;
this.given = given;
this.kept = kept;
this.p1ShotsFired = p1ShotsFired;
this.p2ShotsFired = p2ShotsFired;
this.p1EnemyKilled = p1EnemyKilled;
this.p2EnemyKilled = p2EnemyKilled;
this.p1DistanceToMothership = p1DistanceToMothership;
this.p2DistanceToMothership = p2DistanceToMothership;
this.gameLength = gameLength;
this.gotMothership = gotMothership;
this.shareSteps = shareSteps;
this.p1Input = inputP1;
this.p2Input = inputP2;
};
if( 'undefined' != typeof global ) {
module.exports = global.Experiment = Experiment;
}