Example #1
0
function child_render($param)
{
    global $g_page, $g_cfg;
    $g_page["frame"] = "site_admin/frame.html";
    if (!http_user_auth("admin", "admin")) {
        return redirect("/");
    }
    if (isset($param[1]) && $param[1] == "switch_status") {
        list($cname, $p) = [$_GET["name"], $_GET["p"]];
        if ($p == "close") {
            dbupdate("sys_variations", [], ["test" => $cname], ["completed" => "now()"]);
        }
        return redirect("/stats/multivariants");
    }
    $q = gettable("select * from sys_variations where completed is null");
    $t = [];
    foreach ($q as $row) {
        if (!isset($t[$row["test"]])) {
            $t[$row["test"]] = [];
        }
        if (!isset($t[$row["test"]][$row["variation"]])) {
            $t[$row["test"]][$row["variation"]] = ["goals" => []];
        }
        $t[$row["test"]][$row["variation"]]["content"] = substr($row["content"], 0, 256);
        $cm = new Variant($row["test"]);
        $t[$row["test"]][$row["variation"]]["enrolled"] = $cm->get() == $row["variation"] ? 1 : 0;
        $t[$row["test"]][$row["variation"]]["variation"] = $row["variation"];
        $cv = [];
        $cgoal = $row;
        $cgoal["pc"] = $row["sample"] == 0 ? "N/A" : round($row["conversion"] / $row["sample"] * 100, 2);
        $t[$row["test"]][$row["variation"]]["goals"][] = $cgoal;
        $t[$row["test"]][$row["variation"]] = update($t[$row["test"]][$row["variation"]], $cv);
    }
    $res = [];
    foreach ($t as $name => $row) {
        $cm = [];
        foreach ($t[$name] as $varname => $cvar) {
            uasort($cvar["goals"], function ($a, $b) {
                global $g_mv_goals;
                if (($i = array_search($a["goal"], $g_mv_goals)) === false) {
                    return -1;
                }
                if (($j = array_search($b["goal"], $g_mv_goals)) === false) {
                    return -1;
                }
                if ($i == $j) {
                    return 0;
                }
                return $i > $j ? 1 : -1;
            });
            $cm[] = $cvar;
        }
        $res[] = ["test" => $name, "var" => $cm];
    }
    // print_r($res); exit;
    $scr = new Scriptor("site_admin/multivariants.html", ["tests" => $res]);
    return $scr->result();
}
Example #2
0
 public static function read($id)
 {
     global $g_session_id, $g_session_new;
     $q = gettable("select * from sys_sessions where session_cookie=@cookie and domain = @domain", ["cookie" => $id, "domain" => $_SERVER["SERVER_NAME"]]);
     if (count($q) > 0) {
         $g_session_id = $q[0]["id"];
         return $q[0]["session_data"];
     }
     // insert minimum viable session id
     $g_session_id = dbupinsert("sys_sessions", ["session_cookie" => $id, "domain" => $_SERVER["SERVER_NAME"]], ["lastupdate"], ["lastupdate" => "now()", "cohort_date" => "now()"]);
     $g_session_new = true;
     // mark it as new
     return '';
 }
Example #3
0
if (isset($_SERVER["argv"]) && isset($_SERVER["SCRIPT_FILENAME"]) && basename($_SERVER["SCRIPT_FILENAME"]) == basename(__FILE__)) {
    echo "cog_database: Running self-tests...\n";
    // set up asserts
    assert_options(ASSERT_ACTIVE, 1);
    assert_options(ASSERT_WARNING, 0);
    assert_options(ASSERT_QUIET_EVAL, 0);
    // Set up the callback
    assert_options(ASSERT_CALLBACK, function ($file, $line, $code) {
        echo "Assertion Failed:\n File '{$file}' \n  Line '{$line}'  Code '{$code}'\n\n";
    });
    assert(initsql());
    assert(resolvequery("VALUES (@email, @example)", array("email" => "*****@*****.**", "example" => 123)) == 'VALUES ("*****@*****.**", "123")');
    // table-based testing
    dbcommit("drop table if exists cog_testing");
    dbcommit("create table if not exists cog_testing (id int primary key auto_increment, username varchar(64), status enum('live', 'deleted') default 'live', created datetime )");
    dbinsert("cog_testing", ["username" => random_string(16)], ["created" => "now()"]);
    $q = gettable("select * from cog_testing where status = 'live' ");
    assert(count($q) == 1);
    // unique insert testing
    $res = dbuniqueinsert("cog_testing", ["username" => "unique"], ["username" => "unique", "status" => "live"], ["created" => "now()"]);
    assert($res !== false);
    // this should return with new ID
    $q = gettable("select * from cog_testing where status = 'live' ");
    assert(count($q) == 2);
    $res = dbuniqueinsert("cog_testing", ["username" => "unique"], ["username" => "unique", "status" => "live"], ["created" => "now()"]);
    assert($res == 0);
    // this should return 0
    dbcommit("drop table if exists cog_testing");
    // clean up
    echo "Self-tests finished\n";
}
Example #4
0
function child_render($param)
{
    $data = ["msglist" => gettable("select * from site_guestbook")];
    $scr = new Scriptor("site_guestbook/guestbook.html", $data);
    return $scr->result();
}
Example #5
0
function variant_recalculate()
{
    global $g_mv_goals, $g_mv_tests;
    $res = [];
    foreach ($g_mv_tests as $row) {
        $res[$row["test"] . "|" . $row["variation"] . "|" . $row["goal"] . "|sample"] = [];
        $res[$row["test"] . "|" . $row["variation"] . "|" . $row["goal"] . "|conversion"] = [];
        $res[$row["test"] . "|" . $row["variation"] . "|" . $row["goal"] . "|start_log_id"] = $row["start_log_id"];
    }
    // print_r($res); exit;
    // add sessions
    $q = gettable("select * from sys_sessions where ishuman = 1");
    session_start();
    foreach ($q as $row) {
        foreach (array_keys($_SESSION) as $ckeys) {
            unset($_SESSION[$ckeys]);
        }
        if (!session_decode($row["session_data"])) {
            internal_error("Unable to unserialize: " . $row["session_data"]);
        }
        $res = variant_recalculate_identity($res, $_SESSION);
    }
    // add users
    $q = gettable("select * from usr_users");
    foreach ($q as $row) {
        $srow = json_decode($row["session_data"], true);
        if ($srow == null) {
            continue;
        }
        $nrow = json_decode($row["usr_notes"], true);
        if ($nrow == null) {
            continue;
        }
        if (isset($nrow["_mg_cancellation"])) {
            $srow["_mg_cancellation"] = intval($nrow["_mg_cancellation"]);
        }
        $res = variant_recalculate_identity($res, $srow);
    }
    // print_r($g_mv_tests ); exit;
    $ckeys = array_keys($res);
    foreach ($g_mv_tests as $row) {
        $sample = count(array_unique($res[$row["test"] . "|" . $row["variation"] . "|" . $row["goal"] . "|sample"]));
        $conv = count(array_unique($res[$row["test"] . "|" . $row["variation"] . "|" . $row["goal"] . "|conversion"]));
        $cwhere = update([], $row, ["test", "variation", "goal"]);
        dbupdate("sys_variations", ["sample" => $sample, "conversion" => $conv], $cwhere);
    }
}