Changeset 7 for trunk


Ignore:
Timestamp:
Sep 14, 2018, 1:11:19 AM (6 years ago)
Author:
chronos
Message:
  • Added: Show daily statistics for runners.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/index.php

    r6 r7  
    9898        {
    9999          $RunnerStat = $DbResult->fetch_assoc();
    100           if ($RunnerStat['Distance'] != $Runner['OverallDistance'])
     100          if ($RunnerStat['Distance'] < $Runner['OverallDistance'])
    101101          {
    102102            $this->Database->insert('RunnerStat', array(
     
    193193    $DbResult = $this->Database->query('SELECT * FROM Runner WHERE Id='.$RunnerId);
    194194    $DbRow = $DbResult->fetch_assoc();
    195     $Output .= '<h4 style="text-align: center;">Runner '.$DbRow['Name'].'</h4></br>';
    196 
    197 
    198     $Where = 'Runner='.$RunnerId;
    199 
     195    $Output .= '<h4 style="text-align: center;">Runner '.$DbRow['Name'].'</h4>';
     196
     197
     198    $Where = 'RunnerStat.Runner='.$RunnerId;
     199
     200    // Show detailed stats
     201    $Output .= '<div style="text-align: center">Detailed</div><br/>';
    200202    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `RunnerStat` WHERE '.$Where);
    201203    $DbRow = $DbResult->fetch_row();
     
    238240    $Output .= '</table>';
    239241    $Output .= $PageList['Output'];
     242    $Output .= '</div><br/>';
     243
     244    // Show daily stats
     245    $Where = '1';
     246
     247    $DailyTableMaxId = 'SELECT * FROM (SELECT MAX(Id) AS MaxId FROM `RunnerStat` AS T1 WHERE T1.Runner='.$RunnerId.' GROUP BY DATE(Time)) AS T2 LEFT JOIN RunnerStat AS T3 ON T3.Id=T2.MaxId';
     248    $DailyTableMinId = 'SELECT * FROM (SELECT MIN(Id) AS MinId FROM `RunnerStat` AS T1 WHERE T1.Runner='.$RunnerId.' GROUP BY DATE(Time)) AS T2 LEFT JOIN RunnerStat AS T3 ON T3.Id=T2.MinId';
     249    $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$DailyTableMaxId.') AS B');
     250    $DbRow = $DbResult->fetch_row();
     251    $PageList = GetPageList($DbRow[0]);
     252
     253    $Output .= '<div style="text-align: center">Daily</div><br/>';
     254    $Output .= '<div id="list_content">';
     255    $Output .= $PageList['Output'];
     256    $TableColumns = array(
     257      array('Name' => 'Time', 'Title' => 'Time'),
     258      array('Name' => 'Distance', 'Title' => 'Distance [km]'),
     259      array('Name' => 'Money', 'Title' => 'Money [Kč]'),
     260      array('Name' => 'Rank', 'Title' => 'Rank'),
     261      array('Name' => 'Duration', 'Title' => 'Duration'),
     262      array('Name' => 'Length', 'Title' => 'Length [km]'),
     263      array('Name' => 'Speed', 'Title' => 'Speed [km/hour]'),
     264    );
     265    $Order = GetOrderTableHeader($TableColumns, 'Time', 1);
     266    $Output .= '<table class="WideTable">';
     267    $Output .= $Order['Output'];
     268    $DbResult = $this->Database->query('SELECT * '.
     269      ', (SELECT T4.Distance - B.Distance + 1.5 FROM ('.$DailyTableMinId.') AS B WHERE (DATE(B.Time) = DATE(T4.Time)) AND (B.Runner = T4.Runner) ORDER BY B.Time DESC LIMIT 1) AS Length'.
     270      ', (SELECT TIME_TO_SEC(TIMEDIFF(T4.Time, B.Time)) / (Length - 1.5) * Length FROM ('.$DailyTableMinId.') AS B WHERE (DATE(B.Time) = DATE(T4.Time)) AND (B.Runner = T4.Runner) ORDER BY B.Time DESC LIMIT 1) AS Duration'.
     271      ', NULL AS Speed'.
     272      ' FROM ('.$DailyTableMaxId.') AS T4'.
     273      ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']);
     274    while($MeetItem = $DbResult->fetch_assoc())
     275    {
     276      $Output .= '<tr>'.
     277        '<td>'.HumanDateTime(MysqlDateTimeToTime($MeetItem['Time'])).'</td>'.
     278        '<td>'.$MeetItem['Distance'].'</td>'.
     279        '<td>'.$MeetItem['Money'].'</td>'.
     280        '<td>'.$MeetItem['Rank'].'</td>';
     281      if ($MeetItem['Duration'] != null) $Output .= '<td>'.$PrefixMultiplier->Add($MeetItem['Duration'], '', 4, 'Time').'</td>';
     282        else $Output .= '<td>&nbsp;</td>';
     283      $Output .= '<td>'.$MeetItem['Length'].'</td>';
     284      if ($MeetItem['Duration'] > 0) $Output .= '<td>'.$PrefixMultiplier->Add($MeetItem['Length'] / $MeetItem['Duration'] * 3600, '', 4, 'Decimal').'</td>';
     285        else $Output .= '<td>&nbsp;</td>';
     286      $Output .= '</tr>';
     287    }
     288    $Output .= '</table>';
     289    $Output .= $PageList['Output'];
    240290    $Output .= '</div>';
    241291
Note: See TracChangeset for help on using the changeset viewer.