Changeset 5


Ignore:
Timestamp:
Sep 12, 2018, 1:43:54 AM (6 years ago)
Author:
chronos
Message:
  • Added: Show lap duration, length and speed.
Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/index.php

    r4 r5  
    55include_once('Global.php');
    66include_once('Run.php');
     7include_once('PrefixMultiplier.php');
    78
    89session_start();
     
    5657  }
    5758
    58   function QueryRunners($Category, $Page, $TeamId, $Query = '', $StartNumber = '')
    59   {
    60     $URL = 'http://leaderboard.teribear.cz/Home/GetRunners?category='.$Category.'&page='.$Page.'&teamId='.$TeamId.'&query='.$Query;
    61     if ($Category != '') $URL .= '&startNumber='.$StartNumber;
     59  // Query: text from name
     60  // Page: index of page, one page is 30 items
     61  // Category: '', all, men, woman, kids, families, teams
     62  // TeamId: id of team
     63  // Count: number of items per page, default 30
     64  function QueryRunners($Category, $Page, $TeamId, $Query = null, $StartNumber = null, $Count = null)
     65  {
     66    $URL = 'http://leaderboard.teribear.cz/Home/GetRunners?category='.$Category.'&page='.$Page.'&teamId='.$TeamId;
     67    if ($Count != null) $URL .= '&count='.$Count;
     68    if ($Query != null) $URL .= '&query='.$Query;
     69    if ($Category != null) $URL .= '&startNumber='.$StartNumber;
    6270    $Content = file_get_contents($URL);
    6371    $JSON = json_decode($Content, true);
     
    175183  function ShowRunner()
    176184  {
     185    $PrefixMultiplier = new PrefixMultiplier();
    177186    $Output = '';
    178187
     
    197206    $TableColumns = array(
    198207      array('Name' => 'Time', 'Title' => 'Time'),
    199       array('Name' => 'Distance', 'Title' => 'Distance'),
    200       array('Name' => 'Money', 'Title' => 'Money'),
     208      array('Name' => 'Distance', 'Title' => 'Distance [km]'),
     209      array('Name' => 'Money', 'Title' => 'Money [Kč]'),
    201210      array('Name' => 'Rank', 'Title' => 'Rank'),
     211      array('Name' => 'Duration', 'Title' => 'Duration'),
     212      array('Name' => 'Length', 'Title' => 'Length [km]'),
     213      array('Name' => 'Speed', 'Title' => 'Speed [km/hour]'),
    202214    );
    203215    $Order = GetOrderTableHeader($TableColumns, 'Time', 1);
    204216    $Output .= '<table class="WideTable">';
    205217    $Output .= $Order['Output'];
    206     $DbResult = $this->Database->select('RunnerStat', '*',
    207       $Where.$Order['SQL'].$PageList['SQLLimit']);
     218    $DbResult = $this->Database->query('SELECT *'.
     219      ', (SELECT RunnerStat.Time - B.Time FROM RunnerStat AS B WHERE (B.Time < RunnerStat.Time) AND (B.Runner = RunnerStat.Runner) ORDER BY B.Time DESC LIMIT 1) AS Duration'.
     220      ', (SELECT RunnerStat.Distance - B.Distance FROM RunnerStat AS B WHERE (B.Time < RunnerStat.Time) AND (B.Runner = RunnerStat.Runner) ORDER BY B.Time DESC LIMIT 1) AS Length'.
     221      ', NULL AS Speed'.
     222      ' FROM RunnerStat'.
     223      ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']);
    208224    while($MeetItem = $DbResult->fetch_assoc())
    209225    {
     
    212228        '<td>'.$MeetItem['Distance'].'</td>'.
    213229        '<td>'.$MeetItem['Money'].'</td>'.
    214         '<td>'.$MeetItem['Rank'].'</td>'.
    215         '</tr>';
     230        '<td>'.$MeetItem['Rank'].'</td>';
     231      if ($MeetItem['Duration'] != null) $Output .= '<td>'.$PrefixMultiplier->Add($MeetItem['Duration'], '', 4, 'Time').'</td>';
     232        else $Output .= '<td>&nbsp;</td>';
     233      $Output .= '<td>'.$MeetItem['Length'].'</td>';
     234      if ($MeetItem['Duration'] > 0) $Output .= '<td>'.$PrefixMultiplier->Add($MeetItem['Length'] / $MeetItem['Duration'] * 3600, '', 4, 'Decimal').'</td>';
     235        else $Output .= '<td>&nbsp;</td>';
     236      $Output .= '</tr>';
    216237    }
    217238    $Output .= '</table>';
Note: See TracChangeset for help on using the changeset viewer.