Exemplo n.º 1
0
 private function convertWeapons2Sub($in)
 {
     $ret = [];
     foreach (Subweapon::find()->all() as $sub) {
         $ret[$sub->key] = (object) ['name' => Yii::t('app-subweapon', $sub->name), 'count' => 0, 'sum_kill' => 0, 'sum_death' => 0, 'win_count' => 0, 'avg_kill' => null, 'avg_death' => null, 'wp' => null, 'encounter_3' => null, 'encounter_4' => null];
     }
     foreach ($in->weapons as $weapon) {
         $o = $ret[$weapon->subweapon->key];
         $o->count += $weapon->count;
         $o->sum_kill += $weapon->sum_kill;
         $o->sum_death += $weapon->sum_death;
         $o->win_count += $weapon->win_count;
     }
     foreach ($ret as $o) {
         if ($o->count > 0) {
             $o->avg_kill = $o->sum_kill / $o->count;
             $o->avg_death = $o->sum_death / $o->count;
             $o->wp = $o->win_count * 100 / $o->count;
             $encounterRate = $o->count / $in->player_count;
             $o->encounter_3 = 100 * (1 - pow(1 - $encounterRate, 3));
             $o->encounter_4 = 100 * (1 - pow(1 - $encounterRate, 4));
         }
     }
     usort($ret, function ($a, $b) {
         foreach (['count', 'wp', 'avg_kill', 'avg_death'] as $key) {
             $tmp = $b->{$key} - $a->{$key};
             if ($tmp != 0) {
                 return $tmp;
             }
         }
         return strnatcasecmp($a->name, $b->name);
     });
     return $ret;
 }
Exemplo n.º 2
0
 private function makeWeaponsListSubweapons(User $user)
 {
     $query = Subweapon::find()->andWhere(['in', 'id', array_map(function ($model) {
         return $model->subweapon_id;
     }, Weapon::findAll($this->getUsedWeaponIdList($user)))]);
     $ret = [];
     foreach ($query->all() as $item) {
         $ret['+' . $item->key] = Yii::t('app-subweapon', $item->name);
     }
     if (count($ret) < 2) {
         return [];
     }
     asort($ret);
     return [Yii::t('app', 'Sub Weapon') => $ret];
 }
Exemplo n.º 3
0
 private function makeWeaponsListSubweapons()
 {
     $ret = [];
     foreach (Subweapon::find()->all() as $item) {
         $ret['+' . $item->key] = Yii::t('app-subweapon', $item->name);
     }
     asort($ret);
     return [Yii::t('app', 'Sub Weapon') => $ret];
 }