public function actionUpdate($region, $number)
 {
     $transaction = Yii::$app->db->beginTransaction();
     if (!($region = Region::findOne(['key' => $region]))) {
         printf("Unknown region: %s\n", $region);
         return 1;
     }
     if (!($fest = Splatfest::findOne(['region_id' => $region->id, '[[order]]' => $number]))) {
         printf("Unknown number: %s (region = %s)\n", $number, $region->key);
         return 1;
     }
     printf("Target #%d (Region=%s, Number=%d)\n", $fest->id, $region->key, $fest->order);
     $alpha = SplatfestTeam::findOne(['fest_id' => $fest->id, 'team_id' => 1]);
     $bravo = SplatfestTeam::findOne(['fest_id' => $fest->id, 'team_id' => 2]);
     if (!$alpha || !$bravo || $alpha->color_hue === null || $bravo->color_hue === null) {
         printf("    > Team information is not ready\n");
         return 1;
     }
     printf("    > cleanup ...\n");
     SplatfestBattleSummary::deleteAll(['fest_id' => $fest->id]);
     $this->createBattleSummaryTmpTimestamp($fest);
     $this->createBattleSummaryTmpTable('tmp_summary_a', $fest, $alpha->color_hue, $bravo->color_hue);
     $this->createBattleSummaryTmpTable('tmp_summary_b', $fest, $bravo->color_hue, $alpha->color_hue);
     $this->createBattleSummary($fest);
     $transaction->commit();
     return 0;
 }
Пример #2
0
 public function getResults()
 {
     $query = SplatfestBattleSummary::find()->andWhere(['{{splatfest_battle_summary}}.[[fest_id]]' => $this->fest->id])->orderBy('{{splatfest_battle_summary}}.[[timestamp]] ASC');
     return array_map(function ($a) {
         return ['at' => strtotime($a->timestamp), 'alpha' => $a->alpha_win + $a->bravo_lose, 'bravo' => $a->bravo_win + $a->alpha_lose];
     }, $query->all());
 }
Пример #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSplatfestBattleSummaries()
 {
     return $this->hasMany(SplatfestBattleSummary::className(), ['fest_id' => 'id']);
 }