Beispiel #1
0
 public function run()
 {
     $rules = [];
     $query = Rule::find()->innerJoinWith('mode')->andWhere(['{{game_mode}}.[[key]]' => 'gachi']);
     foreach ($query->all() as $rule) {
         $rules[$rule->id] = Yii::t('app-rule', $rule->name);
     }
     asort($rules);
     $maps = [];
     foreach (Map::find()->all() as $map) {
         $maps[$map->id] = Yii::t('app-map', $map->name);
     }
     asort($maps);
     // init data
     $data = [];
     foreach (array_keys($maps) as $mapId) {
         $data[$mapId] = [];
         foreach (array_keys($rules) as $ruleId) {
             $data[$mapId][$ruleId] = (object) ['battle_count' => 0, 'ko_count' => 0];
         }
     }
     // set data
     foreach ($this->query() as $row) {
         $ruleId = $row['rule_id'];
         $mapId = $row['map_id'];
         $data[$mapId][$ruleId]->battle_count = (int) $row['battle_count'];
         $data[$mapId][$ruleId]->ko_count = (int) $row['ko_count'];
     }
     return $this->controller->render('knockout.tpl', ['rules' => $rules, 'maps' => $maps, 'data' => $data]);
 }
 private function getData(User $user, BattleFilterForm $filter)
 {
     $query = (new \yii\db\Query())->select(['map_key' => 'MAX({{map}}.[[key]])', 'rule_key' => 'MAX({{rule}}.[[key]])', 'result' => '(CASE WHEN {{battle}}.[[is_win]] = TRUE THEN \'win\' ELSE \'lose\' END)', 'count' => 'COUNT(*)'])->from('battle')->innerJoin('map', '{{battle}}.[[map_id]] = {{map}}.[[id]]')->innerJoin('rule', '{{battle}}.[[rule_id]] = {{rule}}.[[id]]')->leftJoin('lobby', '{{battle}}.[[lobby_id]] = {{lobby}}.[[id]]')->leftJoin('game_mode', '{{rule}}.[[mode_id]] = {{game_mode}}.[[id]]')->leftJoin('weapon', '{{battle}}.[[weapon_id]] = {{weapon}}.[[id]]')->leftJoin('weapon_type', '{{weapon}}.[[type_id]] = {{weapon_type}}.[[id]]')->leftJoin('subweapon', '{{weapon}}.[[subweapon_id]] = {{subweapon}}.[[id]]')->leftJoin('special', '{{weapon}}.[[special_id]] = {{special}}.[[id]]')->andWhere(['{{battle}}.[[user_id]]' => $user->id])->andWhere(['in', '{{battle}}.[[is_win]]', [true, false]])->groupBy(['{{battle}}.[[map_id]]', '{{battle}}.[[rule_id]]', '{{battle}}.[[is_win]]']);
     if ($filter && !$filter->hasErrors()) {
         $this->filter($query, $filter);
     }
     $maps = Map::find()->all();
     $rules = Rule::find()->all();
     $ret = [];
     foreach ($maps as $map) {
         $tmp = [];
         foreach ($rules as $rule) {
             $tmp[$rule->key] = ['win' => 0, 'lose' => 0];
         }
         $ret[$map->key] = $tmp;
     }
     foreach ($query->createCommand()->queryAll() as $row) {
         $row = (object) $row;
         $ret[$row->map_key][$row->rule_key][$row->result] = (int) $row->count;
     }
     $maps2 = [];
     foreach ($maps as $map) {
         $maps2[$map->key] = Yii::t('app-map', $map->name);
     }
     asort($maps2);
     $rules2 = [];
     foreach ($rules as $rule) {
         $rules2[$rule->key] = Yii::t('app-rule', $rule->name);
     }
     asort($rules2);
     return ['data' => $ret, 'mapNames' => $maps2, 'ruleNames' => $rules2];
 }
 public function safeDown()
 {
     $this->delete('splapi_map', ['map_id' => array_map(function ($a) {
         return $a->id;
     }, Map::findAll(['key' => ['shottsuru', 'anchovy']]))]);
     $this->delete('map', ['key' => ['shottsuru', 'anchovy']]);
 }
Beispiel #4
0
 public function run()
 {
     $response = Yii::$app->getResponse();
     $response->format = 'json';
     return array_map(function ($map) {
         return $map->toJsonArray();
     }, Map::find()->all());
 }
 private function makeMapsList()
 {
     $ret = [];
     foreach (Map::find()->all() as $map) {
         $ret[$map->key] = Yii::t('app-map', $map->name);
     }
     asort($ret);
     return array_merge(['' => Yii::t('app-map', 'Any Map')], $ret);
 }
 /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $routeName = 'dashboard';
     $routeMethod = 'index';
     $users = \App\Models\User::count();
     $sources = \App\Models\Source::count();
     $maps = \App\Models\Map::count();
     $data = compact('routeName', 'routeMethod', 'users', 'sources', 'maps');
     return view('admin.sections.dashboard.index', $data);
 }
Beispiel #7
0
 /**
  * @return string
  */
 public function actionGetDots()
 {
     $points = Map::find()->all();
     $data = [];
     /* @var $point Map */
     foreach ($points as $point) {
         $item = ['center' => [$point->latitude, $point->longitude], 'name' => $point->type, 'preset' => "3islands#circleDotIcon", 'iconColor' => "#0095b6", 'balloonContent' => $point->type, 'image' => '/images/' . $point->type . '.gif'];
         $data[] = $item;
     }
     return json_encode($data);
 }
 public function up()
 {
     $map = [];
     // [ 'arowana' => 42, ... ]
     foreach (Map::find()->all() as $_) {
         $map[$_->key] = $_->id;
     }
     // 今後表記揺れが発生する可能性があるので map_id を PKEY にはしない
     $this->createTable('splapi_map', ['id' => $this->primaryKey(), 'map_id' => $this->integer()->notNull(), 'name' => $this->string(32)->notNull()->unique()]);
     $this->addForeignKey('fk_splapi_map_1', 'splapi_map', 'map_id', 'map', 'id');
     $this->batchInsert('splapi_map', ['map_id', 'name'], [[$map['arowana'], 'アロワナモール'], [$map['bbass'], 'Bバスパーク'], [$map['dekaline'], 'デカライン高架下'], [$map['hakofugu'], 'ハコフグ倉庫'], [$map['hirame'], 'ヒラメが丘団地'], [$map['hokke'], 'ホッケふ頭'], [$map['kinmedai'], 'キンメダイ美術館'], [$map['mahimahi'], 'マヒマヒリゾート&スパ'], [$map['masaba'], 'マサバ海峡大橋'], [$map['mongara'], 'モンガラキャンプ場'], [$map['mozuku'], 'モズク農園'], [$map['negitoro'], 'ネギトロ炭鉱'], [$map['shionome'], 'シオノメ油田'], [$map['tachiuo'], 'タチウオパーキング']]);
 }
 public function storeLayer($request)
 {
     $layer = new Layer();
     $values = $request->except('_token', '_method', 'map_id', 'source_id');
     $layer->fill($values);
     $map = Map::findOrFail($request->map_id);
     $layer->map()->associate($map);
     $source = Source::findOrFail($request->source_id);
     $layer->source()->associate($source);
     $layer->save();
     return $layer;
 }
 public function rules()
 {
     return [[['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['lobby'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'key'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key', 'when' => function () {
         return substr($this->rule, 0, 1) !== '@';
     }], [['rule'], 'validateGameMode', 'when' => function () {
         return substr($this->rule, 0, 1) === '@';
     }], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key', 'when' => function () {
         return !in_array(substr($this->weapon, 0, 1), ['@', '+', '*'], true);
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => WeaponType::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '@';
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Subweapon::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '+';
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Special::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '*';
     }], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose'], [['term'], 'in', 'range' => ['this-period', 'last-period', '24h', 'today', 'yesterday', 'term']], [['term_from', 'term_to'], 'date', 'format' => 'yyyy-M-d H:m:s']];
 }
 public function rules()
 {
     return [[['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key', 'when' => function () {
         return substr($this->rule, 0, 1) !== '@';
     }], [['rule'], 'validateGameMode', 'when' => function () {
         return substr($this->rule, 0, 1) === '@';
     }], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key', 'when' => function () {
         return !in_array(substr($this->weapon, 0, 1), ['@', '+', '*'], true);
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => WeaponType::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '@';
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Subweapon::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '+';
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Special::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '*';
     }], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose']];
 }
 public function getInkedData()
 {
     $query = Battle::find()->with(['rule', 'map'])->innerJoinWith(['rule', 'map'])->joinWith(['lobby'])->andWhere(['{{battle}}.[[user_id]]' => $this->user->id, '{{rule}}.[[key]]' => 'nawabari'])->andWhere(['not', ['{{battle}}.[[is_win]]' => null]])->andWhere(['not', ['{{battle}}.[[my_point]]' => null]])->andWhere(['or', ['{{battle}}.[[lobby_id]]' => null], ['<>', '{{lobby}}.[[key]]', 'private']])->orderBy('{{battle}}.[[id]] DESC');
     $maps = [];
     foreach (Map::find()->all() as $map) {
         $maps[$map->key] = (object) ['key' => $map->key, 'name' => Yii::t('app-map', $map->name), 'area' => $map->area, 'battles' => [], 'avgInked' => null];
     }
     foreach ($query->each() as $battle) {
         $tmp = $maps[$battle->map->key];
         $tmp->battles[] = (object) ['index' => -1 * count($tmp->battles), 'inked' => max(0, $battle->my_point - ($battle->is_win ? 300 : 0))];
     }
     foreach ($maps as $map) {
         if (!empty($map->battles)) {
             $sum = array_sum(array_map(function ($a) {
                 return $a->inked;
             }, $map->battles));
             $map->avgInked = $sum / count($map->battles);
         }
     }
     uasort($maps, function ($a, $b) {
         return strnatcasecmp($a->name, $b->name);
     });
     return $maps;
 }
Beispiel #13
0
 private function makeMaps()
 {
     $ret = [];
     foreach (Map::find()->all() as $map) {
         $ret[$map->id] = Yii::t('app-map', $map->name);
     }
     asort($ret);
     return static::arrayMerge(['' => Yii::t('app', 'Unknown')], $ret);
 }
Beispiel #14
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMap()
 {
     return $this->hasOne(Map::className(), ['id' => 'map_id']);
 }
 public function toBattle()
 {
     $user = $this->getUser();
     $o = new Battle();
     $o->user_id = $user->id;
     $o->env_id = $user->env_id;
     $o->lobby_id = $this->lobby ? Lobby::findOne(['key' => $this->lobby])->id : null;
     $o->rule_id = $this->rule ? Rule::findOne(['key' => $this->rule])->id : null;
     $o->map_id = $this->map ? Map::findOne(['key' => $this->map])->id : null;
     $o->weapon_id = $this->weapon ? Weapon::findOne(['key' => $this->weapon])->id : null;
     $o->level = $this->level ? (int) $this->level : null;
     $o->level_after = $this->level_after ? (int) $this->level_after : null;
     $o->rank_id = $this->rank ? Rank::findOne(['key' => $this->rank])->id : null;
     $o->rank_after_id = $this->rank_after ? Rank::findOne(['key' => $this->rank_after])->id : null;
     $o->rank_exp = (string) $this->rank_exp != '' ? (int) $this->rank_exp : null;
     $o->rank_exp_after = (string) $this->rank_exp_after != '' ? (int) $this->rank_exp_after : null;
     $o->cash = (string) $this->cash != '' ? (int) $this->cash : null;
     $o->cash_after = (string) $this->cash_after != '' ? (int) $this->cash_after : null;
     $o->is_win = $this->result === 'win' ? true : ($this->result === 'lose' ? false : null);
     $o->rank_in_team = $this->rank_in_team ? (int) $this->rank_in_team : null;
     $o->kill = (string) $this->kill != '' ? (int) $this->kill : null;
     $o->death = (string) $this->death != '' ? (int) $this->death : null;
     $o->gender_id = $this->gender === 'boy' ? 1 : ($this->gender === 'girl' ? 2 : null);
     $o->fest_title_id = $this->fest_title ? FestTitle::findOne(['key' => $this->fest_title])->id : null;
     $o->fest_title_after_id = $this->fest_title_after ? FestTitle::findOne(['key' => $this->fest_title_after])->id : null;
     $o->fest_exp = (string) $this->fest_exp != '' ? (int) $this->fest_exp : null;
     $o->fest_exp_after = (string) $this->fest_exp_after != '' ? (int) $this->fest_exp_after : null;
     $o->my_team_color_hue = $this->my_team_color ? $this->my_team_color['hue'] : null;
     $o->my_team_color_rgb = $this->my_team_color ? vsprintf('%02x%02x%02x', $this->my_team_color['rgb']) : null;
     $o->his_team_color_hue = $this->his_team_color ? $this->his_team_color['hue'] : null;
     $o->his_team_color_rgb = $this->his_team_color ? vsprintf('%02x%02x%02x', $this->his_team_color['rgb']) : null;
     $o->start_at = $this->start_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->start_at) : null;
     $o->end_at = $this->end_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->end_at) : new Now();
     $o->agent_id = null;
     $o->ua_custom = (string) $this->agent_custom == '' ? null : (string) $this->agent_custom;
     $o->at = new Now();
     $o->is_automated = $this->automated === 'yes';
     $o->my_point = (string) $this->my_point != '' ? (int) $this->my_point : null;
     $o->my_team_final_point = (string) $this->my_team_final_point != '' ? (int) $this->my_team_final_point : null;
     $o->his_team_final_point = (string) $this->his_team_final_point != '' ? (int) $this->his_team_final_point : null;
     $o->my_team_final_percent = (string) $this->my_team_final_percent != '' ? sprintf('%.1f', (double) $this->my_team_final_percent) : null;
     $o->his_team_final_percent = (string) $this->his_team_final_percent != '' ? sprintf('%.1f', (double) $this->his_team_final_percent) : null;
     $o->is_knock_out = $this->knock_out === 'yes' ? true : ($this->knock_out === 'no' ? false : null);
     $o->my_team_count = (string) $this->my_team_count != '' ? (int) $this->my_team_count : null;
     $o->his_team_count = (string) $this->his_team_count != '' ? (int) $this->his_team_count : null;
     $o->events = null;
     if ($this->events) {
         $o->events = json_encode($this->events, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     }
     if ($this->gears) {
         $o->headgear_id = $this->processGear('headgear');
         $o->clothing_id = $this->processGear('clothing');
         $o->shoes_id = $this->processGear('shoes');
     }
     if ($this->isTest) {
         $now = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time();
         $o->id = 0;
         foreach ($o->attributes as $k => $v) {
             if ($v instanceof Now) {
                 $o->{$k} = gmdate('Y-m-d H:i:sP', $now);
             }
         }
     }
     return $o;
 }
 public function toBattle()
 {
     $o = new Battle();
     $o->user_id = $this->getUser()->id;
     $o->lobby_id = $this->lobby ? Lobby::findOne(['key' => $this->lobby])->id : null;
     $o->rule_id = $this->rule ? Rule::findOne(['key' => $this->rule])->id : null;
     $o->map_id = $this->map ? Map::findOne(['key' => $this->map])->id : null;
     $o->weapon_id = $this->weapon ? Weapon::findOne(['key' => $this->weapon])->id : null;
     $o->level = $this->level ? (int) $this->level : null;
     $o->level_after = $this->level_after ? (int) $this->level_after : null;
     $o->rank_id = $this->rank ? Rank::findOne(['key' => $this->rank])->id : null;
     $o->rank_after_id = $this->rank_after ? Rank::findOne(['key' => $this->rank_after])->id : null;
     $o->rank_exp = (string) $this->rank_exp != '' ? (int) $this->rank_exp : null;
     $o->rank_exp_after = (string) $this->rank_exp_after != '' ? (int) $this->rank_exp_after : null;
     $o->cash = (string) $this->cash != '' ? (int) $this->cash : null;
     $o->cash_after = (string) $this->cash_after != '' ? (int) $this->cash_after : null;
     $o->is_win = $this->result === 'win' ? true : ($this->result === 'lose' ? false : null);
     $o->rank_in_team = $this->rank_in_team ? (int) $this->rank_in_team : null;
     $o->kill = (string) $this->kill != '' ? (int) $this->kill : null;
     $o->death = (string) $this->death != '' ? (int) $this->death : null;
     $o->gender_id = $this->fest_gender === 'boy' ? 1 : ($this->fest_gender === 'girl' ? 2 : null);
     $o->fest_title_id = $this->fest_rank ? FestTitle::findOne(['key' => $this->fest_rank])->id : null;
     $o->my_team_color_hue = $this->my_team_color ? $this->my_team_color['hue'] : null;
     $o->my_team_color_rgb = $this->my_team_color ? vsprintf('%02x%02x%02x', $this->my_team_color['rgb']) : null;
     $o->his_team_color_hue = $this->his_team_color ? $this->his_team_color['hue'] : null;
     $o->his_team_color_rgb = $this->his_team_color ? vsprintf('%02x%02x%02x', $this->his_team_color['rgb']) : null;
     $o->start_at = $this->start_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->start_at) : null;
     $o->end_at = $this->end_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->end_at) : new Now();
     $o->agent_id = null;
     $o->at = new Now();
     return $o;
 }
use App\Models\Source;
use App\Models\Map;
$factory->define(App\Models\User::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'api_token' => str_random(60), 'remember_token' => str_random(10)];
});
$factory->define(App\Models\Setting::class, function (Faker\Generator $faker) {
    return ['group' => $faker->randomElement(['general', 'mapbox', 'preferences']), 'key' => $faker->word, 'value' => $faker->sentence];
});
$factory->define(App\Models\Map::class, function (Faker\Generator $faker) {
    $users = User::lists('id')->toArray();
    $hash = "";
    do {
        $hash = str_random(4);
    } while (Map::where("hash", "=", $hash)->first() instanceof Map);
    return ['hash' => $hash, 'user_id' => $faker->randomElement($users), 'active' => $faker->boolean(75), 'visibility' => $faker->randomElement(['public', 'public', 'public', 'shared', 'shared', 'private']), 'name' => $faker->sentence(6), 'description' => $faker->paragraph(2), 'style' => $faker->randomElement(['cilv7wj9m00uxbim8zml4zdz3', 'cikedqlyp00bbkqlxe7kzopov']), 'longitude' => 4.390819, 'latitude' => 51.92696, 'zoom' => $faker->numberBetween(8, 10), 'pitch' => $faker->numberBetween(10, 50), 'bearing' => $faker->numberBetween(20, 180), 'views' => $faker->numberBetween(1, 1000), 'created_at' => $faker->dateTimeBetween('-2 year', '-6 months'), 'updated_at' => $faker->dateTimeBetween('-5 months', 'now')];
});
$factory->define(App\Models\Source::class, function (Faker\Generator $faker) {
    $hash = "";
    do {
        $hash = str_random(4);
    } while (Source::where("hash", "=", $hash)->first() instanceof Source);
    return ['hash' => $hash, 'origin_type' => $faker->randomElement(['url', 'url', 'url', 'url', 'file', 'dropbox', 'gdrive']), 'origin_url' => $faker->randomElement([null, $faker->url]), 'origin_file' => $faker->randomElement([null, 'whatever.csv']), 'origin_format' => $faker->randomElement(['csv', 'geojson']), 'origin_size' => $faker->numberBetween(100000, 15000000), 'name' => $faker->sentence(2), 'description' => $faker->sentence(20), 'web' => 'https://schiedam.dataplatform.nl/dataset/' . $faker->slug, 'sync_status' => $faker->randomElement(['ready', 'ready', 'ready', 'ready', 'ready', 'queued', 'downloading', 'processing', 'disabled', 'disabled', 'error']), 'sync_interval' => $faker->randomElement(['never', 'onchange', 'hourly', 'daily', 'weekly', 'monthly', 'yearly']), 'synced_at' => $faker->dateTimeBetween('-1 month', '-1 day'), 'created_at' => $faker->dateTimeBetween('-2 year', '-6 months'), 'updated_at' => $faker->dateTimeBetween('-5 months', 'now')];
});
$factory->define(App\Models\Tag::class, function (Faker\Generator $faker) {
    return ['name' => $faker->word];
});
$factory->define(App\Models\Layer::class, function (Faker\Generator $faker) {
    $sources = Source::lists('id')->toArray();
    $maps = Map::lists('id')->toArray();
    return ['order' => $faker->numberBetween(0, 100), 'name' => $faker->word, 'map_id' => $faker->randomElement($maps), 'source_id' => $faker->randomElement($sources), 'minzoom' => 0, 'maxzoom' => 22, 'interactive' => $faker->boolean(75), 'type' => $faker->randomElement(['fill', 'line', 'circle']), 'visible' => $faker->boolean(90), 'opacity' => $faker->randomElement([1, 8, 5, 2, 0])];
});
 public function destroyMap($id)
 {
     $map = Map::findOrFail($id);
     $result = Map::destroy($id);
     return $result;
 }
 public function getMaps()
 {
     $ret = [];
     foreach (Map::find()->all() as $map) {
         $ret[$map->key] = Yii::t('app-map', $map->name);
     }
     uasort($ret, 'strnatcasecmp');
     return $ret;
 }
Beispiel #20
0
 public function rules()
 {
     return [[['lobby_id'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'id'], [['rule_id'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'id'], [['map_id'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'id'], [['weapon_id'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'id']];
 }
Beispiel #21
0
 /**
  * @param $data array
  */
 public function create($data)
 {
     $map = new Map();
     $map->setAttributes($data);
     $this->saveOrFail($map);
 }