Class ShrimpTest_Model

Description

ShrimpTest Model class

Implements the default ShrimpTest "Model". "Model" is model in the MVC sense, so it essentially is used to access the experiment store.

Located in /classes/model.php (line 16)


	
			
Variable Summary
Method Summary
ShrimpTest_Model ShrimpTest_Model ()
int delete_experiment (int $experiment_id, [bool $force = false])
void delete_experiment_variant (int $experiment_id, int $variant_id)
string display_metric_value (string $metric_name, float $value, [float $raw = null])
array get_experiment (int $experiment_id)
array get_experiments ([array $args = array( )])
array get_experiment_stats (int $experiment_id, [bool $force = false])
string get_experiment_status (int $experiment_id)
array get_experiment_variant (int $experiment_id, [int $variant_id = 0])
array get_experiment_variants (int $experiment_id, [wpdb_result_type $type = OBJECT])
array get_metric_types_to_edit ([string $current_type = null])
array get_variant_types_to_edit ([string $current_type = null])
array get_visitor_variant (int $experiment_id, int $visitor_id)
void init (ShrimpTest &$shrimptest_instance)
void normal_cdf (float $z, [string $type = 'different'])
int sort_by_defaultness (object $a, object $b)
void update_experiment (int $experiment_id, array|object $experiment_data)
void update_experiment_status (int $experiment_id, string $status)
void update_experiment_variant (int $experiment_id, int $variant_id, array|object $variant_data)
void update_experiment_variants (int $experiment_id, array $variants)
void update_variants_type (int $experiment_id, string $variants_type)
void update_visitor_metric (int $experiment_id, float $value, boolean $monotonic, int $visitor_id)
void w_rand ( $weights)
float zscore (array $control, array $variant)
Variables
string $db_prefix (line 31)

Prefix for all ShrimpTest database tables.

Includes $wpdb->prefix

array $metric_types = array() (line 42)

Array of registered metric types and their arguments

ShrimpTest $shrimp (line 22)

Reference to the global ShrimpTest instance

int $stats_timeout (line 52)

Timeout value, in seconds, for experiment stats cache.

By default, 60 minutes (3600). Updatable via the shrimptest_stats_timeout filter. Also the timeout used to setup the stats-generating WP Cron process.

string $stats_transient (line 60)

A prefix for the experiment stats transient name

By default, 'shrimptest_stats_'. Updatable via the shrimptest_stats_transient filter.

array $variant_types = array() (line 37)

Array of registered variant types and their arguments

Methods
Constructor ShrimpTest_Model (line 67)

Dummy constructor

Hint: run init()

ShrimpTest_Model ShrimpTest_Model ()
delete_experiment (line 269)

Delete the specified experiment, if the status will allow.

INDIVIDUAL EXPERIMENT FUNCTIONS

Will delete data not only from the experiments data, but will also delete associated data from other tables.

int delete_experiment (int $experiment_id, [bool $force = false])
  • int $experiment_id
  • bool $force
delete_experiment_variant (line 531)

Delete an experiment variant

EXPERIMENT VARIANT FUNCTIONS

void delete_experiment_variant (int $experiment_id, int $variant_id)
  • int $experiment_id
  • int $variant_id
display_metric_value (line 723)

Return a "display-friendly" string of a given metric value, based on the metric that it is.

For example, if the metric is counting currency, the function may take 5 and return '$5'.

string display_metric_value (string $metric_name, float $value, [float $raw = null])
  • string $metric_name
  • float $value
  • float $raw
get_active_experiments (line 97)

Get an array of active experiments

AGGREGATE EXPERIMENT FUNCTIONS

array get_active_experiments ()
get_experiment (line 184)

Get an experiment's specification

INDIVIDUAL EXPERIMENT FUNCTIONS
Returns all the data from the experiments table, with the "data" column, if available, unserialized into an array. All associated variants from the experiments_variants table will also be put in the "variants" entry as an array.

array get_experiment (int $experiment_id)
  • int $experiment_id
get_experiments (line 114)

Get an array of experiments, using the parameters provided.

AGGREGATE EXPERIMENT FUNCTIONS

Possible parameters:

  • status, default ''
  • orderby, default 'experiment_id'
  • order, default 'ASC'

array get_experiments ([array $args = array( )])
  • array $args
get_experiment_stats (line 393)

Get the computed stats for the specified experiment

INDIVIDUAL EXPERIMENT FUNCTIONS
Will try to pull the stats from the stats cache (which uses the WordPress Transients API), but will recreate it if it has expired or if $force is set.

The return value is organized as follows: for an experiment with X variants, there will be X+2 entries. Entries 0..(X-1) will have statistics for each of the variants. There is also an entry called "total". The variant and total statistics entries are themselves arrays, with the following entries:

  • variant_name
  • N, the number of participants in the experiment
  • avg, the average value of the metric
  • sum, the aggregate total value of the metric
  • sd, the variance of the metric, in standard deviations
In addition, the X-1 variant entries which are not the control (entries 1..(X-1)) will have "zscore" and "p" entries, which are the z-score and p-value of the variant, when compared to the control.

Finally, the return value also has a "stats" entry which contains the following properties:

  • unix, human, two representations for the time when this stat was computed
  • time, how long this experiment calculation took
  • duration_reached, true if the experiment has specified an experiment duration and it has been reached.

If the experiment specification specified an experiment duration, and it has been met with this experiment stats computation, the action shrimptest_experiment_duration_reached will be triggered, and the duration_reached property will be added to the experiment data.

array get_experiment_stats (int $experiment_id, [bool $force = false])
  • int $experiment_id
  • bool $force
get_experiment_status (line 299)

Get the status string for the specified experiment.

INDIVIDUAL EXPERIMENT FUNCTIONS

string get_experiment_status (int $experiment_id)
  • int $experiment_id
get_experiment_variant (line 512)

Get a particular experiment variant and its specification

EXPERIMENT VARIANT FUNCTIONS

array get_experiment_variant (int $experiment_id, [int $variant_id = 0])
  • int $experiment_id
  • int $variant_id
get_experiment_variants (line 490)

Get a list of variants for the given experiment

EXPERIMENT VARIANT FUNCTIONS

array get_experiment_variants (int $experiment_id, [wpdb_result_type $type = OBJECT])
  • int $experiment_id
  • wpdb_result_type $type
get_metric_types_to_edit (line 740)

Get an array of metric type objects with some basic metadata, for editing.

Used by the ShrimpTest UI, so metrics which are _programmatic will be disabled, unless they are turned on, for example.

array get_metric_types_to_edit ([string $current_type = null])
  • string $current_type
get_reserved_experiment_id (line 165)

Get a reserved experiment id

INDIVIDUAL EXPERIMENT FUNCTIONS
This is used to create a new "reserved" experiment and return that experiment id. This can then be used to take the user to the "add new experiment" screen.

int get_reserved_experiment_id ()
get_variant_types_to_edit (line 689)

Get an array of variant type objects with some basic metadata, for editing.

Used by the ShrimpTest UI, so variants which are _programmatic will be disabled, unless they are turned on, for example.

array get_variant_types_to_edit ([string $current_type = null])
  • string $current_type
get_visitor_variant (line 641)

Get the variant specification for the given experiment and visitor so that we can use it

array get_visitor_variant (int $experiment_id, int $visitor_id)
  • int $experiment_id
  • int $visitor_id
init (line 80)

Initialization

void init (ShrimpTest &$shrimptest_instance)
normal_cdf (line 832)

Implements a normal culmulative distribution function (CDF), the integral of the probability density function.

HELPER FUNCTIONS

$type can be 'worse', 'better', or 'different'.

void normal_cdf (float $z, [string $type = 'different'])
  • float $z
  • string $type: which type of integral we want to compute return float
sort_by_defaultness (line 774)

Sort by "defaultness"

HELPER FUNCTIONS
A sorting function which will prefer to order objects which have the _default property further forward.

int sort_by_defaultness (object $a, object $b)
  • object $a
  • object $b
update_experiment (line 214)

Update an experiment's specification

INDIVIDUAL EXPERIMENT FUNCTIONS
Update the experiments table's entry for the given experiment id, putting some pre-specified parameters into columns, and everything else gets serialized into the "data" column. Information on variants and a new status string can also be specified in the experiment data, but will simply be passed on to update_experiment_variants() and update_experiment_status()

The given experiment data is first merged with the current experiment data so that no data is lost, using array_replace_recursive().

void update_experiment (int $experiment_id, array|object $experiment_data)
  • int $experiment_id
  • array|object $experiment_data
update_experiment_status (line 315)

Update the specified experiment's status code.

INDIVIDUAL EXPERIMENT FUNCTIONS

Will set the start_time when setting to "active", and the end_time when setting to "finished".

void update_experiment_status (int $experiment_id, string $status)
  • int $experiment_id
  • string $status
update_experiment_variant (line 545)

Update an experiment variant

EXPERIMENT VARIANT FUNCTIONS

void update_experiment_variant (int $experiment_id, int $variant_id, array|object $variant_data)
  • int $experiment_id
  • int $variant_id
  • array|object $variant_data
update_experiment_variants (line 589)

Update multiple variants of an experiment

EXPERIMENT VARIANT FUNCTIONS

void update_experiment_variants (int $experiment_id, array $variants)
  • int $experiment_id
  • array $variants: variants specifications, keyed by variant id
update_variants_type (line 337)

Update the variant type of the specified experiment

INDIVIDUAL EXPERIMENT FUNCTIONS

void update_variants_type (int $experiment_id, string $variants_type)
  • int $experiment_id
  • string $variants_type
update_visitor_metric (line 617)

Update a metric value for the given visitor

void update_visitor_metric (int $experiment_id, float $value, boolean $monotonic, int $visitor_id)
  • int $experiment_id
  • float $value
  • boolean $monotonic: if true, will only update if the value is greater (optional)
  • int $visitor_id
w_rand (line 789)

Take an associated array with numerical values and returns a weighted-random key

HELPER FUNCTIONS

void w_rand ( $weights)
  • $weights
zscore (line 815)

Compute a z-score based on the control's stats and the variant's stats

HELPER FUNCTIONS

float zscore (array $control, array $variant)
  • array $control
  • array $variant

Documentation generated on Sat, 04 Sep 2010 23:40:57 -0400 by phpDocumentor 1.4.3