diff lucene/src/luan/modules/lucene/Ab_testing.luan @ 503:92c3d22745b8

make _ENV optional
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 20 May 2015 23:24:46 -0600
parents 598123096772
children 7bc63886d4f2
line wrap: on
line diff
--- a/lucene/src/luan/modules/lucene/Ab_testing.luan	Tue May 19 17:57:20 2015 -0600
+++ b/lucene/src/luan/modules/lucene/Ab_testing.luan	Wed May 20 23:24:46 2015 -0600
@@ -9,10 +9,11 @@
 local Http = require "luan:http/Http"
 local Logging = require "luan:logging/Logging"
 
+local M = {}
 
 local logger = Logging.logger "Ab_testing"
 
-function of(index)
+function M.of(index)
 
 	local ab_testing = {}
 
@@ -91,8 +92,8 @@
 				for value, count in pairs(results[event]) do
 					fancy[event][value] = {}
 					fancy[event][value].count = count
-					fancy[event][value].pct_of_total = percent(count,all[value])
-					fancy[event][value].pct_of_prev = percent(count,prev[value])
+					fancy[event][value].pct_of_total = M.percent(count,all[value])
+					fancy[event][value].pct_of_prev = M.percent(count,prev[value])
 				end
 				prev = results[event]
 			end
@@ -140,7 +141,7 @@
 				results[name] = test.fancy_results()
 			end
 			Io.stdout = Http.response.text_writer()
-			html(test_names,ab_testing.test_map,results)
+			M.html(test_names,ab_testing.test_map,results)
 		end }
 	end
 
@@ -151,7 +152,7 @@
 -- aggregator factories
 
 -- fn(doc) should return boolean whether doc should be counted
-function count(fn)
+function M.count(fn)
 	return function()
 		local aggregator = {}
 		aggregator.result = 0
@@ -164,10 +165,10 @@
 	end
 end
 
-count_all = count( function(doc) return true end )
+M.count_all = M.count( function(doc) return true end )
 
 -- fn(doc) should return number to add to result, return 0 for nothing
-function sum(fn)
+function M.sum(fn)
 	return function()
 		local aggregator = {}
 		aggregator.result = 0
@@ -180,7 +181,7 @@
 
 
 
-function percent(x,total)
+function M.percent(x,total)
 	if total==0 then
 		return 0
 	else
@@ -204,7 +205,7 @@
 	return v.gsub([[(\d+\.\d{1})\d+]],'$1')
 end
 
-function html(test_names,tests,results) %>
+function M.html(test_names,tests,results) %>
 <!DOCTYPE html>
 <html lang="en">
 	<head>
@@ -265,3 +266,5 @@
 	</body>
 </html>
 <% end
+
+return M