Skip to content
Browse files

allow option to clear the db, and fixed a bug in report.php with alte…

…rnatives that need urlencoding
  • Loading branch information...
1 parent c6052e2 commit c8f663092e3e626e84be51cd2fce676d3bf4669f @aliasaria committed Mar 30, 2010
Showing with 57 additions and 8 deletions.
  1. +3 −4 TODO.txt
  2. +37 −0 lib/report.php
  3. +17 −4 report.php
View
7 TODO.txt
@@ -1,12 +1,11 @@
- Add author and credit information
-- Add notion of statistical significance based on Vanity ala http://20bits.com/articles/statistical-analysis-and-ab-testing/
-- Allow ability to clear the data from a test
- Add IP restriction on report.php
- Have metrics that can have size, and related results that would be distributions : E.g. # of Pages viewed. This would be more complicated.
- Fix date_time issues where I just use unicode time and not proper date math (can't find docs for date match in PHP 5.2)
-
+- Allow alternatives and tests that have spaces in their titles (!)
Suggestions
- Have an option on a metric so that it is only initialized upon request
-- Have a flag where this runs without redis for debugging (e.g. file-based or sqlite)
+- Have a flag where this runs without redis for debugging (e.g. file-based or sqlite)
+- We can save A LOT of space if we don't add members to the set of participants in line 55 of tests.php, but instead just incr a number
View
37 lib/report.php
@@ -186,4 +186,41 @@ function ab_tests_conclusion($test)
}
return($r);
+}
+
+
+function erase_all_keys_except_forced_keys()
+{
+ global $r;
+
+ /////////////////////////////////////////
+ //First get all the keys you want to save
+ /////////////////////////////////////////
+ $force_keys = array();
+ $force_vals = array();
+
+ //the redis "keys" function searches for keys that match a specified pattern
+ $force_keys = $r->keys("ab:*:force");
+
+ foreach($force_keys as $key)
+ {
+ $force_vals[] = $r->get($key);
+ }
+
+ print_r($force_keys);
+ print_r($force_vals);
+
+
+ /////////////////////////////////////////
+ //Now erase everything else
+ /////////////////////////////////////////
+ $r->flushdb();
+
+ /////////////////////////////////////////
+ //Now restore the forced keys
+ /////////////////////////////////////////
+ for ($i = 0; $i < count(force_keys); $i++)
+ {
+ $r->set($force_keys[$i], $force_vals[$i]);
+ }
}
View
21 report.php
@@ -61,9 +61,18 @@
$alt = $_GET['alt'];
if ($alt != "!!null!!")
- ab_tests_force_alternative($test, $alt);
+ ab_tests_force_alternative(urldecode($test), urldecode($alt));
else
- ab_tests_force_alternative($test, null);
+ ab_tests_force_alternative(urldecode($test), null);
+}
+
+
+
+
+//do forced alternative logic if necessary
+if (isset($_GET['clear-all-data']))
+{
+ erase_all_keys_except_forced_keys();
}
?>
@@ -132,13 +141,13 @@
if ($forced_alternative != $alt)
{
- echo ' <a href="?force=true&test=' . $test['name'] . '&alt=' . $alt . '#'. $name .'" class="grey-button pcb">
+ echo ' <a href="?force=true&test=' . urlencode($test['name']) . '&alt=' . urlencode($alt) . '#'. urlencode($name) .'" class="grey-button pcb">
<span style="color: #666;">Show Always</span>
</a>';
}
else
{
- echo ' <span class="forced-text">Always Showing</span> <a href="?force=true&test=' . $test['name'] . '&alt=' . "!!null!!" . '#'. $name .'" class="red-disabled-button pcb">
+ echo ' <span class="forced-text">Always Showing</span> <a href="?force=true&test=' . urlencode($test['name']) . '&alt=' . "!!null!!" . '#'. urlencode($name) .'" class="red-disabled-button pcb">
<span style="color: #333;">Clear</a>
</span>';
}
@@ -321,5 +330,9 @@
?>
+
+
+<hr/>
+<a href="?clear-all-data=true" class="red-button pcb"><span>Clear All Data</span></a>
</body>
</html>

0 comments on commit c8f6630

Please sign in to comment.
Something went wrong with that request. Please try again.