comparison lucene/src/luan/modules/lucene/Ab_testing.luan @ 295:1f4cc8505308

fix Ab_testing git-svn-id: https://luan-java.googlecode.com/svn/trunk@296 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 12 Dec 2014 09:45:13 +0000
parents 5652cdea25f5
children 6e11eace1091
comparison
equal deleted inserted replaced
294:5652cdea25f5 295:1f4cc8505308
1 import "luan:Math" 1 import "luan:Math"
2 import "luan:Table" 2 import "luan:Table"
3 import "luan:Io" 3 import "luan:Io"
4 import "luan:web/Http" 4 import "luan:web/Http"
5 5 import "luan:logging/Logging"
6
7
8 local logger = Logging.logger "Ab_testing"
6 9
7 function of(index) 10 function of(index)
8 11
9 local ab_testing = {} 12 local ab_testing = {}
10 13
110 end 113 end
111 114
112 function ab_testing.to_doc(doc,values,tests) 115 function ab_testing.to_doc(doc,values,tests)
113 tests = tests or ab_testing.test_map 116 tests = tests or ab_testing.test_map
114 if values == nil then 117 if values == nil then
115 for _, test in ipairs(tests) do 118 values = {}
116 doc[test.field] = test.values[Math.random(#test.values)] 119 for _, test in pairs(tests) do
117 end 120 values[test.name] = test.values[Math.random(#test.values)]
118 else 121 end
119 for _, test in ipairs(tests) do 122 end
120 doc[test.field] = values[test.name] 123 for _, test in pairs(tests) do
121 end 124 doc[test.field] = values[test.name]
122 end 125 end
126 return values
123 end 127 end
124 128
125 function ab_testing.web_page(test_names) 129 function ab_testing.web_page(test_names)
126 return { service = function() 130 return { service = function()
127 local results = {} 131 local results = {}