当前位置: 首页>>代码示例>>PHP>>正文


PHP Calculator::currentMetrics方法代码示例

本文整理汇总了PHP中Calculator::currentMetrics方法的典型用法代码示例。如果您正苦于以下问题:PHP Calculator::currentMetrics方法的具体用法?PHP Calculator::currentMetrics怎么用?PHP Calculator::currentMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Calculator的用法示例。


在下文中一共展示了Calculator::currentMetrics方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: showSinglestat

 public function showSinglestat($statID)
 {
     if (Auth::check()) {
         return Redirect::route('connect.connect');
     } else {
         try {
             $user = User::find(1);
             Auth::login($user);
             $currentMetrics = Calculator::currentMetrics();
             $metricValues = Metric::where('user', Auth::user()->id)->where('date', '<', Carbon::now())->orderBy('date', 'desc')->take(31)->get();
             foreach ($currentMetrics as $metricID => $statClassName) {
                 if ($metricID == $statID) {
                     $metricsArray = array();
                     foreach ($metricValues as $metric) {
                         $metricsArray[$metric->date] = $metric->{$metricID};
                     }
                     ksort($metricsArray);
                     $allMetrics[$metricID] = $metricsArray;
                 }
             }
             if (isset($currentMetrics[$statID])) {
                 return View::make('demo.single_stat', array('data' => $currentMetrics[$statID]['metricClass']::show($allMetrics[$statID], true), 'metricDetails' => $currentMetrics[$statID], Auth::logout()));
             }
             return Redirect::route('demo.dashboard')->with('error', 'Statistic does not exist.');
         } catch (Exception $e) {
             Auth::logout();
             Log::error($e);
             return Redirect::route('demo.dashboard')->with('error', 'Something went wrong, we will return shortly.');
         }
     }
 }
开发者ID:raschan,项目名称:fruit-dashboard,代码行数:31,代码来源:DemoController.php

示例2: formatMetrics

 public function formatMetrics()
 {
     // get currently calculated metrics
     $currentMetrics = Calculator::currentMetrics();
     $this->date = Carbon::createFromFormat('Y-m-d', $this->date)->format('Y-m-d, l');
     // go through them
     foreach ($currentMetrics as $statID => $statName) {
         if (is_null($this->{$statID})) {
             $this->{$statID} = 'Not enough data';
         } else {
             switch ($statID) {
                 // money formats fall through
                 case 'mrr':
                 case 'arr':
                 case 'arpu':
                     // divide the value by 100
                     $this->{$statID} /= 100;
                     // format it into money
                     setlocale(LC_MONETARY, 'en_US');
                     $this->{$statID} = money_format('%n', $this->{$statID});
                     break;
                     // percent formats fall through
                 // percent formats fall through
                 case 'uc':
                     $this->{$statID} = $this->{$statID} . '%';
                     break;
                     // pieces formats fall through
                 // pieces formats fall through
                 case 'cancellations':
                 case 'au':
                     break;
                 default:
                     break;
             }
             // /switch
         }
         // /if
     }
     // /foreach
 }
开发者ID:raschan,项目名称:fruit-dashboard,代码行数:40,代码来源:Metric.php

示例3: showSinglestat

 public function showSinglestat($statID)
 {
     // check if trial period is ended
     if (Auth::user()->isTrialEnded()) {
         return Redirect::route('auth.plan')->with('error', 'Trial period ended.');
     }
     $currentMetrics = Calculator::currentMetrics();
     $metricValues = Metric::where('user', Auth::user()->id)->orderBy('date', 'desc')->take(31)->get();
     foreach ($currentMetrics as $metricID => $statClassName) {
         $metricsArray = array();
         foreach ($metricValues as $metric) {
             $metricsArray[$metric->date] = $metric->{$metricID};
         }
         ksort($metricsArray);
         $allMetrics[$metricID] = $metricsArray;
     }
     if (isset($currentMetrics[$statID])) {
         return View::make('auth.single_stat', array('data' => $currentMetrics[$statID]['metricClass']::show($allMetrics[$statID], true), 'metricDetails' => $currentMetrics[$statID]));
     } else {
         return Redirect::route('auth.dashboard')->with('error', 'Statistic does not exist.');
     }
 }
开发者ID:raschan,项目名称:fruit-dashboard,代码行数:22,代码来源:AuthController.php

示例4: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // get all the users
     $users = User::all();
     $previousDayDate = Carbon::yesterday()->toDateString();
     // currently calculated metrics
     $currentMetrics = Calculator::currentMetrics();
     // for each user send email with their metrics
     $dailyEmailSent = 0;
     $weeklyEmailSent = 0;
     foreach ($users as $user) {
         // check if user finished the connect process
         if ($user->isConnected() && $user->ready == 'connected' && !$user->isTrialEnded()) {
             switch ($user->summaryEmailFrequency) {
                 case 'none':
                     // no summary email
                     break;
                 case 'daily':
                     // default behavior, send yesterday's data
                     // get the user's metrics
                     $metric = Metric::where('user', $user->id)->where('date', $previousDayDate)->first();
                     if ($metric) {
                         $previousMetrics = Metric::where('user', $user->id)->where('date', '<=', Carbon::yesterday()->subDays(30)->toDateString())->orderBy('date', 'desc')->first();
                         $changes = array();
                         foreach ($currentMetrics as $metricID => $metricDetails) {
                             // get the correct color
                             $changes[$metricID]['positiveIsGood'] = $metricDetails['metricClass']::POSITIVE_IS_GOOD;
                             $date = $metric->date;
                             if ($previousMetrics) {
                                 if ($previousMetrics->{$metricID} != 0) {
                                     $value = $metric->{$metricID} / $previousMetrics->{$metricID} * 100 - 100;
                                     $changes[$metricID][$date]['isBigger'] = $value > 0 ? true : false;
                                     $changes[$metricID][$date]['value'] = round($value) . ' %';
                                 } else {
                                     $changes[$metricID][$date]['value'] = null;
                                 }
                             } else {
                                 $changes[$metricID][$date]['value'] = null;
                             }
                         }
                         // format metrics to presentable data
                         $metric->formatMetrics();
                         // this line is for making the daily email the same format as the weekly
                         // so we only need one email template
                         $metrics = array($metric->date => $metric);
                         $data = array('metrics' => $metrics, 'currentMetrics' => $currentMetrics, 'changes' => $changes, 'isDaily' => true, 'index' => 0);
                         $email = Mailman::make('emails.summary')->with($data)->to($user->email)->subject('Daily summary')->send();
                         //File::put(public_path().'/summary_email.html',$email);
                         $dailyEmailSent++;
                     }
                     break;
                 case 'weekly':
                     // send a weekly summary to the user with their numbers
                     // check if today is monday (we send weekly emails on monday)
                     /* improvment idea
                     				change this if to switch-case with days
                     				for user controlled daily send
                     			*/
                     if (Carbon::now()->dayOfWeek == Carbon::WEDNESDAY) {
                         // get the user's metrics
                         $metrics = Metric::where('user', $user->id)->where('date', '<=', $previousDayDate)->orderBy('date', 'desc')->take(7)->get();
                         $previousMetrics = Metric::where('user', $user->id)->where('date', '<=', Carbon::yesterday()->subDays(30)->toDateString())->orderBy('date', 'desc')->take(7)->get();
                         $changes = array();
                         foreach ($currentMetrics as $metricID => $metricDetails) {
                             // get the correct color
                             $changes[$metricID]['positiveIsGood'] = $metricDetails['metricClass']::POSITIVE_IS_GOOD;
                             foreach ($previousMetrics as $id => $prevMetric) {
                                 $date = $metrics[$id]->date;
                                 if ($prevMetric->{$metricID} != 0) {
                                     $value = $metrics[$id]->{$metricID} / $prevMetric->{$metricID} * 100 - 100;
                                     $changes[$metricID][$date]['isBigger'] = $value > 0 ? true : false;
                                     $changes[$metricID][$date]['value'] = round($value) . ' %';
                                 } else {
                                     $changes[$metricID][$date]['value'] = null;
                                 }
                             }
                         }
                         // format metrics to presentable data
                         $weeklyMetrics = array();
                         foreach ($metrics as $metric) {
                             $metric->formatMetrics();
                             $weeklyMetrics[$metric->date] = $metric;
                         }
                         $data = array('metrics' => $weeklyMetrics, 'currentMetrics' => $currentMetrics, 'changes' => $changes, 'isDaily' => false, 'index' => 0);
                         // login the user (necessary to get the email address)
                         // Auth::login($user);
                         // send the email to the user
                         $email = Mailman::make('emails.summary')->with($data)->to($user->email)->subject('Weekly summary')->send();
                         //File::put(public_path().'/summary_email.html',$email);
                         $weeklyEmailSent++;
                     }
                     break;
                 default:
                     Log::error('notifications string has been changed, check the email sending code');
                     break;
//.........这里部分代码省略.........
开发者ID:raschan,项目名称:fruit-dashboard,代码行数:101,代码来源:SendDailyEmail.php


注:本文中的Calculator::currentMetrics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。