本文整理汇总了PHP中Calculator::calculateMetrics方法的典型用法代码示例。如果您正苦于以下问题:PHP Calculator::calculateMetrics方法的具体用法?PHP Calculator::calculateMetrics怎么用?PHP Calculator::calculateMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Calculator
的用法示例。
在下文中一共展示了Calculator::calculateMetrics方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
DB::table('events')->delete();
$currentDay = time();
$user = User::find(1);
// days generated before the current date
$generatedDay = $currentDay - 370 * 24 * 60 * 60;
// generating data for ~2 years
for ($i = 0; $i < 750; $i++) {
// timestamp of the current day
$dailyTimeStamp = $generatedDay + $i * 24 * 60 * 60;
$date = date('Y-m-d', $dailyTimeStamp);
$monthStats = EventSeeder::monthlyStats($dailyTimeStamp);
$eventTimes = EventSeeder::generateEventTimes($monthStats, $dailyTimeStamp);
foreach ($eventTimes as $event) {
$temparray = EventSeeder::getEventType($monthStats, $event);
if ($temparray) {
DB::table('events')->insert(array('user' => $user->id, 'created' => date('Y-m-d H:i:s', $event), 'eventID' => $temparray['id'], 'type' => $temparray['type'], 'object' => $temparray['object'], 'provider' => 'stripe', 'previousAttributes' => $temparray['previousAttributes'], 'date' => date('Y-m-d', $event)));
}
}
// set time to last timestamp +1
$event++;
// calculate all
Calculator::calculateMetrics($user, $event);
}
}
示例2: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
Log::info('CalculateMetrics fired');
// going through the users
foreach (User::all() as $user) {
// check if user is connected and ready (in case he is just connecting), and trial not ended yet
// or it's demo user
if ($user->isStripeConnected() && $user->ready == 'connected' && !$user->isTrialEnded() || $user->id == 1) {
// saving events
Calculator::calculateMetrics($user, time());
}
}
Log::info('CalculateMetrics finished');
}
示例3: calculateMetrics
/**
* daily metric calculator - called from cron script
* @param $user
*
* @return null
*/
public static function calculateMetrics($user, $time)
{
// get needed time vars
if ($time) {
$timestamp = $time;
} else {
$timestamp = time();
}
$today = date('Y-m-d', $timestamp);
$yesterday = date('Y-m-d', $timestamp - 86400);
// get today's metrics
$metrics = Metric::firstOrNew(array('user' => $user->id, 'date' => $today));
// get yesterday's metrics
// this should never return an empty array
$yesterdayMetric = Metric::where('user', $user->id)->where('date', $yesterday)->first();
if (!$yesterdayMetric) {
Calculator::calculateMetrics($user, $timestamp - 86400);
$yesterdayMetric = Metric::where('user', $user->id)->where('date', $yesterday)->first();
}
// get today's events
$events = Event::where('user', $user->id)->where('date', $today)->get();
// events have a provider, needs merging
// FIXME!!!!
// calculate all the metrics
// monthly recurring revenue
// return int
$metrics->mrr = MrrStat::calculate($yesterdayMetric->mrr, $events);
// active users
// return int
$metrics->au = AUStat::calculate($yesterdayMetric->au, $events);
// annual recurring revenue
// return int
$metrics->arr = ArrStat::calculate($metrics->mrr);
// average recurring revenue per active user
// return int
$metrics->arpu = ArpuStat::calculate($metrics->mrr, $metrics->au);
// daily and monthly cancellations
// return array
list($daily, $monthly) = CancellationStat::calculate($events, $user);
$metrics->cancellations = $daily;
$metrics->monthlyCancellations = $monthly;
// user churn
// return float
$metrics->uc = UserChurnStat::calculate($metrics->monthlyCancellations, $user, $timestamp);
// save everything
$metrics->save();
}