Ejemplo n.º 1
0
function RecalcTeamResultFromTeamLevelPoints($raidid, $teamid)
{
    if (empty($teamid) and empty($raidid)) {
        return;
    }
    $teamRaidCondition = !empty($teamid) ? " t.team_id = {$teamid}" : "d.raid_id = {$raidid}";
    if (empty($teamid)) {
        CMmbLogger::enable(0);
        //CMmbLogger::enable(1);
    }
    $tm0 = microtime(true);
    // Обнуляем данные расчета
    $sql = " update  TeamLevelPoints tlp\n\t\t         join Teams t\n\t\t\t on tlp.team_id = t.team_id\n  \t\t         inner join Distances d\n\t\t\t on t.distance_id = d.distance_id\n\t\t  set  tlp.teamlevelpoint_penalty = NULL,\n\t\t       tlp.teamlevelpoint_duration = NULL,\n\t\t       t.team_maxlevelpointorderdone = NULL,\n\t\t       t.team_minlevelpointorderwitherror = NULL,\n\t\t       t.team_donelevelpoint = NULL,\n\t\t       t.team_comment = NULL\n \t\t  where {$teamRaidCondition}";
    $rs = MySqlQuery($sql);
    $tm1 = CMmbLogger::addInterval(' 1 ', $tm0);
    RecalcTeamLevelPointsDuration($raidid, $teamid);
    $tm2 = CMmbLogger::addInterval(' 2', $tm1);
    RecalcTeamLevelPointsPenaltyWithDiscount($raidid, $teamid);
    $tm3 = CMmbLogger::addInterval(' 3', $tm2);
    RecalcTeamLevelPointsPenaltyWithoutDiscount($raidid, $teamid);
    $tm4 = CMmbLogger::addInterval(' 4', $tm3);
    // echo 'RecalcTeamLevelPointsResult '.$raidid.','.$teamid;
    RecalcTeamLevelPointsResult($raidid, $teamid);
    $tm5 = CMmbLogger::addInterval(' 5', $tm4);
    //	return;
    // Находим ключ ММБ, если указана только команда
    if (empty($raidid)) {
        $sql = "select d.raid_id\n\t\t\t\tfrom Teams t\n\t\t\t\t\tinner join Distances d\n\t\t\t\t\ton t.distance_id = d.distance_id\n\t\t\t\twhere t.team_id = {$teamid}\n\t\t\t\tLIMIT 0,1";
        $raidid = CSql::singleValue($sql, 'raid_id');
    }
    //Ставим ошибки
    //FindErrors($raidid, $teamid);
    $tm6 = CMmbLogger::addInterval(' 6', $tm5);
    // $raidid мог измениться
    $teamRaidCondition = !empty($teamid) ? "t.team_id = {$teamid}" : "d.raid_id = {$raidid}";
    // Результат команды - это результат в максимальной точке
    // Перевод в секунды нужен для корректной работы MAX
    $sql = " update  Teams t\n\t\t\t\tinner join\n\t\t          \t(select tlp.team_id,\n\t\t\t\t\t        MAX(COALESCE(lp.levelpoint_order, 0)) as progress,\n\t\t\t\t\t\t\tMAX(t.distance_id) as distance_id,\n\t\t\t\t\t        MAX(TIME_TO_SEC(COALESCE(tlp.teamlevelpoint_result, 0))) as secresult\n\t\t\t\t\t from TeamLevelPoints tlp\n\t\t\t\t\t      inner join Teams t\n\t\t\t\t\t      on tlp.team_id = t.team_id\n\t\t\t\t\t      inner join Distances d\n\t\t\t\t\t      on t.distance_id = d.distance_id\n\t\t\t\t\t      inner join LevelPoints lp\n\t\t\t\t\t      on tlp.levelpoint_id = lp.levelpoint_id\n\t\t\t\t\t where  {$teamRaidCondition}\n\t\t\t\t\t group by tlp.team_id\n\t\t\t\t\t) a\n\t\t  \t\ton t.team_id = a.team_id\n\t\t  \t\tinner join\n\t\t\t\t\t(select  lp.distance_id,\n\t\t\t\t\t         MAX(lp.levelpoint_order) as maxlporder\n\t\t\t\t\tfrom LevelPoints lp\n\t\t\t\t\tgroup by lp.distance_id\n\t\t\t\t\t) b\n\t\t\t  \ton a.distance_id = b.distance_id\n  \t          set  team_result =  CASE WHEN b.maxlporder = COALESCE(a.progress, 0) THEN SEC_TO_TIME(COALESCE(a.secresult, 0)) ELSE NULL END\n\t\t\t\t, team_maxlevelpointorderdone = COALESCE(a.progress, 0) ";
    //     echo $sql;
    $rs = MySqlQuery($sql);
    $tm7 = CMmbLogger::addInterval(' 7', $tm6);
    // теперь можно посчитать рейтинг
    RecalcTeamUsersRank($raidid);
    $tm8 = CMmbLogger::addInterval(' 8', $tm7);
    //
    // Находим минимальную точку с ошибкой (COALESCE(tlp.error_id, 0) > 0)
    // < 0 - это не ошибка - предупреждение
    $sql = " update  Teams t\n\t\t\t\t    inner join\n\t    \t\t      \t(select tlp.team_id,\n\t\t\t\t\t        MIN(COALESCE(lp.levelpoint_order, 0)) as error\n\t\t\t\t\t\tfrom TeamLevelPoints tlp\n\t\t\t\t\t\t\t\tinner join Teams t\n\t\t\t\t\t\t\t    on tlp.team_id = t.team_id\n\t\t\t      \t\t\t\tinner join Distances d\n\t\t\t      \t\t\t\ton t.distance_id = d.distance_id\n\t\t\t      \t\t\t\tinner join LevelPoints lp\n\t\t\t      \t\t\t\ton tlp.levelpoint_id = lp.levelpoint_id\n\t\t\t\t\t\twhere  COALESCE(tlp.error_id, 0) > 0\n\t\t        \t\t\tand {$teamRaidCondition}\n\t\t\t\t\t\tgroup by tlp.team_id\n\t\t\t\t\t\t) a\n\t\t  \t\t\ton t.team_id = a.team_id\n          \tset  team_minlevelpointorderwitherror = COALESCE(a.error, 0)";
    //     echo $sql;
    $rs = MySqlQuery($sql);
    $tm9 = CMmbLogger::addInterval(' 9', $tm8);
    // Находим невзятые КП
    // расчет закомментирован, так ка Сергей строит список другим способом
    /*
    	 $sql = " update  Teams t
    				    inner join
    	    		      	(select t.team_id, GROUP_CONCAT(lp.levelpoint_name ORDER BY lp.levelpoint_order, ' ') as skippedlevelpoint
    						from  Teams t
    								inner join  Distances d
    								on t.distance_id = d.distance_id
    								join LevelPoints lp
     								on t.distance_id = lp.distance_id
    									and  COALESCE(t.team_maxlevelpointorderdone, 0) >= lp.levelpoint_order
    								left outer join TeamLevelPoints tlp
    								on lp.levelpoint_id = tlp.levelpoint_id
    									and t.team_id = tlp.team_id
    					 	where 	tlp.levelpoint_id is NULL
    								and d.distance_hide = 0 and t.team_hide = 0
    								and $teamRaidCondition
    						group by t.team_id
    						) a
    		  			on t.team_id = a.team_id
    	       		set  team_skippedlevelpoint = COALESCE(a.skippedlevelpoint, '')";
    
    		 //     echo $sql;
    
    		 $rs = MySqlQuery($sql);*/
    // Обновляем комментарий у команды
    $sql = " update  Teams t\n                inner join\n                      (select tlp.team_id \n\t\t\t\t\t\t,group_concat(COALESCE(teamlevelpoint_comment, '')) as team_comment\n\t\t\t\t       from TeamLevelPoints tlp\n\t\t\t\t\t\t\tleft outer join Errors err\n\t\t\t\t\t\t\ton tlp.error_id = err.error_id\n\t\t\t\t\t\t    inner join Teams t\n\t\t\t\t\t\t    on t.team_id = tlp.team_id\n\t\t\t\t\t\t    inner join Distances d\n\t\t\t    \t\t\ton t.distance_id = d.distance_id\n                       where  COALESCE(tlp.teamlevelpoint_comment, '') <> ''\n                                and {$teamRaidCondition}\n                       group by tlp.team_id\n                      ) a\n\t\t  \t\ton t.team_id = a.team_id\n\t\t  set  t.team_comment = a.team_comment";
    //   echo $sql;
    $rs = MySqlQuery($sql);
    $tm10 = CMmbLogger::addInterval(' 10', $tm9);
    //Теперь в это поле добавляем ошибки  tlp.error_id  > 0
    $sql = " update  Teams t\n                inner join\n                      (select tlp.team_id \n\t\t\t\t\t\t,group_concat(COALESCE(error_name, '')) as team_error\n\t\t\t\t\t\tfrom TeamLevelPoints tlp\n\t\t\t\t\t\t\t\tleft outer join Errors err\n\t\t\t\t\t\t\t\ton tlp.error_id = err.error_id\n\t\t\t\t\t\t\t    inner join Teams t\n\t\t\t\t\t\t\t    on t.team_id = tlp.team_id\n\t\t\t\t\t\t\t    inner join Distances d\n\t\t\t\t\t\t\t    on t.distance_id = d.distance_id\n\t\t\t\t\t\twhere  COALESCE(tlp.error_id, 0) > 0\n\t\t                       and {$teamRaidCondition}\n\t\t\t\t\t\tgroup by tlp.team_id\n                      ) a\n\t\t  \t\ton t.team_id = a.team_id\n\t\t  set  t.team_comment = CASE WHEN a.team_error <> '' THEN CONCAT('Ошибки: ', a.team_error, '; ',  COALESCE(t.team_comment, ''))  ELSE t.team_comment END";
    //   echo $sql;
    $rs = MySqlQuery($sql);
    $tm11 = CMmbLogger::addInterval(' 11', $tm10);
    //Теперь в это поле добавляем предупреждения  tlp.error_id  < 0
    $sql = " update  Teams t\n                inner join\n                      (select tlp.team_id \n\t\t\t\t\t\t,group_concat(COALESCE(error_name, '')) as team_error\n\t\t\t\t\t\tfrom TeamLevelPoints tlp\n\t\t\t\t\t\t\t\tleft outer join Errors err\n\t\t\t\t\t\t\t\ton tlp.error_id = err.error_id\n\t\t\t\t\t\t\t    inner join Teams t\n\t\t\t\t\t\t\t    on t.team_id = tlp.team_id\n\t\t\t\t\t\t\t    inner join Distances d\n\t\t\t\t\t\t\t    on t.distance_id = d.distance_id\n\t\t\t\t\t\twhere  COALESCE(tlp.error_id, 0) < 0\n\t\t                       and {$teamRaidCondition}\n\t\t\t\t\t\tgroup by tlp.team_id\n                      ) a\n\t\t  \t\ton t.team_id = a.team_id\n\t\t  set  t.team_comment = CASE WHEN a.team_error <> '' THEN CONCAT('Предупреждения: ', a.team_error, '; ',  COALESCE(t.team_comment, ''))  ELSE t.team_comment END";
    //   echo $sql;
    $rs = MySqlQuery($sql);
    $tm12 = CMmbLogger::addInterval(' 12', $tm11);
    //Теперь в это поле добавляем предупреждения  tlp.error_id  < 0
    $sql = " update  Teams t\n                inner join\n                      (select tlp.team_id \n\t\t\t\t\t\t,group_concat(COALESCE(error_name, '')) as team_error\n\t\t\t\t\t\tfrom TeamLevelPoints tlp\n\t\t\t\t\t\t\t\tleft outer join Errors err\n\t\t\t\t\t\t\t\ton tlp.error_id = err.error_id\n\t\t\t\t\t\t\t    inner join Teams t\n\t\t\t\t\t\t\t    on t.team_id = tlp.team_id\n\t\t\t\t\t\t\t    inner join Distances d\n\t\t\t\t\t\t\t    on t.distance_id = d.distance_id\n\t\t\t\t\t\twhere  COALESCE(tlp.error_id, 0) < 0\n\t\t                       and {$teamRaidCondition}\n\t\t\t\t\t\tgroup by tlp.team_id\n                      ) a\n\t\t  \t\ton t.team_id = a.team_id\n\t\t  set  t.team_comment = CASE WHEN a.team_error <> '' THEN CONCAT('Предупреждения: ', a.team_error, '; ',  COALESCE(t.team_comment, ''))  ELSE t.team_comment END";
    //   echo $sql;
    $rs = MySqlQuery($sql);
    $tm13 = CMmbLogger::addInterval(' 13', $tm12);
    //считаем (только для интерфейса список вщзятых КП
    $sql = " update  Teams t\n                inner join\n                      (select tlp.team_id \n\t\t\t,group_concat(DATE_FORMAT(COALESCE(tlp.teamlevelpoint_datetime, ''),'%H:%i')  order by teamlevelpoint_datetime  separator ', ') as team_donelevelpoint\n\t\t\t\t\t\tfrom TeamLevelPoints tlp\n\t\t\t\t\t\t\t    inner join Teams t\n\t\t\t\t\t\t\t    on t.team_id = tlp.team_id\n\t\t\t\t\t\t\t    inner join Distances d\n\t\t\t\t\t\t\t    on t.distance_id = d.distance_id\n\t\t\t\t\t\twhere  COALESCE(tlp.teamlevelpoint_datetime, 0) > 0\n\t\t                       and {$teamRaidCondition}\n\t\t\t\t\t\tgroup by tlp.team_id\n                      ) a\n\t\t  \t\ton t.team_id = a.team_id\n\t\t  set  t.team_donelevelpoint = a.team_donelevelpoint ";
    //   echo $sql;
    $rs = MySqlQuery($sql);
    $tm14 = CMmbLogger::addInterval(' 14', $tm13);
    // теперь можно посчитать рейтинг
    RecalcUsersRank($raidid);
    $tm14 = CMmbLogger::addInterval(' 15', $tm13);
    $msg = CMmbLogger::getText();
    //CMmb::setShortResult($msg, '');
    CMmb::setMessage($msg);
}
Ejemplo n.º 2
0
    // Действие вызывается ссылкой Объединение
    CMmb::setViews('ViewRankPage', '');
} else {
    if ($action == "viewLogs") {
        // todo добавить проверку прав!!!
        CMmb::setViews('viewLogs', '');
    } elseif ($action == 'RecalcRaidRank') {
        if ($RaidId <= 0) {
            CMmb::setShortResult('Марш-бросок не найден', '');
            return;
        }
        if (!$Administrator && !$Moderator) {
            return;
        }
        $Result = 0;
        $Result = RecalcTeamUsersRank($RaidId);
        CMmb::setShortResult('Рейтинг участников марш-броска пересчитан', 'ViewAdminDataPage');
    } elseif ($action == 'SendMessageForAll') {
        if ($RaidId <= 0) {
            CMmb::setShortResult('Марш-бросок не найден', '');
            return;
        }
        // рассылать всем может только администратор
        if (!$Administrator) {
            return;
        }
        CMmb::setViews('ViewAdminDataPage', '');
        $pText = $_POST['MessageText'];
        $pSubject = $_POST['MessageSubject'];
        $pSendType = mmb_validateInt($_POST, 'SendForAllTypeId');
        if (empty($pSubject) or trim($pSubject) == 'Тема рассылки') {