public function actionUpdate() { $competitions = Competition::model()->findAllByAttributes(array('type' => Competition::TYPE_WCA), array('condition' => 'date < unix_timestamp() AND date > unix_timestamp() - 86400 * 20', 'order' => 'date ASC')); $wcaDb = intval(file_get_contents(dirname(__DIR__) . '/config/wcaDb')); $sql = "UPDATE `user` `u`\r\n\t\t\t\tINNER JOIN `registration` `r` ON `u`.`id`=`r`.`user_id`\r\n\t\t\t\tLEFT JOIN `competition` `c` ON `r`.`competition_id`=`c`.`id`\r\n\t\t\t\tLEFT JOIN `wca_{$wcaDb}`.`Results` `rs`\r\n\t\t\t\t\tON `c`.`wca_competition_id`=`rs`.`competitionId`\r\n\t\t\t\t\tAND `rs`.`personName`=CASE WHEN `u`.`name_zh`='' THEN `u`.`name` ELSE CONCAT(`u`.`name`, ' (', `u`.`name_zh`, ')') END\r\n\t\t\t\tSET `u`.`wcaid`=`rs`.`personId`\r\n\t\t\t\tWHERE `u`.`wcaid`='' and `r`.`competition_id`=%id%"; $db = Yii::app()->db; $num = []; foreach ($competitions as $competition) { $num[$competition->id] = $db->createCommand(str_replace('%id%', $competition->id, $sql))->execute(); } echo 'updated wcaid: ', array_sum($num), PHP_EOL; Yii::import('application.statistics.*'); Yii::app()->cache->flush(); $data = Statistics::getData(true); echo 'set results_statistics_data: ', $data ? 1 : 0, PHP_EOL; }
public function actionStatistics() { $name = $this->sGet('name'); $names = array_map('ucfirst', explode('-', $name)); $class = implode('', $names); $this->description = Yii::t('statistics', 'Based on the official WCA competition results, we generated several WCA statistics about Chinese competitions and competitors, which were regularly up-to-date.'); if ($class !== '') { if (method_exists($this, $method = 'stat' . $class)) { $this->{$method}(); Yii::app()->end(); } else { throw new CHttpException(404); } } $data = Statistics::getData(); extract($data); $this->pageTitle = array('Fun Statistics'); $this->title = 'Fun Statistics'; $this->setWeiboShareDefaultText('关于中国WCA官方比赛及选手成绩的一系列趣味统计', false); $this->render('statistics', array('statistics' => $statistics, 'time' => $time)); }