Last corrections before micro workers
This commit is contained in:
		
							parent
							
								
									688223eb58
								
							
						
					
					
						commit
						00fe3dfe34
					
				| @ -1,3 +1,40 @@ | |||||||
|  | // http://codereview.stackexchange.com/questions/37028/grouping-elements-in-array-by-multiple-properties
 | ||||||
|  | function groupBy(array, f) | ||||||
|  | { | ||||||
|  |     var groups = {}; | ||||||
|  |     array.forEach(function(o) { | ||||||
|  |         var group = JSON.stringify(f(o)); | ||||||
|  |         groups[group] = groups[group] || []; | ||||||
|  |         groups[group].push(o); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     return Object.keys(groups).map(function(group) { | ||||||
|  |         return groups[group]; | ||||||
|  |     }) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function compareRecommendationStyle(style1, style2) { | ||||||
|  | 
 | ||||||
|  |     if (style1.recommendation_style[4] === 'B' && style2.recommendation_style[4] !== 'B') { | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (style2.recommendation_style[4] === 'B' && style1.recommendation_style[4] !== 'B') { | ||||||
|  |         return 1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (style1.recommendation_style[4] === 'V' && style2.recommendation_style[4] === 'A') { | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (style2.recommendation_style[4] === 'V' && style1.recommendation_style[4] === 'A') { | ||||||
|  |         return 1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return 0; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function main(path) { | function main(path) { | ||||||
| 
 | 
 | ||||||
|     var db = JSON.parse(require('fs').readFileSync(path, 'utf8')); |     var db = JSON.parse(require('fs').readFileSync(path, 'utf8')); | ||||||
| @ -8,45 +45,152 @@ function main(path) { | |||||||
|     var meanTimeArrow = 0; |     var meanTimeArrow = 0; | ||||||
|     var meanTimeViewport = 0; |     var meanTimeViewport = 0; | ||||||
| 
 | 
 | ||||||
|     console.log(); |     var groups = makeGroups(db); | ||||||
| 
 | 
 | ||||||
|     for (var i = 0; i < db.experiments.length; i++) { |     groups.forEach(function(elt) { | ||||||
|  |         var ok = true; | ||||||
| 
 | 
 | ||||||
|         var exp = db.experiments[i]; |         // console.log(elt);
 | ||||||
|         var events = exp.elements.events; |         elt.sort(compareRecommendationStyle); | ||||||
| 
 |         // console.log(elt);
 | ||||||
|         if (events.length === 0 || exp.user.worker_id === null) { |  | ||||||
| 
 |  | ||||||
|             continue; |  | ||||||
| 
 |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         var coins = []; |  | ||||||
|         for (var j = 0; j < exp.elements.events.length; j++) { |  | ||||||
| 
 |  | ||||||
|             if (exp.elements.events[j].type === 'coin') { |  | ||||||
| 
 |  | ||||||
|                 if (coins.find(function(elt) { return elt.id === exp.elements.events[j].id; }) === undefined) { |  | ||||||
| 
 |  | ||||||
|                     coins.push(exp.elements.events[j]); |  | ||||||
| 
 |  | ||||||
|                 } |  | ||||||
| 
 | 
 | ||||||
|  |         elt.forEach(function(subElt) { | ||||||
|  |             if (subElt.coin_combination_id !== elt[0].coin_combination_id) { | ||||||
|  |                 ok = false; | ||||||
|             } |             } | ||||||
|  |         }); | ||||||
| 
 | 
 | ||||||
|  |         if (!ok) { | ||||||
|  |             process.stderr.write('Error : assertion failed'); | ||||||
|  |             process.exit(-1); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         console.log(elt.length + ' -> ' + elt[0].coin_combination_id); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     console.log('-----------------'); | ||||||
|  | 
 | ||||||
|  |     var value = minDifferences(groups); | ||||||
|  |     console.log(value); | ||||||
|  | 
 | ||||||
|  |     // for (var i = 0; i < db.experiments.length; i++) {
 | ||||||
|  | 
 | ||||||
|  |     //     var exp = db.experiments[i];
 | ||||||
|  |     //     var events = exp.elements.events;
 | ||||||
|  | 
 | ||||||
|  |     //     if (events.length === 0 || exp.user.worker_id === null) {
 | ||||||
|  | 
 | ||||||
|  |     //         continue;
 | ||||||
|  | 
 | ||||||
|  |     //     }
 | ||||||
|  | 
 | ||||||
|  |     //     var coins = [];
 | ||||||
|  |     //     for (var j = 0; j < exp.elements.events.length; j++) {
 | ||||||
|  | 
 | ||||||
|  |     //         if (exp.elements.events[j].type === 'coin') {
 | ||||||
|  | 
 | ||||||
|  |     //             if (coins.find(function(elt) { return elt.id === exp.elements.events[j].id; }) === undefined) {
 | ||||||
|  | 
 | ||||||
|  |     //                 coins.push(exp.elements.events[j]);
 | ||||||
|  | 
 | ||||||
|  |     //             }
 | ||||||
|  | 
 | ||||||
|  |     //         }
 | ||||||
|  | 
 | ||||||
|  |     //     }
 | ||||||
|  |     //     console.log(`${exp.id} -> ${coins.length} (on ${exp.coinCombination.scene_id} )`);
 | ||||||
|  |     // }
 | ||||||
|  | 
 | ||||||
|  |     // console.log();
 | ||||||
|  | 
 | ||||||
|  |     // for (var i = 0; i < db.users.length; i++) {
 | ||||||
|  | 
 | ||||||
|  |     //     var user = db.users[i];
 | ||||||
|  |     //     console.log(`${user.worker_id} has done ${user.experiments.length} experiments with rating ${user.rating}`);
 | ||||||
|  | 
 | ||||||
|  |     // }
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function minDifference(exps) { | ||||||
|  | 
 | ||||||
|  |     var dict = {}; | ||||||
|  | 
 | ||||||
|  |     exps.forEach(function(subElt) { | ||||||
|  |         dict[subElt.recommendation_style[4]] = subElt.duration; | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     if (dict.B !== undefined) { | ||||||
|  | 
 | ||||||
|  |         if (dict.A !== undefined && dict.V !== undefined) { | ||||||
|  |             return ( | ||||||
|  |                 Math.min(dict.A - dict.B, dict.V - dict.B) | ||||||
|  |             ); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (dict.A !== undefined) { | ||||||
|  |             return dict.A - dict.B; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (dict.V !== undefined) { | ||||||
|  |             return dict.V - dict.B; | ||||||
|         } |         } | ||||||
|         console.log(`${exp.id} -> ${coins.length} (on ${exp.coinCombination.scene_id} )`); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     console.log(); | } | ||||||
| 
 | 
 | ||||||
|     for (var i = 0; i < db.users.length; i++) { | function minDifferences(groups) { | ||||||
| 
 | 
 | ||||||
|         var user = db.users[i]; |     var differences = []; | ||||||
|         console.log(`${user.worker_id} has done ${user.experiments.length} experiments with rating ${user.rating}`); |  | ||||||
| 
 | 
 | ||||||
|  |     groups.forEach(function(elt) { | ||||||
|  | 
 | ||||||
|  |         var timesMean = 0; | ||||||
|  | 
 | ||||||
|  |         elt.forEach(function(elt) { | ||||||
|  |             var duration = experimentDuration(elt); | ||||||
|  |             timesMean += experimentDuration(elt); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         timesMean /= elt.length; | ||||||
|  | 
 | ||||||
|  |         var normalizedElt = []; | ||||||
|  | 
 | ||||||
|  |         elt.forEach(function(subElt) { | ||||||
|  |             normalizedElt.push({ | ||||||
|  |                 recommendation_style : subElt.recommendation_style, | ||||||
|  |                 duration : experimentDuration(subElt) / timesMean | ||||||
|  |             }); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         var diff = minDifference(normalizedElt); | ||||||
|  | 
 | ||||||
|  |         if (diff !== undefined) | ||||||
|  |             differences.push(diff); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     var sum = 0; | ||||||
|  | 
 | ||||||
|  |     differences.forEach(function(elt) { | ||||||
|  |         sum += elt; | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     return sum / differences.length; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function experimentDuration(exp) { | ||||||
|  |     var lastCoin = null; | ||||||
|  | 
 | ||||||
|  |     for (var i = exp.elements.events.length - 1; i >= 0; i--) { | ||||||
|  |         if (exp.elements.events[i].type === 'coin') { | ||||||
|  |             lastCoin = exp.elements.events[i]; | ||||||
|  |             break; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     return timeDifference(exp.elements.events[0].time, lastCoin.time); | ||||||
|  | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function timeDifference(time1, time2) { | function timeDifference(time1, time2) { | ||||||
| @ -63,6 +207,26 @@ function timeToString(_time) { | |||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function makeGroups(db) { | ||||||
|  | 
 | ||||||
|  |     var elements = []; | ||||||
|  | 
 | ||||||
|  |     for (var i = 0; i < db.experiments.length; i++) { | ||||||
|  | 
 | ||||||
|  |         if (db.experiments[i].coinCombination.scene_id !== 1 && db.experiments[i].elements.events.length !== 0) { | ||||||
|  | 
 | ||||||
|  |             elements.push(db.experiments[i]); | ||||||
|  | 
 | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return groupBy(elements, function(item) { | ||||||
|  |         return item.coin_combination_id;//, item.user.rating];
 | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
| if (process.argv.length !== 3) { | if (process.argv.length !== 3) { | ||||||
|     process.stderr.write('Error : please give me a JSON file to work on\n'); |     process.stderr.write('Error : please give me a JSON file to work on\n'); | ||||||
|     process.exit(-1); |     process.exit(-1); | ||||||
|  | |||||||
| @ -12,7 +12,8 @@ block content | |||||||
| 
 | 
 | ||||||
| block extrajs | block extrajs | ||||||
|     script. |     script. | ||||||
|         if ($.browser.chrome || $.browser.mozilla) { |         var isOpera = window.navigator.userAgent.indexOf("OPR") > -1 || window.navigator.userAgent.indexOf("Opera") > -1; | ||||||
|  |         if (($.browser.chrome || $.browser.mozilla) && !isOpera) { | ||||||
|             $('#start').html('You can now <a href="/user-study">start when you are ready</a>'); |             $('#start').html('You can now <a href="/user-study">start when you are ready</a>'); | ||||||
|         } else { |         } else { | ||||||
|             $('#start').html('Sorry, your browser is not compatible... please try again with Firefox or Chrome'); |             $('#start').html('Sorry, your browser is not compatible... please try again with Firefox or Chrome'); | ||||||
|  | |||||||
| @ -37,8 +37,8 @@ block content | |||||||
|                 //-input#fullarrow(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}) |                 //-input#fullarrow(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}) | ||||||
|                 //-label(for="fullarrow" style={'margin-right':'10px'}) Full arrow |                 //-label(for="fullarrow" style={'margin-right':'10px'}) Full arrow | ||||||
| 
 | 
 | ||||||
|                 input#lock(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}, checked) |                 input#lock(type="checkbox", style={'zoom':'1.7'}, checked) | ||||||
|                 label(for="lock" style={'margin-right':'10px'}) Pointer lock |                 label(for="lock" style={'margin-right':'10px', 'zoom': '1.7'}) Pointer lock | ||||||
| 
 | 
 | ||||||
|                 input#showarrows(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px', 'display':'none'}, checked) |                 input#showarrows(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px', 'display':'none'}, checked) | ||||||
|                 label(for="showarrows" style={'margin-right':'10px', 'display': 'none'}) Show arrows |                 label(for="showarrows" style={'margin-right':'10px', 'display': 'none'}) Show arrows | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								js/l3d/apps/prototype/tutorial/TutorialSteps.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								js/l3d/apps/prototype/tutorial/TutorialSteps.js
									
									
									
									
										vendored
									
									
								
							| @ -258,7 +258,7 @@ TutorialSteps.prototype.alert = function(myString, justclicked) { | |||||||
| 
 | 
 | ||||||
| TutorialSteps.prototype.notify = function(myString, justclick) { | TutorialSteps.prototype.notify = function(myString, justclick) { | ||||||
|     $('#alert-placeholder').html( |     $('#alert-placeholder').html( | ||||||
|         '<div id="toto" class="alert alert-warning alert-dismissable">' + |         '<div id="toto" class="alert alert-info alert-dismissable">' + | ||||||
|             (justclick ? |             (justclick ? | ||||||
|             '<button type="button" class="close" aria-hidden="true"' + |             '<button type="button" class="close" aria-hidden="true"' + | ||||||
|                      'onclick="setTimeout(onWindowResize, 100); nextStep();' + '">' + |                      'onclick="setTimeout(onWindowResize, 100); nextStep();' + '">' + | ||||||
| @ -275,6 +275,12 @@ TutorialSteps.prototype.notify = function(myString, justclick) { | |||||||
|     $('#toto').removeClass('alert-info').addClass('alert-danger'); |     $('#toto').removeClass('alert-info').addClass('alert-danger'); | ||||||
| 
 | 
 | ||||||
|     setTimeout(function() { |     setTimeout(function() { | ||||||
|         $('#toto').removeClass('alert-danger').addClass('alert-warning'); |         $('#toto').removeClass('alert-danger').addClass('alert-info'); | ||||||
|     }, 500); |         setTimeout(function() { | ||||||
|  |             $('#toto').removeClass('alert-info').addClass('alert-danger'); | ||||||
|  |             setTimeout(function() { | ||||||
|  |                 $('#toto').removeClass('alert-danger').addClass('alert-info'); | ||||||
|  |             }, 700); | ||||||
|  |         }, 700); | ||||||
|  |     }, 700); | ||||||
| }; | }; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user