Reference: https://github.com/etsy/statsd/blob/master/README.md
Sampling 0.1
Tells StatsD that this counter is being sent sampled every 1/10th of the time.

@param mixed $data
@param int   $sampleRate

@return mixed $data
765852
public function appendSampleRate($data, $sampleRate = 1)
    {
        if ($sampleRate < 1) {
            array_walk($data, function(&$message, $key) use ($sampleRate) {
                $message = sprintf('%s|@%s', $message, $sampleRate);
            });
        }

        return $data;
    }
1103928
public static function _getDataTime_stemp(string $data): string
    {
        self::$tempo_da_sessao = strtotime($data);

        return self::inserir_tempo(self::$tempo_da_sessao);
    }
1107893
public function checkData($data)
    {
        $class_name = $this->getTypeClassName();

        if (!$data instanceof $class_name) {
            $data = $this->createObjectFrom($data);
        }

        return $data;
    }
780997
public static function random($data = false) {

        if($data) {

            if(Validate::isObject($data)) {

                $data = Format::objectToArray($data);
            }

            if(Validate::isArray($data)) {

                return $data[array_rand($data, 1)];
            } 
        }

        return false;
    }
1132197
protected function calculate_sample($sampleid, $sampleorigin, $starttime = false, $endtime = false) {
        global $DB;

        if (!$logstore = \core_analytics\manager::get_analytics_logstore()) {
            throw new \coding_exception('No available log stores');
        }

        // Filter by context to use the logstore_standard_log db table index.
        $course = $this->retrieve('course', $sampleid);
        $select = "courseid = :courseid AND anonymous = :anonymous AND (crud = 'c' OR crud = 'u')";
        $params = array('courseid' => $course->id, 'anonymous' => '0');

        if ($user = $this->retrieve('user', $sampleid)) {
            $select .= " AND userid = :userid";
            $params['userid'] = $user->id;
        }

        if ($starttime) {
            $select .= " AND timecreated > :starttime";
            $params['starttime'] = $starttime;
        }
        if ($endtime) {
            $select .= " AND timecreated <= :endtime";
            $params['endtime'] = $endtime;
        }

        $nlogs = $logstore->get_events_select_count($select, $params);
        if ($nlogs) {
            return self::get_max_value();
        } else {
            return self::get_min_value();
        }
    }
285805
protected function calculate_sample($sampleid, \core_analytics\analysable $course, $starttime = false, $endtime = false) {

        $userenrol = $this->retrieve('user_enrolments', $sampleid);

        // We use completion as a success metric.
        $ccompletion = new \completion_completion(array('userid' => $userenrol->userid, 'course' => $course->get_id()));
        if ($ccompletion->is_complete()) {
            return 0;
        } else {
            return 1;
        }
    }
17714
public function getStatisticData($lastDays = 10)
    {
        $timestamp = DateTimer::getZeroTimeStamp(strtotime('-' . $lastDays - 1 . ' days'));
        $dateTime = DateTimer::getDateTime4TimeStamp($timestamp);

        $donateEntity = $this->getDonateLogEntity();
        $typList = $donateEntity->getDonateTypes();
        $donateHistory = $donateEntity->getDonateHistorySuccess($dateTime);
        $result = [];

        // set some default values
        $range = DateTimer::getDateRange4Period($dateTime, new \DateTime());
        foreach ($range as $date) {
            foreach ($typList as $type) {
                $result[$date->format('Y-m-d')][$type] = [
                    'amount' => 0,
                    'coins' => 0
                ];
            }
        }

        if ($donateHistory) {
            foreach ($donateHistory as $donateData) {
                /** @var \DateTime $date */
                $date = $donateData['created'];
                $result[$date->format('Y-m-d')][$donateData['type']]['amount'] += $donateData['amount'];
                $result[$date->format('Y-m-d')][$donateData['type']]['coins'] += $donateData['coins'];
            }
        }

        return $result;
    }
1068196
public static function Input($data)
    {

      /** handle a multiple ensure **/
     
      $args = func_get_args();
      if (count($args) > 1) {
          return EnsureResource::InputTwo($args); 
      }

      if ($data instanceof DataPacket || $data instanceof DataPacketCollection)
          return $data;
      /** empty if not set **/
      if (!isset($data) || $data == null)
          return new DataPacket(array());

      if ($data instanceof Parameters)
          return new DataPacket($data->data);

      if (isset($data[0]) && $data[0] instanceof Parameters)
          return new DataPacket($data[0]->data);

      if ($data instanceof CollectionObject || is_string($data) ||
          $data instanceof BaML || $data instanceof BaMLAttribute || $data instanceof BaMLVerb)
      return new DataPacket($data);

      if (isset($data[0]) && isset($data[1]) && !is_array($data[0]) && is_array($data[1])) 
         return new DataPacket(array_merge(array($data[0]), $data[1]));

      if (isset($data[0]) && is_array($data) && BaseUtilities::is_multidimensional($data) && is_array($data[0]) && sizeof($data) == 1)
        return new DataPacket($data[0]);

      if (!(is_array($data) || $data instanceof \stdClass))
        Throw new \CatapultApiException(EXCEPTIONS::WRONG_PARAMETERS);

      if (!($data instanceof DataPacket && is_multidimensional($data)))
        return new DataPacket($data);

      if (!($data instanceof DataPacketCollection))
        return new DataPacketCollection($data);
    }
917640
public function insertData($data)
    {
        $sql = $this->getInsertSql($data);
        try {
            $result = app("db")->insert($sql);
        } catch (\Exception $e) {
            Log::info('c=CopydataApiController f=insertData  msg=' . $e->getMessage());
            return false;
        }
        return $result;

    }
112742
public function formatInput($data)
    {
        if ($data) {
            if (is_numeric(key($data))) {
                foreach ($data as $k => $v){
                    if (is_numeric($k) && is_array($v)) {
                        $data[$k] = static::formatInputRecord($v);
                    }
                }
            } else {
                $data = static::formatInputRecord($data);
            }
        }
        return $data;
    }
59477
protected function save_train_samples(array $sampleids, \core_analytics\local\time_splitting\base $timesplitting) {
        global $DB;

        $trainingsamples = new \stdClass();
        $trainingsamples->modelid = $this->analyser->get_modelid();
        $trainingsamples->analysableid = $timesplitting->get_analysable()->get_id();
        $trainingsamples->timesplitting = $timesplitting->get_id();

        $trainingsamples->sampleids = json_encode($sampleids);
        $trainingsamples->timecreated = time();

        $DB->insert_record('analytics_train_samples', $trainingsamples);
    }
190187
public static function insertStats( array $data )
    {
        $vars = array_values( eZPerfLoggerINI::variable( 'GeneralSettings', 'TrackVariables' ) );
        foreach( $data as $datapoint )
        {
            foreach( $datapoint['counters'] as $i => $value )
            {
                $varname = $vars[$i];
                if ( !isset( self::$stats[$varname]['min'] ) || self::$stats[$varname]['min'] > $value )
                {
                    self::$stats[$varname]['min'] = $value;
                }
                if ( !isset( self::$stats[$varname]['max'] ) || self::$stats[$varname]['max'] < $value )
                {
                    self::$stats[$varname]['max'] = $value;
                }
                self::$stats[$varname]['total'] = self::$stats[$varname]['total'] + $value;
            }
        }
        self::$statsCount = self::$statsCount + count( $data );
    }
651776
protected function calculate_sample($sampleid, \core_analytics\analysable $course, $starttime = false, $endtime = false) {

        $userenrol = $this->retrieve('user_enrolments', $sampleid);

        // Get course grade to pass.
        $courseitem = $this->get_course_gradetopass($course->get_id());

        // Get the user grade.
        $usergrade = $this->get_user_grade($courseitem['courseitemid'], $userenrol->userid);

        if ($usergrade >= $courseitem['gradetopass']) {
            return 0;
        }

        return 1;
    }
705005
public function getTimingsAccumulator( array $timerData )
    {
        $groups = $this->getGroups( $timerData );
        $res = array();

        if ( sizeof( $groups ) > 0 )
        {
            foreach ( $groups as $groupName => $group )
            {
                $groupStats = new stdClass();

                // Calculate the total time.
                foreach ( $group->elements as $name => $element )
                {
                    $elapsedTime = sprintf( '%.5f', $element->elapsedTime );
                    $percent = sprintf( '%.2f', (100 * ($element->elapsedTime / $group->elapsedTime ) ) );
                    $average = sprintf( '%.5f', ( $element->elapsedTime / $element->count ) );
                    $groupInfos = new stdClass();
                    $groupInfos->name = $name;
                    $groupInfos->elapsed = $elapsedTime;
                    $groupInfos->percent = $percent.' %';
                    $groupInfos->count = $element->count;
                    $groupInfos->average = $average;
                    $groupInfos->switches = array();

                    foreach ( $element->switchTime as $switch )
                    {
                        $switchInfos = new stdClass();
                        $elapsedTime = sprintf( '%.5f', $switch->time - $element->startTime );
                        $percent = sprintf( '%.2f', ( 100 * ( $elapsedTime / $group->elapsedTime ) ) );
                        $switchInfos->name = $switch->name;
                        $switchInfos->elapsed = $elapsedTime;
                        $switchInfos->percent = $percent.' %';

                        $groupInfos->switches[] = $switchInfos;
                    }

                    $groupStats->elements[] = $groupInfos;
                }

                if ( $group->count > 1 )
                {
                    $elapsedTime = sprintf( '%.5f', $group->elapsedTime );
                    $average = sprintf( '%.5f', ( $group->elapsedTime / $group->count ) );
                    $groupStats->totalElapsed = $elapsedTime;
                    $groupStats->count = $group->count;
                    $groupStats->average = $average;
                }

                $res[$groupName] = $groupStats;
            }
        }

        return $res;
    }
521967
public function counter($metric, $count = 1, array $tags = array(), $sampleRate = AbstractMetric::DEFAULT_SAMPLE_RATE)
    {
        return new Counter($this->prefix($metric), $count, array_merge($this->defaultTags, $tags), $sampleRate);
    }
1119211
protected function calculate_sample($sampleid, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) {

        $noteachersindicator = $this->retrieve('\core_course\analytics\indicator\no_teacher', $sampleid);
        $nostudentsindicator = $this->retrieve('\core_course\analytics\indicator\no_student', $sampleid);
        if ($noteachersindicator == \core_course\analytics\indicator\no_teacher::get_min_value() ||
                $nostudentsindicator == \core_course\analytics\indicator\no_student::get_min_value()) {
            // No teachers or no students :(.
            return 1;
        }
        return 0;
    }
591465
public static function count($data = false) {

        if ($data && Validate::isArray($data)) {

            return count($data);
        } else if ($data && Validate::isObject($data)) {

            return count(get_object_vars($data));
        }

        return 0;
    }