示例#1
0
 /**
  * Calculate stats for the whole group
  *
  * @since 0.4.0
  *
  * @access protected
  */
 protected function group_stats()
 {
     $total = $conversions = 0;
     $rates = [];
     foreach ($this->stats['variants'] as $variant) {
         $total = $total + $variant->total;
         $conversions = $conversions + $variant->conversions;
         $rates[] = $variant->conversion_rate;
     }
     $avg_conversion_rate = Statistics::mean($rates);
     if (0 == $total) {
         $conversion_rate = 0;
     } else {
         $conversion_rate = $conversions / $total;
     }
     //$std_deviation = Statistics::standardDeviation( $rates );
     $this->stats['group'] = new stats($total, $conversions, $conversion_rate, $avg_conversion_rate);
 }
示例#2
0
 /**
  * Calculate the average sessions and set in average property
  *
  * @access private
  *
  * @since 1.1.0
  *
  * @param bool $unique Optional. To get unique values or not. Default is true.
  */
 private function calculate_average($unique = true)
 {
     $what = $this->what($unique);
     if (empty($this->weeks[$what])) {
         $this->find_weeks(4, $unique);
     }
     if (1 >= count($this->weeks[$what]) && isset($this->weeks[$what][0])) {
         $this->average[$what] = $this->weeks[$what][0];
     } elseif (1 >= count($this->weeks[$what]) && !isset($this->weeks[$what][0])) {
         $this->average[$what] = 0;
     } else {
         $this->average[$what] = Statistics::mean($this->weeks[$what]);
     }
 }