Changeset 43 for trunk/index.php
- Timestamp:
- Sep 17, 2020, 9:51:29 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/index.php
r42 r43 147 147 if ($StartNumber != null) $URL .= '&startNumber='.$StartNumber; 148 148 $Content = file_get_contents($URL); 149 $JSON = json_decode($Content, true); 149 if (($Content !== false) and !empty($Content)) 150 { 151 $JSON = json_decode($Content, true); 152 } else 153 { 154 $JSON = null; 155 echo('Cannot load data from remote server ('.$URL.').<br/>'."\n"); 156 } 150 157 return $JSON; 151 158 } … … 154 161 { 155 162 $ItemsPerPage = 30; 156 $MaxCount = 350 * 30;163 $MaxCount = 250 * 30; 157 164 if ($Count > 0) $MaxCount = $Count; 158 165 $Result = array(); … … 162 169 $Page = $I * floor($MaxCount / $ItemsPerPage); 163 170 $JSON = $this->QueryRunners($Category, $Page, null, null, null, $MaxCount); 164 foreach ($JSON['items'] as $Item)171 if ($JSON != null) 165 172 { 166 $Result[] = $Item; 167 } 168 if (($JSON['last'] == 'true') or (count($JSON) == 0)) break; 169 if ($I > 10) break; // Safe limit if last would not work 170 $I++; 173 foreach ($JSON['items'] as $Item) 174 { 175 $Result[] = $Item; 176 } 177 if (($JSON['last'] == 'true') or (count($JSON) == 0)) break; 178 if ($I > 10) break; // Safe limit if last would not work 179 $I++; 180 } else break; 171 181 } 172 182 return $Result; … … 193 203 $Runners = array(); 194 204 $DbResult = $this->Database->query('SELECT Runner.Id, Runner.ChipNumber, Runner.Team, '. 195 '(SELECT RunnerStat.Distance FROM RunnerStat WHERE (RunnerStat.Runner = Runner.Id) ORDER BY RunnerStat. DistanceDESC LIMIT 1) AS Distance '.205 '(SELECT RunnerStat.Distance FROM RunnerStat WHERE (RunnerStat.Runner = Runner.Id) ORDER BY RunnerStat.Id DESC LIMIT 1) AS Distance '. 196 206 'FROM Runner WHERE Year='.$Year); 197 207 while ($DbRow = $DbResult->fetch_assoc()) … … 207 217 $Teams = array(); 208 218 $DbResult = $this->Database->query('SELECT Team.Id, Team.WebId, Team.Name, '. 209 '(SELECT TeamStat.Distance FROM TeamStat WHERE (TeamStat.Team = Team.Id) ORDER BY TeamStat. DistanceDESC LIMIT 1) AS Distance '.219 '(SELECT TeamStat.Distance FROM TeamStat WHERE (TeamStat.Team = Team.Id) ORDER BY TeamStat.Id DESC LIMIT 1) AS Distance '. 210 220 'FROM Team WHERE Year='.$Year); 211 221 while ($DbRow = $DbResult->fetch_assoc()) … … 277 287 278 288 if ($Runners[$Item['ChipNumber']]['Distance'] != $Item['OverallDistance']) 279 $Queries[] = $this->Database->GetInsert('RunnerStat', array( 280 'Time' => TimeToMysqlDateTime($Time), 281 'Runner' => $RunnerId, 282 'Distance' => $Item['OverallDistance'], 283 'Rank' => $Item['Pos'], 284 'Money' => $Item['Money'], 285 )); 289 { 290 $Queries[] = $this->Database->GetInsert('RunnerStat', array( 291 'Time' => TimeToMysqlDateTime($Time), 292 'Runner' => $RunnerId, 293 'Distance' => $Item['OverallDistance'], 294 'Rank' => $Item['Pos'], 295 'Money' => $Item['Money'], 296 )); 297 } 286 298 } else 287 299 if (($Item['Type'] == 'team') or ($Item['Type'] == 'rodina')) … … 341 353 $Time = time(); 342 354 $Items = $this->QueryRunnersAll('all'); 355 $Output = T('Loaded items count: '.count($Items).'<br/>'); 343 356 $ItemsWithoutProgress = array(); 344 357 foreach ($Items as $Item) … … 364 377 //file_put_contents('import/'.$Hash.'.txt', print_r($Items, true)); 365 378 } 366 $Output = T('Data synchronization from leaderboard finished.');379 $Output .= T('Data synchronization from leaderboard finished.<br/>'); 367 380 return $Output; 368 381 } … … 475 488 $this->Title = $Title.' '.$DbRow['Name'].' - '.$this->Title; 476 489 $Output .= '<div class="page-title">'.$Title.' '.$DbRow['Name'].'</div>'; 477 $Output .= '<div class="section-title">'.$this->ItemsYearList('/'.$UrlDir.'/', $TeamId, 'Team', 'Name="'.$ DbRow['Name'].'"').'</div>';490 $Output .= '<div class="section-title">'.$this->ItemsYearList('/'.$UrlDir.'/', $TeamId, 'Team', 'Name="'.$this->Database->real_escape_string($DbRow['Name']).'"').'</div>'; 478 491 $this->LoadYearParameters($DbRow['Year']); 479 492 $Output .= '<div class="section-title">'. … … 526 539 527 540 $Output .= $this->ShowDetailed('Team', $TeamId); 541 //$Output .= $this->ShowDetailedChart('Team', $TeamId); 528 542 $Output .= $this->ShowDaily('Team', $TeamId); 543 //$Output .= $this->ShowDailyChart('Team', $TeamId); 529 544 530 545 return $Output; … … 535 550 $PrefixMultiplier = new PrefixMultiplier(); 536 551 552 $TableStat = $Table.'Stat'; 537 553 $Output = '<div class="section-title">'.T('Lap progress').'</div>'; 538 $Where = $Table .'Stat.'.$Table.'='.$Id;539 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$Table.'Stat`WHERE '.$Where);554 $Where = $TableStat.'.'.$Table.'='.$Id; 555 $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$TableStat.' WHERE '.$Where); 540 556 $DbRow = $DbResult->fetch_row(); 541 557 $PageList = GetPageList($DbRow[0]); … … 555 571 $Output .= '<table class="WideTable">'; 556 572 $Output .= $Order['Output']; 557 $TableStat = $Table.'Stat';558 573 $DbResult = $this->Database->query('SELECT *'. 559 574 ', (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'. … … 583 598 $Output .= $PageList['Output']; 584 599 $Output .= '</div><br/>'; 600 return $Output; 601 } 602 603 function ShowDetailedChart($Table, $Id) 604 { 605 $TableStat = $Table.'Stat'; 606 $DbResult = $this->Database->query('SELECT *'. 607 ', (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'. 608 ', (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'. 609 ', NULL AS Speed'. 610 ' FROM '.$TableStat. 611 ' WHERE '.$TableStat.'.'.$Table.'='.$Id.' ORDER BY Time'); 612 $ChartValues = array(); 613 while ($Item = $DbResult->fetch_assoc()) 614 { 615 $ChartValues[MysqlDateTimeToTime($Item['Time'])] = $Item['Distance']; 616 } 617 $Output = $this->ShowChart($Table.'Detailed', $ChartValues, T('Lap progress')); 585 618 return $Output; 586 619 } … … 649 682 $Output .= $PageList['Output']; 650 683 $Output .= '</div>'; 684 return $Output; 685 } 686 687 function ShowDailyChart($Table, $Id) 688 { 689 $TableStat = $Table.'Stat'; 690 $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'; 691 $DbResult = $this->Database->query('SELECT * '. 692 ', 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'. 693 ' FROM ('.$DailyTableMaxId.') AS T4'. 694 ' ORDER BY Time'); 695 $ChartValues = array(); 696 while ($Item = $DbResult->fetch_assoc()) 697 { 698 $ChartValues[MysqlDateTimeToTime($Item['Time'])] = $Item['Length']; 699 } 700 $Output = $this->ShowChart($Table.'Daily', $ChartValues, T('Daily progress')); 651 701 return $Output; 652 702 } … … 734 784 if ($DbRow['TeamName'] != '') 735 785 $Output .= '<div class="section-title"><a href="'.$this->Link('/team/'.$DbRow['TeamId']).'">'.$DbRow['TeamName'].'</a></div>'; 736 $Output .= '<div class="section-title">'.$this->ItemsYearList('/runner/', $RunnerId, 'Runner', 'Name="'.$ DbRow['Name'].'"').'</div>';786 $Output .= '<div class="section-title">'.$this->ItemsYearList('/runner/', $RunnerId, 'Runner', 'Name="'.$this->Database->real_escape_string($DbRow['Name']).'"').'</div>'; 737 787 $this->LoadYearParameters($DbRow['Year']); 738 788 739 789 $Output .= $this->ShowDetailed('Runner', $RunnerId); 790 //$Output .= $this->ShowDetailedChart('Runner', $RunnerId); 740 791 $Output .= $this->ShowDaily('Runner', $RunnerId); 792 //$Output .= $this->ShowDailyChart('Runner', $RunnerId); 741 793 return $Output; 742 794 } … … 800 852 $Lang = 'en'; 801 853 $Output = '<?xml version="1.0" encoding="'.$this->Config['Encoding'].'"?>'."\n". 802 '<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.803 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$Lang.'" lang="'.$Lang.'">'.854 '<!doctype html>'. 855 '<html>'. 804 856 '<head>'. 805 857 '<link rel="stylesheet" href="'.$this->Link('/style/style.css').'" type="text/css" media="all" />'. 806 858 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->Config['Encoding'].'" />'. 807 '<meta name="viewport" content="width=device-width, initial-scale=1">'; 859 '<meta name="viewport" content="width=device-width, initial-scale=1">'. 860 '<script type="text/javascript" src="'.$this->Link('/Packages/Chart.js/Chart.js').'"></script>'; 808 861 //'<script src="'.$this->Link('/jquery.js').'"></script>'; 809 862 $Output .= '<title>'.$this->Title.'</title>'. … … 915 968 $this->MoneyKm = $DbRow['MoneyKm']; 916 969 } 970 } 971 972 function ShowChart($ChartName, $Values, $Title) 973 { 974 $Output = '<div style="width:50%; text-align: center; margin-left: auto; margin-right: auto;">'. 975 ' <canvas id="'.$ChartName.'"></canvas>'. 976 '</div>'. 977 '<script type="text/javascript">'; 978 $Output .= "var ctx = document.getElementById('".$ChartName."').getContext('2d'); 979 window.chartColors = { 980 red: 'rgb(255, 99, 132)', 981 orange: 'rgb(255, 159, 64)', 982 yellow: 'rgb(255, 205, 86)', 983 green: 'rgb(75, 192, 192)', 984 blue: 'rgb(54, 162, 235)', 985 purple: 'rgb(153, 102, 255)', 986 grey: 'rgb(201, 203, 207)' 987 }; 988 var config = { 989 type: 'line', 990 data: { 991 labels: ["; 992 foreach ($Values as $Key => $Value) 993 { 994 $Output .= "'".$Key."', "; 995 } 996 $Output .= "], 997 datasets: [{ 998 label: '', 999 backgroundColor: window.chartColors.red, 1000 borderColor: window.chartColors.red, 1001 data: ["; 1002 foreach ($Values as $Key => $Value) 1003 { 1004 $Output .= "{ x: ".$Key.", "; 1005 $Output .= "y: ".$Value." }, "; 1006 } 1007 $Output .= " 1008 ], 1009 fill: false, 1010 }] 1011 }, 1012 options: { 1013 responsive: true, 1014 title: { 1015 display: true, 1016 text: '".$Title."' 1017 }, 1018 tooltips: { 1019 mode: 'index', 1020 intersect: false, 1021 }, 1022 hover: { 1023 mode: 'nearest', 1024 intersect: true 1025 }, 1026 scales: { 1027 xAxes: [{ 1028 type: 'time', 1029 display: true, 1030 scaleLabel: { 1031 display: true, 1032 labelString: 'Date' 1033 }, 1034 ticks: { 1035 major: { 1036 fontStyle: 'bold', 1037 fontColor: '#FF0000' 1038 } 1039 } 1040 }], 1041 yAxes: [{ 1042 display: true, 1043 scaleLabel: { 1044 display: true, 1045 labelString: 'value' 1046 } 1047 }] 1048 } 1049 } 1050 }; 1051 var ".$ChartName." = new Chart(ctx, config); 1052 </script>"; 1053 return $Output; 917 1054 } 918 1055 … … 937 1074 ); 938 1075 $GlobalLocaleManager = $this->LocaleManager; 939 $this->LinkLocaleExceptions = array('style' );1076 $this->LinkLocaleExceptions = array('style', 'Packages'); 940 1077 941 1078 $this->PathItems = $this->ProcessURL();
Note:
See TracChangeset
for help on using the changeset viewer.