@@ -15,13 +15,13 @@ |
||
| 15 | 15 | |
| 16 | 16 | // a weight of 0 means selections in that category do not increase the score |
| 17 | 17 | public static $categories = [ |
| 18 | - [ "id" => 1, "weight" => 0, "name" => "Restoration"], |
|
| 19 | - [ "id" => 2, "weight" => 1, "name" => "Forgetting Priorities"], |
|
| 20 | - [ "id" => 3, "weight" => 2, "name" => "Anxiety"], |
|
| 21 | - [ "id" => 4, "weight" => 4, "name" => "Speeding Up"], |
|
| 22 | - [ "id" => 5, "weight" => 6, "name" => "Ticked Off"], |
|
| 23 | - [ "id" => 6, "weight" => 8, "name" => "Exhausted"], |
|
| 24 | - [ "id" => 7, "weight" => 10, "name" => "Relapse/Moral Failure"], |
|
| 18 | + ["id" => 1, "weight" => 0, "name" => "Restoration"], |
|
| 19 | + ["id" => 2, "weight" => 1, "name" => "Forgetting Priorities"], |
|
| 20 | + ["id" => 3, "weight" => 2, "name" => "Anxiety"], |
|
| 21 | + ["id" => 4, "weight" => 4, "name" => "Speeding Up"], |
|
| 22 | + ["id" => 5, "weight" => 6, "name" => "Ticked Off"], |
|
| 23 | + ["id" => 6, "weight" => 8, "name" => "Exhausted"], |
|
| 24 | + ["id" => 7, "weight" => 10, "name" => "Relapse/Moral Failure"], |
|
| 25 | 25 | ]; |
| 26 | 26 | |
| 27 | 27 | public static $colors = [ |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | ->groupBy('date, user_id') |
| 86 | 86 | ->having('user_id = :user_id'); |
| 87 | 87 | $temp_dates = $query->all(); |
| 88 | - foreach($temp_dates as $temp_date) { |
|
| 88 | + foreach ($temp_dates as $temp_date) { |
|
| 89 | 89 | $past_checkin_dates[] = $this->time->convertUTCToLocal($temp_date['date']); |
| 90 | 90 | } |
| 91 | 91 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | public function getDailyScore($date = null) { |
| 116 | 116 | // default to today's score |
| 117 | - if(is_null($date)) $date = $this->time->getLocalDate(); |
|
| 117 | + if (is_null($date)) $date = $this->time->getLocalDate(); |
|
| 118 | 118 | |
| 119 | 119 | list($start, $end) = $this->time->getUTCBookends($date); |
| 120 | 120 | $score = $this->calculateScoreByUTCRange($start, $end); |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | public function calculateScoresOfLastMonth() { |
| 150 | - $key = "scores_of_last_month_".Yii::$app->user->id."_".$this->time->getLocalDate(); |
|
| 150 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $this->time->getLocalDate(); |
|
| 151 | 151 | $scores = Yii::$app->cache->get($key); |
| 152 | - if($scores === false) { |
|
| 152 | + if ($scores === false) { |
|
| 153 | 153 | $scores = []; |
| 154 | 154 | |
| 155 | 155 | $dt = new DateTime("now", new DateTimeZone("UTC")); |
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | public function calculateScore($usr_bhvrs, $all_cats = null) { |
| 169 | - if(!!!$usr_bhvrs) return []; |
|
| 170 | - if(!!!$all_cats) $all_cats = $this->behavior->getCategories(); |
|
| 169 | + if (!!!$usr_bhvrs) return []; |
|
| 170 | + if (!!!$all_cats) $all_cats = $this->behavior->getCategories(); |
|
| 171 | 171 | |
| 172 | 172 | $usr_bhvrs = array_reduce($usr_bhvrs, function($carry, $bhvr) { |
| 173 | 173 | $date = $this->time->convertUTCToLocal($bhvr['date']); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | }, []); |
| 177 | 177 | |
| 178 | 178 | $scores = []; |
| 179 | - foreach($usr_bhvrs as $date => $bhvrs) { |
|
| 179 | + foreach ($usr_bhvrs as $date => $bhvrs) { |
|
| 180 | 180 | $picked = array_reduce($bhvrs, function($carry, $bhvr) { |
| 181 | 181 | $carry[$bhvr['category_id']][] = $bhvr['id']; |
| 182 | 182 | return $carry; |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | private function _getCatGrades($picked, $all_cats = null) { |
| 193 | - if(!!!$all_cats) $all_cats = $this->behavior->getCategories(); |
|
| 193 | + if (!!!$all_cats) $all_cats = $this->behavior->getCategories(); |
|
| 194 | 194 | |
| 195 | 195 | return array_reduce($all_cats, function($carry, $cat) use($picked) { |
| 196 | - if(array_key_exists($cat['category_id'], $picked)) { |
|
| 196 | + if (array_key_exists($cat['category_id'], $picked)) { |
|
| 197 | 197 | $count = count($picked[$cat['category_id']]); |
| 198 | - $prcnt_2x = ($count / $cat['behavior_count']) * 2; |
|
| 198 | + $prcnt_2x = ($count/$cat['behavior_count'])*2; |
|
| 199 | 199 | // because we're doubling the % we want to ensure we don't take more than 100% |
| 200 | - $carry[$cat['category_id']] = $cat['weight'] * min($prcnt_2x, 1); |
|
| 200 | + $carry[$cat['category_id']] = $cat['weight']*min($prcnt_2x, 1); |
|
| 201 | 201 | } else { |
| 202 | 202 | $carry[$cat['category_id']] = 0; |
| 203 | 203 | } |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $colors = \common\models\Category::$colors; |
| 221 | 221 | $arr = array_reduce(self::decorateWithCategory($this->getBehaviorsWithCounts()), function($acc, $row) use ($colors) { |
| 222 | 222 | $cat_id = $row['behavior']['category']['id']; |
| 223 | - if(array_key_exists($cat_id, $acc)) { |
|
| 223 | + if (array_key_exists($cat_id, $acc)) { |
|
| 224 | 224 | $acc[$cat_id]['count'] += $row['count']; |
| 225 | 225 | } else { |
| 226 | 226 | $acc[$cat_id] = [ |
@@ -237,10 +237,10 @@ discard block |
||
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | public static function decorate(Array $uo, $with_category = false) { |
| 240 | - foreach($uo as &$o) { |
|
| 241 | - if($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
| 240 | + foreach ($uo as &$o) { |
|
| 241 | + if ($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
| 242 | 242 | $o['behavior'] = $behavior; |
| 243 | - if($with_category) { |
|
| 243 | + if ($with_category) { |
|
| 244 | 244 | $o['behavior']['category'] = \common\models\Category::getCategory('id', $o['behavior']['category_id']); |
| 245 | 245 | } |
| 246 | 246 | } |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | ->groupBy('behavior_id, user_id') |
| 261 | 261 | ->having('user_id = :user_id') |
| 262 | 262 | ->orderBy('count DESC'); |
| 263 | - if($limit) { |
|
| 263 | + if ($limit) { |
|
| 264 | 264 | $query->limit($limit); |
| 265 | 265 | } |
| 266 | 266 | |
@@ -35,12 +35,12 @@ |
||
| 35 | 35 | <th>Behavior</th> |
| 36 | 36 | <th>Category</th> |
| 37 | 37 | </tr> |
| 38 | -<?php foreach($top_behaviors as $key => $row) { |
|
| 38 | +<?php foreach ($top_behaviors as $key => $row) { |
|
| 39 | 39 | $num = $key + 1; |
| 40 | -print "<tr>". |
|
| 41 | - "<td>{$row['count']}</td>". |
|
| 42 | - "<td>{$row['behavior']['name']}</td>". |
|
| 43 | - "<td>{$row['behavior']['category']['name']}</td>". |
|
| 40 | +print "<tr>" . |
|
| 41 | + "<td>{$row['count']}</td>" . |
|
| 42 | + "<td>{$row['behavior']['name']}</td>" . |
|
| 43 | + "<td>{$row['behavior']['category']['name']}</td>" . |
|
| 44 | 44 | "</tr>"; |
| 45 | 45 | } |
| 46 | 46 | ?> |