Changeset 41


Ignore:
Timestamp:
Sep 14, 2020, 12:22:36 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Translate prefix multipliers.
  • Modified: Improve length, duration and speed calculation in detailed and daily tables.
  • Added: Allow to define lap length na money per Km for each year.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Locale/cs.php

    r39 r41  
    5050        'Search' => 'Hledat',
    5151        'hour' => 'hodinu',
     52        'yoctosecond' => 'yoctosekund',
     53        'zeptosecond' => 'zeptosekund',
     54        'attosecond' => 'attosekund',
     55        'femtosecond' => 'femtosekund',
     56        'pikosecond' => 'pikosekund',
     57        'nanosecond' => 'nanosekund',
     58        'microsecond' => 'mikrosekund',
     59        'millisecond' => 'milisekund',
     60        'second' => 'sekund',
     61        'minutes' => 'minut',
     62        'minute' => 'minuta',
     63        'hours' => 'hodin',
     64        'hour' => 'hodina',
     65        'days' => 'dnů',
     66        'day' => 'den',
     67        'weeks' => 'týdnů',
     68        'week' => 'týden',
     69        'months' => 'měsíců',
     70        'month' => 'měsíc',
     71        'years' => 'roků',
     72        'year' => 'rok',
     73        'decades' => 'desetiletí',
     74        'decade' => 'desetiletí',
     75        'centuries' => 'století',
     76        'century' => 'století',
     77        'millennia' => 'tisíciletí',
     78        'millennium' => 'tisíciletí',
    5279      ),
    5380      'URL' => array(
  • trunk/Packages/Common/PrefixMultiplier.php

    r39 r41  
    11<?php
    22
     3function InitPrefixMultipliers()
     4{
     5  global $PrefixMultipliers;
    36$PrefixMultipliers = array
    47(
     
    4851    'Definition' => array
    4952    (
    50       array('ys', 'yoctosecond', pow(10, -24)),
    51       array('zs', 'zeptosecond', pow(10, -21)),
    52       array('as', 'attosecond', pow(10, -18)),
    53       array('fs', 'femtosecond', pow(10, -15)),
    54       array('ps', 'pikosecond', pow(10, -12)),
    55       array('ns', 'nanosecond', pow(10, -9)),
    56       array('us', 'mikrosecond', pow(10, -6)),
    57       array('ms', 'milisecond', pow(10, -3)),
    58       array('s', 'second', 1),
    59       array('minutes', 'minute', 60),
    60       array('hours', 'hour', 60 * 60) ,
    61       array('days', 'day', 24 * 60 * 60),
    62       array('weeks', 'week', 7 * 24 * 60 * 60),
    63       array('months', 'month', 30 * 24 * 60 * 60),
    64       array('years', 'year', 364 * 24 * 60 * 60),
    65       array('desitiletí', 'desetiletí', 10 * 364 * 24 * 60 * 60),
    66       array('staletí', 'staletí', 100 * 364 * 24 * 60 * 60),
    67       array('tisíciletí', 'tisiciletí', 10000 * 364 * 24 * 60 * 60),
     53      array('ys', T('yoctosecond'), pow(10, -24)),
     54      array('zs', T('zeptosecond'), pow(10, -21)),
     55      array('as', T('attosecond'), pow(10, -18)),
     56      array('fs', T('femtosecond'), pow(10, -15)),
     57      array('ps', T('pikosecond'), pow(10, -12)),
     58      array('ns', T('nanosecond'), pow(10, -9)),
     59      array('us', T('microsecond'), pow(10, -6)),
     60      array('ms', T('millisecond'), pow(10, -3)),
     61      array('s', T('second'), 1),
     62      array(T('minutes'), T('minute'), 60),
     63      array(T('hours'), T('hour'), 60 * 60) ,
     64      array(T('days'), T('day'), 24 * 60 * 60),
     65      array(T('weeks'), T('week'), 7 * 24 * 60 * 60),
     66      array(T('months'), T('month'), 30 * 24 * 60 * 60),
     67      array(T('years'), T('year'), 364 * 24 * 60 * 60),
     68      array(T('decades'), T('decade'), 10 * 364 * 24 * 60 * 60),
     69      array(T('centuries'), T('century'), 100 * 364 * 24 * 60 * 60),
     70      array(T('millennia'), T('millennium'), 10000 * 364 * 24 * 60 * 60),
    6871    ),
    6972  ),
    7073);
     74}
    7175
    7276class PrefixMultiplier
     
    117121  }
    118122}
     123
     124InitPrefixMultipliers();
  • trunk/SQL/Upgrade.txt

    r21 r41  
    1515  MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
    1616
     17-- 41
     18
     19CREATE TABLE `Year` (
     20  `Id` int(11) NOT NULL,
     21  `Year` int(11) NOT NULL,
     22  `MoneyKm` int(11) NOT NULL,
     23  `LapLength` DECIMAL(10,1) NOT NULL
     24) ENGINE=InnoDB DEFAULT CHARSET=utf8;
     25
     26ALTER TABLE `Year` ADD PRIMARY KEY (`Id`);
     27
     28ALTER TABLE `Year`
     29  MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT;
     30COMMIT;
     31
     32INSERT INTO `Year` (`Id`, `Year`, `MoneyKm`, `LapLength`) VALUES
     33(1, 2018, 30, '1.5'),
     34(2, 2019, 30, '1.5'),
     35(3, 2020, 10, '0.0');
  • trunk/index.php

    r40 r41  
    66include_once('Run.php');
    77include_once('Packages/Common/Base.php');
     8include_once('Packages/Common/Locale.php');
    89include_once('Packages/Common/PrefixMultiplier.php');
    9 include_once('Packages/Common/Locale.php');
    1010
    1111session_start();
     
    2929  var $LinkLocaleExceptions;
    3030  var $Title;
     31  var $LapLength;
     32  var $MoneyKm;
     33  var $MaxRunnerSpeed;
     34  var $MinRunnerSpeed;
    3135
    3236  function __construct()
     
    3640    $this->LinkLocaleExceptions = array();
    3741    $this->Title = '';
     42    $this->LapLength = 0; // km
     43    $this->MoneyKm = 0; // Kč
     44    $this->MaxRunnerSpeed = 20; // km/hour
     45    $this->MinRunnerSpeed = 2; // km/hour
    3846  }
    3947
     
    468476    $Output .= '<div class="page-title">'.$Title.' '.$DbRow['Name'].'</div>';
    469477    $Output .= '<div class="section-title">'.$this->ItemsYearList('/'.$UrlDir.'/', $TeamId, 'Team', 'Name="'.$DbRow['Name'].'"').'</div>';
     478    $this->LoadYearParameters($DbRow['Year']);
    470479    $Output .= '<div class="section-title">'.
    471480      T('Runners').': '.$DbRow['RunnerCount'].', '.
     
    546555    $Output .= '<table class="WideTable">';
    547556    $Output .= $Order['Output'];
     557    $TableStat = $Table.'Stat';
    548558    $DbResult = $this->Database->query('SELECT *'.
    549       ', (SELECT TIME_TO_SEC(TIMEDIFF('.$Table.'Stat.Time, B.Time)) FROM '.$Table.'Stat AS B WHERE (B.Time < '.$Table.'Stat.Time) AND (B.'.$Table.' = '.$Table.'Stat.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Duration'.
    550       ', (SELECT '.$Table.'Stat.Distance - B.Distance FROM '.$Table.'Stat AS B WHERE (B.Time < '.$Table.'Stat.Time) AND (B.'.$Table.' = '.$Table.'Stat.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Length'.
     559      ', (SELECT '.$TableStat.'.Distance - B.Distance FROM '.$TableStat.' AS B WHERE (B.Time < '.$TableStat.'.Time) AND (B.'.$Table.' = '.$TableStat.'.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Length'.
     560      ', (SELECT TIME_TO_SEC(TIMEDIFF('.$TableStat.'.Time, B.Time)) FROM '.$TableStat.' AS B WHERE (B.Time < '.$TableStat.'.Time) AND (B.'.$Table.' = '.$TableStat.'.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Duration'.
    551561      ', NULL AS Speed'.
    552       ' FROM '.$Table.'Stat'.
     562      ' FROM '.$TableStat.
    553563      ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']);
    554564    while ($Item = $DbResult->fetch_assoc())
     
    559569        '<td>'.$Item['Money'].'</td>'.
    560570        '<td>'.$Item['Rank'].'</td>';
    561       if ($Item['Duration'] != null) $Output .= '<td>'.$PrefixMultiplier->Add($Item['Duration'], '', 4, 'Time').'</td>';
     571      if (($Item['Duration'] != null) and ($Item['Duration'] < $Item['Length'] / $this->MinRunnerSpeed * 3600)) $Output .= '<td>'.$PrefixMultiplier->Add($Item['Duration'], '', 4, 'Time').'</td>';
    562572        else $Output .= '<td>&nbsp;</td>';
    563573      $Output .= '<td>'.$Item['Length'].'</td>';
    564       if ($Item['Duration'] > 0) $Output .= '<td>'.$PrefixMultiplier->Add($Item['Length'] / $Item['Duration'] * 3600, '', 4, 'Decimal').'</td>';
     574      $Speed = $Item['Length'] / $Item['Duration'] * 3600;
     575      if (($Item['Duration'] > 0) and ($Item['Duration'] < $Item['Length'] * 3600 / $this->MinRunnerSpeed))
     576        $Output .= '<td>'.$PrefixMultiplier->Add($Speed, '', 4, 'Decimal').'</td>';
    565577        else $Output .= '<td>&nbsp;</td>';
    566578      $Output .= '</tr>';
     
    577589    $Where = '1';
    578590
    579     $DailyTableMaxId = 'SELECT * FROM (SELECT MAX(Id) AS MaxId FROM `'.$Table.'Stat` AS T1 WHERE T1.'.$Table.'='.$Id.' GROUP BY DATE(Time)) AS T2 LEFT JOIN '.$Table.'Stat AS T3 ON T3.Id=T2.MaxId';
    580     $DailyTableMinId = 'SELECT * FROM (SELECT MIN(Id) AS MinId FROM `'.$Table.'Stat` AS T1 WHERE T1.'.$Table.'='.$Id.' GROUP BY DATE(Time)) AS T2 LEFT JOIN '.$Table.'Stat AS T3 ON T3.Id=T2.MinId';
     591    $TableStat = $Table.'Stat';
     592    $DailyTableMaxId = 'SELECT * FROM (SELECT MAX(Id) AS MaxId FROM '.$TableStat.' AS T1 WHERE T1.'.$Table.'='.$Id.' GROUP BY DATE(Time)) AS T2 LEFT JOIN '.$TableStat.' AS T3 ON T3.Id=T2.MaxId';
     593    $DailyTableMinId = 'SELECT * FROM (SELECT MIN(Id) AS MinId FROM '.$TableStat.' AS T1 WHERE T1.'.$Table.'='.$Id.' GROUP BY DATE(Time)) AS T2 LEFT JOIN '.$TableStat.' AS T3 ON T3.Id=T2.MinId';
    581594    $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$DailyTableMaxId.') AS B');
    582595    $DbRow = $DbResult->fetch_row();
     
    598611    $Output .= '<table class="WideTable">';
    599612    $Output .= $Order['Output'];
    600     $DbResult = $this->Database->query('SELECT * '.
    601       ', (SELECT T4.Distance - B.Distance + 1.5 FROM ('.$DailyTableMinId.') AS B WHERE (DATE(B.Time) = DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Length'.
    602       ', (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.'.$Table.' = T4.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Duration'.
    603       ', NULL AS Speed'.
    604       ' FROM ('.$DailyTableMaxId.') AS T4'.
    605       ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']);
     613
     614    if ($this->LapLength == 0)
     615    {
     616      $DbResult = $this->Database->query('SELECT * '.
     617        ', COALESCE((SELECT T4.Distance - B.Distance FROM ('.$DailyTableMaxId.') AS B WHERE (DATE(B.Time) < DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.') ORDER BY B.Time DESC LIMIT 1), T4.Distance) AS Length'.
     618        ', NULL AS Duration'.
     619        ', NULL AS Speed'.
     620        ' FROM ('.$DailyTableMaxId.') AS T4'.
     621        ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']);
     622    } else
     623    {
     624      $DbResult = $this->Database->query('SELECT * '.
     625        ', COALESCE((SELECT T4.Distance - B.Distance FROM ('.$DailyTableMaxId.') AS B WHERE (DATE(B.Time) < DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.') ORDER BY B.Time DESC LIMIT 1), T4.Distance) AS Length'.
     626        //', (SELECT COUNT(*) * '.$this->LapLength.' FROM '.$TableStat.' AS B WHERE (DATE(B.Time) = DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.')) AS LapLength'.
     627        ', (SELECT TIME_TO_SEC(TIMEDIFF(T4.Time, B.Time)) / (Length - '.$this->LapLength.') * Length FROM ('.$DailyTableMinId.') AS B WHERE (DATE(B.Time) = DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Duration'.
     628        ', NULL AS Speed'.
     629        ' FROM ('.$DailyTableMaxId.') AS T4'.
     630        ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']);
     631    }
    606632    while ($Item = $DbResult->fetch_assoc())
    607633    {
     
    700726    if (!is_numeric($RunnerId)) die(T('Runner id needs to be numeric'));
    701727
    702     $DbResult = $this->Database->query('SELECT Runner.Name, Team.Name AS TeamName, Team.Id AS TeamId FROM Runner LEFT JOIN Team ON Team.Id=Runner.Team WHERE Runner.Id='.$RunnerId);
     728    $DbResult = $this->Database->query('SELECT Runner.Name, Team.Name AS TeamName, Team.Id AS TeamId, Team.Year FROM Runner LEFT JOIN Team ON Team.Id=Runner.Team WHERE Runner.Id='.$RunnerId);
    703729    $DbRow = $DbResult->fetch_assoc();
    704730    $this->Title = T('Runner').' '.$DbRow['Name'].' - '.$this->Title;
     
    707733      $Output .= '<div class="section-title"><a href="'.$this->Link('/team/'.$DbRow['TeamId']).'">'.$DbRow['TeamName'].'</a></div>';
    708734    $Output .= '<div class="section-title">'.$this->ItemsYearList('/runner/', $RunnerId, 'Runner', 'Name="'.$DbRow['Name'].'"').'</div>';
     735    $this->LoadYearParameters($DbRow['Year']);
    709736
    710737    $Output .= $this->ShowDetailed('Runner', $RunnerId);
     
    732759    }
    733760    if ($Year == 0) $Year = $this->GetLatestYear();
     761    $this->LoadYearParameters($Year);
    734762    return $Year;
    735763  }
     
    876904  }
    877905
     906  function LoadYearParameters($Year)
     907  {
     908    $DbResult = $this->Database->query('SELECT * FROM `Year` WHERE `Year`.`Year`='.$Year);
     909    if ($DbResult->num_rows > 0)
     910    {
     911      $DbRow = $DbResult->fetch_assoc();
     912      $this->LapLength = $DbRow['LapLength'];
     913      $this->MoneyKm = $DbRow['MoneyKm'];
     914    }
     915  }
     916
    878917  function Run()
    879918  {
     
    917956      $this->LocaleManager->LoadLocale($this->LocaleManager->LangCode);
    918957    }
     958    InitPrefixMultipliers();
    919959
    920960    if (GetRemoteAddress() != '')
Note: See TracChangeset for help on using the changeset viewer.