Mercurial Hosting > luan
comparison lucene/src/luan/modules/lucene/Ab_testing.luan @ 292:e8a2153f6ce1
minor
git-svn-id: https://luan-java.googlecode.com/svn/trunk@293 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 10 Dec 2014 21:44:19 +0000 |
parents | a35d1177bbf0 |
children | 5652cdea25f5 |
comparison
equal
deleted
inserted
replaced
291:a35d1177bbf0 | 292:e8a2153f6ce1 |
---|---|
7 function of(index) | 7 function of(index) |
8 | 8 |
9 local ab_testing = {} | 9 local ab_testing = {} |
10 | 10 |
11 ab_testing.test_map = {} | 11 ab_testing.test_map = {} |
12 ab_testing.test_list = {} | |
13 | 12 |
14 function ab_testing.test(test) | 13 function ab_testing.test(test) |
15 test.name or error "name not defined" | 14 test.name or error "name not defined" |
16 test.values or error "values not defined" | 15 test.values or error "values not defined" |
17 | 16 |
90 prev = results[event] | 89 prev = results[event] |
91 end | 90 end |
92 return fancy | 91 return fancy |
93 end | 92 end |
94 | 93 |
95 | |
96 ab_testing.test_map[test.name] = test | 94 ab_testing.test_map[test.name] = test |
97 ab_testing.test_list[#ab_testing.test_list + 1] = test | |
98 | 95 |
99 return test | 96 return test |
100 end | 97 end |
101 | 98 |
102 function ab_testing.value(test_name,values) | 99 function ab_testing.value(test_name,values) |
103 return values[test_name] or ab_testing.test_map[test_name].values[1] | 100 return values[test_name] or ab_testing.test_map[test_name].values[1] |
104 end | 101 end |
105 | 102 |
106 -- returns map from test name to value | 103 -- returns map from test name to value |
107 function ab_testing.from_doc(doc) | 104 function ab_testing.from_doc(doc) |
108 local tests = ab_testing.test_list | |
109 local values = {} | 105 local values = {} |
110 for _, test in ipairs(tests) do | 106 for _, test in pairs(ab_testing.test_map) do |
111 values[test.name] = doc[test.field] | 107 values[test.name] = doc[test.field] |
112 end | 108 end |
113 return values | 109 return values |
114 end | 110 end |
115 | 111 |
116 function ab_testing.to_doc(doc,values,tests) | 112 function ab_testing.to_doc(doc,values,tests) |
117 tests = tests or ab_testing.test_list | 113 tests = tests or ab_testing.test_map |
118 if values == nil then | 114 if values == nil then |
119 for _, test in ipairs(tests) do | 115 for _, test in ipairs(tests) do |
120 doc[test.field] = test.values[Math.random(#test.values)] | 116 doc[test.field] = test.values[Math.random(#test.values)] |
121 end | 117 end |
122 else | 118 else |