diff 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
line wrap: on
line diff
--- a/lucene/src/luan/modules/lucene/Ab_testing.luan	Thu Dec 11 01:44:38 2014 +0000
+++ b/lucene/src/luan/modules/lucene/Ab_testing.luan	Thu Dec 11 03:12:26 2014 +0000
@@ -95,11 +95,11 @@
 
 		return test
 	end
-	
+
 	function ab_testing.value(test_name,values)
 		return values[test_name] or ab_testing.test_map[test_name].values[1]
 	end
-	
+
 	-- returns map from test name to value
 	function ab_testing.from_doc(doc)
 		local values = {}
@@ -179,68 +179,79 @@
 	end
 end
 
+local function basic_style() %>
+	body {font-family:'Arial',sans-serif;font-size:16px;padding:1em 2em}
+	h1 {font-weight:bold;font-size:20px}
+	h2 {margin:2em 0 0em;font-size:18px;color:#3589B1}
+	table.results {margin-top:.5em;border-collapse:collapse;font-size:90%}
+	table.results th {background:#eee}
+	table.results th,table.results td {border-left:1px solid #bbb;padding:.4em 2em}
+	table.results tr:nth-child(odd) td {background:#f8f8f8}
+<% end
+
+local function format(v)
+	v = v .. ''
+	return v.gsub('(\d+.\d{1})\d+','$1')
+end
 
 function html(test_names,tests,results) %>
-<html>
-<body>
-<h2>A/B Tests</h2>
-<%
-	for _, test_name in ipairs(test_names) do
-		local test = tests[test_name]
-		local result = results[test_name]
-		local n = #test.values
-		%>
-		<h3><%=test_name%></h3>
-		<table>
-			<tr>
-				<th>Event</th>
-				<th class="top" colspan="<%=n%>">Count</th>
-				<th class="top" colspan="<%=n%>">% of total</th>
-				<th class="top" colspan="<%=n%>">% of prev</th>
-			</tr>
-			<tr>
-				<th></th>
-				<%
-				for _ in range(1,3) do
-					for _, value in ipairs(test.values) do
-						%>
-						<th class="top"><%=value%></th>
-						<%
-					end
-				end
-				%>
-			</tr>
-			<%
-			for _, event in ipairs(test.events) do
-				local event_values = result[event]
-				%>
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<title>A/B Test Results</title>
+		<style><% basic_style() %></style>
+	</head>
+	<body>
+		<h1>A/B Test Results</h1>
+		<%
+		for _, test_name in ipairs(test_names) do
+			local test = tests[test_name]
+			local result = results[test_name]
+			local n = #test.values
+			%>
+			<h2><%=test_name%></h2>
+			<table class="results">
 				<tr>
-					<td><%=event%></td>
+					<th>Event</th>
+					<th class="top" colspan="<%=n%>">Count</th>
+					<th class="top" colspan="<%=n%>">% of total</th>
+					<th class="top" colspan="<%=n%>">% of prev</th>
+				</tr>
+				<tr>
+					<th></th>
 					<%
-					for _, value in ipairs(test.values) do
-						%>
-						<td><%=event_values[value].count%></th>
-						<%
-					end
-					for _, value in ipairs(test.values) do
-						%>
-						<td><%=event_values[value].pct_of_total%></th>
-						<%
-					end
-					for _, value in ipairs(test.values) do
-						%>
-						<td><%=event_values[value].pct_of_prev%></th>
-						<%
+					for _ in range(1,3) do
+						for _, value in ipairs(test.values) do
+							%><th class="top"><%=value%></th><%
+						end
 					end
 					%>
 				</tr>
 				<%
-			end
-			%>
-		</table>
-		<%
-	end
-%>
-</body>
+				for _, event in ipairs(test.events) do
+					local event_values = result[event]
+					%>
+					<tr>
+						<td><%=event%></td>
+						<%
+						for _, value in ipairs(test.values) do
+							%><td><%=format(event_values[value].count)%></th><%
+						end
+						for _, value in ipairs(test.values) do
+							%><td><%=format(event_values[value].pct_of_total)%></th><%
+						end
+						for _, value in ipairs(test.values) do
+							%><td><%=format(event_values[value].pct_of_prev)%></th><%
+						end
+						%>
+					</tr>
+					<%
+				end
+				%>
+			</table>
+			<%
+		end
+		%>
+	</body>
 </html>
-<% end
+<% end
\ No newline at end of file