From 7576b6ca05512ce54e35e5c5f64997af8e9317bc Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Fri, 9 Oct 2015 09:34:27 +0200 Subject: [PATCH] Corrected a bug, improved analysis --- analysis/lib.js | 25 +++++++++++++-- analysis/matlab/script.m | 19 +++++++++--- analysis/matlab/table.m | 8 +++++ analysis/matlab/timecoins.m | 44 +++++++++++++++++++++++++++ analysis/timeBetweenTwoCoins.js | 47 +++++++++++++++++++++++++++++ controllers/prototype/dbrequests.js | 1 + 6 files changed, 136 insertions(+), 8 deletions(-) create mode 100644 analysis/matlab/table.m create mode 100644 analysis/matlab/timecoins.m create mode 100644 analysis/timeBetweenTwoCoins.js diff --git a/analysis/lib.js b/analysis/lib.js index 3f9221a..5bc290b 100644 --- a/analysis/lib.js +++ b/analysis/lib.js @@ -174,9 +174,28 @@ Lib.numberOfInteraction = function(exp) { } } - - - return i; }; + +Lib.durationBetweenCoins = function(exp) { + + var ret = []; + var events = exp.elements.events; + var lastTime = events[0].time; + var ids = []; + + for (var i = 0; i < events.length; i++) { + var event = events[i]; + if (event.type === 'coin') { + if (ids.indexOf(event.id) === -1) { + ids.push(event.id); + ret.push(Lib.timeDifference(lastTime, event.time)); + lastTime = event.time; + } + } + } + + return ret; + +}; diff --git a/analysis/matlab/script.m b/analysis/matlab/script.m index b59012f..323831c 100644 --- a/analysis/matlab/script.m +++ b/analysis/matlab/script.m @@ -1,7 +1,16 @@ -var; +timecoins; plot(X,Y1); hold on; -plot(X, Y2, 'red'); -hold on; -plot(X, Y3, 'green'); -legend('Without recommendation', 'Worst with recommendation', 'Best with recommendation'); +names = who('Y*'); + +N = size(names, 1); + +for i = 1:N, + name = names(i) + name = name{1}; + plot(X, eval(name)); + pause + clf +end + +close all; diff --git a/analysis/matlab/table.m b/analysis/matlab/table.m new file mode 100644 index 0000000..2536bff --- /dev/null +++ b/analysis/matlab/table.m @@ -0,0 +1,8 @@ +X = [ 0 1 2 3 4 5 6 7 ]; + +Y1 = [ 770 368 277 180 361 189 137 198 ]; + +Y2 = [ 444 224 437 214 345 159 201 114 ]; + +Y3 = [ 427 168 437 137 345 127 64 114 ]; + diff --git a/analysis/matlab/timecoins.m b/analysis/matlab/timecoins.m new file mode 100644 index 0000000..67d852c --- /dev/null +++ b/analysis/matlab/timecoins.m @@ -0,0 +1,44 @@ +X = [ 0 1 2 3 4 5 6 7 ]; + +Y1 = [ 3068 9946 3634 4027 9753 11505 6507 93235 ]; + +Y2 = [ 2789 11895 10008 4944 23040 25736 90313 30974 ]; + +Y3 = [ 6414 11518 4577 26118 8629 18662 77239 39086 ]; + +Y4 = [ 7070 4095 9949 5162 4389 52880 53789 3704 ]; + +Y5 = [ 8288 1973 3047 5335 28975 11402 1323 29225 ]; + +Y6 = [ 4512 2627 11536 9231 1770 6568 1559 71200 ]; + +Y7 = [ 7277 25015 9905 5433 7887 4711 2827 19877 ]; + +Y8 = [ 8197 16319 7969 5113 4970 143998 114894 5803 ]; + +Y9 = [ 44253 1303 718 544 772 22305 574 925 ]; + +Y10 = [ 39705 703 603 12045 61187 2950 2333 Inf ]; + +Y11 = [ 12821 5736 4465 29048 1369 3951 35108 25275 ]; + +Y12 = [ 95786 3499 5134 1272 1068 1031 917 897 ]; + +Y13 = [ 2066 10052 22932 1413 8777 20339 46760 54828 ]; + +Y14 = [ 10480 2647 2386 10853 4771 5069 7630 16776 ]; + +Y15 = [ 7528 10848 2836 16234 13345 14158 20331 5378 ]; + +Y16 = [ 5106 1355 6797 3039 21677 14987 27681 3628 ]; + +Y17 = [ 8655 3581 7869 7049 10186 7133 2617 Inf ]; + +Y18 = [ 3617 1516 8342 4511 1490 1748 6360 7718 ]; + +Y19 = [ 8890 1567 5736 10528 4161 1554 11644 78341 ]; + +Y20 = [ 4755 4872 2905 4616 4898 2549 26217 2158 ]; + +Y21 = [ 6185 14015 5533 7327 1237 7990 6032 38959 ]; + diff --git a/analysis/timeBetweenTwoCoins.js b/analysis/timeBetweenTwoCoins.js new file mode 100644 index 0000000..8cb064d --- /dev/null +++ b/analysis/timeBetweenTwoCoins.js @@ -0,0 +1,47 @@ +// Shows with and without : time to last coin = f(CoinCombination) + +var lib = require('./lib.js'); + + +function main(path) { + + var db = lib.loadFromFile(path); + var groups = lib.makeGroups(db); + + // Erase groups that are not usable + groups = groups.filter(function(elt) { + + // An elt is valid if it contains at least 2 exp, BaseRecommendation included + return elt.length > 1 && elt.find(function(e) { return e.recommendation_style[4] === 'B'; }) !== undefined; + + }); + + console.log(lib.toMatlabArray('X', lib.range(0,8))); + + var counter = 0; + groups.forEach(function(elt) { + elt.sort(lib.compareRecommendationStyle); + elt.forEach(function(elt) { + elt.durationBetweenCoins = lib.durationBetweenCoins(elt); + + console.log(lib.toMatlabArray('Y' + (++counter), lib.range(0,8, function(i) { + var ret = elt.durationBetweenCoins[i]; + + if (ret === undefined) + ret = 'Inf'; + + return ret; + }))); + }); + + }); + +} + +if (process.argv.length !== 3) { + process.stderr.write('Error : please give me a JSON file to work on\n'); + process.exit(-1); +} + +main(process.argv[2]); + diff --git a/controllers/prototype/dbrequests.js b/controllers/prototype/dbrequests.js index abbc2de..bd9997f 100644 --- a/controllers/prototype/dbrequests.js +++ b/controllers/prototype/dbrequests.js @@ -697,6 +697,7 @@ DBReq.ExpCreator.prototype.execute = function() { " Scene.name != 'peachcastle' AND\n" + " CoinCombination.id = Experiment.coin_combination_id AND\n" + " Other.id = Experiment.user_id AND\n" + + " Other.valid IS false AND\n" + " Experiment.finished = true AND\n" + " Other.rating = U.rating AND\n" + " Other.id != U.id AND\n" +