comparison lucene/src/luan/modules/lucene/Ab_testing.luan @ 294:5652cdea25f5

Improve html code of core tools. git-svn-id: https://luan-java.googlecode.com/svn/trunk@295 21e917c8-12df-6dd8-5cb6-c86387c605b9
author hugo.tech@gmail.com <hugo.tech@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 11 Dec 2014 03:12:26 +0000
parents e8a2153f6ce1
children 1f4cc8505308
comparison
equal deleted inserted replaced
293:a50e88d3547c 294:5652cdea25f5
93 93
94 ab_testing.test_map[test.name] = test 94 ab_testing.test_map[test.name] = test
95 95
96 return test 96 return test
97 end 97 end
98 98
99 function ab_testing.value(test_name,values) 99 function ab_testing.value(test_name,values)
100 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]
101 end 101 end
102 102
103 -- returns map from test name to value 103 -- returns map from test name to value
104 function ab_testing.from_doc(doc) 104 function ab_testing.from_doc(doc)
105 local values = {} 105 local values = {}
106 for _, test in pairs(ab_testing.test_map) do 106 for _, test in pairs(ab_testing.test_map) do
107 values[test.name] = doc[test.field] 107 values[test.name] = doc[test.field]
177 else 177 else
178 return 100 * x / total 178 return 100 * x / total
179 end 179 end
180 end 180 end
181 181
182 local function basic_style() %>
183 body {font-family:'Arial',sans-serif;font-size:16px;padding:1em 2em}
184 h1 {font-weight:bold;font-size:20px}
185 h2 {margin:2em 0 0em;font-size:18px;color:#3589B1}
186 table.results {margin-top:.5em;border-collapse:collapse;font-size:90%}
187 table.results th {background:#eee}
188 table.results th,table.results td {border-left:1px solid #bbb;padding:.4em 2em}
189 table.results tr:nth-child(odd) td {background:#f8f8f8}
190 <% end
191
192 local function format(v)
193 v = v .. ''
194 return v.gsub('(\d+.\d{1})\d+','$1')
195 end
182 196
183 function html(test_names,tests,results) %> 197 function html(test_names,tests,results) %>
184 <html> 198 <!DOCTYPE html>
185 <body> 199 <html lang="en">
186 <h2>A/B Tests</h2> 200 <head>
187 <% 201 <title>A/B Test Results</title>
188 for _, test_name in ipairs(test_names) do 202 <style><% basic_style() %></style>
189 local test = tests[test_name] 203 </head>
190 local result = results[test_name] 204 <body>
191 local n = #test.values 205 <h1>A/B Test Results</h1>
192 %> 206 <%
193 <h3><%=test_name%></h3> 207 for _, test_name in ipairs(test_names) do
194 <table> 208 local test = tests[test_name]
195 <tr> 209 local result = results[test_name]
196 <th>Event</th> 210 local n = #test.values
197 <th class="top" colspan="<%=n%>">Count</th> 211 %>
198 <th class="top" colspan="<%=n%>">% of total</th> 212 <h2><%=test_name%></h2>
199 <th class="top" colspan="<%=n%>">% of prev</th> 213 <table class="results">
200 </tr>
201 <tr>
202 <th></th>
203 <%
204 for _ in range(1,3) do
205 for _, value in ipairs(test.values) do
206 %>
207 <th class="top"><%=value%></th>
208 <%
209 end
210 end
211 %>
212 </tr>
213 <%
214 for _, event in ipairs(test.events) do
215 local event_values = result[event]
216 %>
217 <tr> 214 <tr>
218 <td><%=event%></td> 215 <th>Event</th>
216 <th class="top" colspan="<%=n%>">Count</th>
217 <th class="top" colspan="<%=n%>">% of total</th>
218 <th class="top" colspan="<%=n%>">% of prev</th>
219 </tr>
220 <tr>
221 <th></th>
219 <% 222 <%
220 for _, value in ipairs(test.values) do 223 for _ in range(1,3) do
221 %> 224 for _, value in ipairs(test.values) do
222 <td><%=event_values[value].count%></th> 225 %><th class="top"><%=value%></th><%
223 <% 226 end
224 end
225 for _, value in ipairs(test.values) do
226 %>
227 <td><%=event_values[value].pct_of_total%></th>
228 <%
229 end
230 for _, value in ipairs(test.values) do
231 %>
232 <td><%=event_values[value].pct_of_prev%></th>
233 <%
234 end 227 end
235 %> 228 %>
236 </tr> 229 </tr>
237 <% 230 <%
238 end 231 for _, event in ipairs(test.events) do
239 %> 232 local event_values = result[event]
240 </table> 233 %>
241 <% 234 <tr>
242 end 235 <td><%=event%></td>
243 %> 236 <%
244 </body> 237 for _, value in ipairs(test.values) do
238 %><td><%=format(event_values[value].count)%></th><%
239 end
240 for _, value in ipairs(test.values) do
241 %><td><%=format(event_values[value].pct_of_total)%></th><%
242 end
243 for _, value in ipairs(test.values) do
244 %><td><%=format(event_values[value].pct_of_prev)%></th><%
245 end
246 %>
247 </tr>
248 <%
249 end
250 %>
251 </table>
252 <%
253 end
254 %>
255 </body>
245 </html> 256 </html>
246 <% end 257 <% end